Decompiled source of Telekinesis v1.0.0

Telekinesis/telekinies.dll

Decompiled a month 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 Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow;
using LabFusion.Utilities;
using MelonLoader;
using MelonLoader.Preferences;
using TelekinesisModNS;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(TelekinesisModClass), "TelekinesisMod", "7.0.0", "Ichigo", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyTitle("telekinies")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("telekinies")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("1f8a7dcf-881a-400c-8ddd-929adb6f8d50")]
[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")]
namespace TelekinesisModNS;

public class TelekinesisModClass : MelonMod
{
	internal static bool Enabled = false;

	internal static float HoldStiffness = 15f;

	internal static float DistanceScrollSpeed = 8f;

	internal static float FlingBoost = 1.3f;

	internal static bool ShowBeam = true;

	internal static bool ShowSphere = true;

	internal static float SphereRadius = 0.3f;

	internal static float SphereOffset = 0.5f;

	internal static float GrabThreshold = 0.6f;

	internal static float ReleaseThreshold = 0.3f;

	private static MelonPreferences_Category _prefCat;

	private static MelonPreferences_Entry<bool> _prefEnabled;

	private static MelonPreferences_Entry<float> _prefStiffness;

	private static MelonPreferences_Entry<float> _prefScrollSpeed;

	private static MelonPreferences_Entry<float> _prefFlingBoost;

	private static MelonPreferences_Entry<bool> _prefShowBeam;

	private static MelonPreferences_Entry<bool> _prefShowSphere;

	private static MelonPreferences_Entry<float> _prefSphereRadius;

	private static MelonPreferences_Entry<float> _prefSphereOffset;

	internal static TKState RightTK = new TKState();

	internal static TKState LeftTK = new TKState();

	public override void OnInitializeMelon()
	{
		SetupPrefs();
		SetupBoneMenu();
		MelonLogger.Msg("[TK] Force Grab v7 loaded");
	}

	private void SetupPrefs()
	{
		_prefCat = MelonPreferences.CreateCategory("TelekinesisMod");
		_prefEnabled = _prefCat.CreateEntry<bool>("Enabled", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		_prefStiffness = _prefCat.CreateEntry<float>("Stiffness", 15f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		_prefScrollSpeed = _prefCat.CreateEntry<float>("ScrollSpeed", 8f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		_prefFlingBoost = _prefCat.CreateEntry<float>("FlingBoost", 1.3f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		_prefShowBeam = _prefCat.CreateEntry<bool>("ShowBeam", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		_prefShowSphere = _prefCat.CreateEntry<bool>("ShowSphere", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		_prefSphereRadius = _prefCat.CreateEntry<float>("SphereRadius", 0.3f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		_prefSphereOffset = _prefCat.CreateEntry<float>("SphereOffset", 0.5f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		Enabled = _prefEnabled.Value;
		HoldStiffness = _prefStiffness.Value;
		DistanceScrollSpeed = _prefScrollSpeed.Value;
		FlingBoost = _prefFlingBoost.Value;
		ShowBeam = _prefShowBeam.Value;
		ShowSphere = _prefShowSphere.Value;
		SphereRadius = _prefSphereRadius.Value;
		SphereOffset = _prefSphereOffset.Value;
	}

	private static void SavePrefs()
	{
		_prefEnabled.Value = Enabled;
		_prefStiffness.Value = HoldStiffness;
		_prefScrollSpeed.Value = DistanceScrollSpeed;
		_prefFlingBoost.Value = FlingBoost;
		_prefShowBeam.Value = ShowBeam;
		_prefShowSphere.Value = ShowSphere;
		_prefSphereRadius.Value = SphereRadius;
		_prefSphereOffset.Value = SphereOffset;
		_prefCat.SaveToFile(false);
	}

	private void SetupBoneMenu()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		Page obj = Page.Root.CreatePage("Telekinesis", Color.magenta, 0, true);
		obj.CreateBool("Enabled", Color.green, Enabled, (Action<bool>)delegate(bool v)
		{
			Enabled = v;
			if (!v)
			{
				RightTK.Drop(0f);
				RightTK.DestroySphere();
				LeftTK.Drop(0f);
				LeftTK.DestroySphere();
			}
			SavePrefs();
		});
		obj.CreateFloat("Stiffness", Color.cyan, HoldStiffness, 1f, 1f, 30f, (Action<float>)delegate(float v)
		{
			HoldStiffness = v;
			SavePrefs();
		});
		obj.CreateFloat("Scroll Speed", Color.cyan, DistanceScrollSpeed, 1f, 1f, 20f, (Action<float>)delegate(float v)
		{
			DistanceScrollSpeed = v;
			SavePrefs();
		});
		obj.CreateFloat("Fling Boost", Color.yellow, FlingBoost, 0.1f, 0.5f, 5f, (Action<float>)delegate(float v)
		{
			FlingBoost = v;
			SavePrefs();
		});
		obj.CreateFloat("Sphere Size", Color.white, SphereRadius, 0.05f, 0.05f, 2f, (Action<float>)delegate(float v)
		{
			SphereRadius = v;
			RightTK.UpdateSphereSize(v);
			LeftTK.UpdateSphereSize(v);
			SavePrefs();
		});
		obj.CreateFloat("Sphere Offset", Color.white, SphereOffset, 0.1f, 0.2f, 2f, (Action<float>)delegate(float v)
		{
			SphereOffset = v;
			SavePrefs();
		});
		obj.CreateBool("Show Sphere", Color.white, ShowSphere, (Action<bool>)delegate(bool v)
		{
			ShowSphere = v;
			if (!v)
			{
				RightTK.DestroySphere();
				LeftTK.DestroySphere();
			}
			SavePrefs();
		});
		obj.CreateBool("Show Beam", Color.white, ShowBeam, (Action<bool>)delegate(bool v)
		{
			ShowBeam = v;
			SavePrefs();
		});
	}

	public override void OnUpdate()
	{
		if (Enabled)
		{
			RigManager rigManager = Player.RigManager;
			if (!((Object)(object)rigManager == (Object)null))
			{
				UpdateHand(RightTK, rigManager.physicsRig.rightHand);
				UpdateHand(LeftTK, rigManager.physicsRig.leftHand);
			}
		}
	}

	private void UpdateHand(TKState tk, Hand hand)
	{
		//IL_0023: 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_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: 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_008f: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_020d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: 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_024b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02be: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)hand == (Object)null)
		{
			return;
		}
		BaseController controller = hand.Controller;
		if ((Object)(object)controller == (Object)null)
		{
			return;
		}
		Transform transform = ((Component)hand).transform;
		Vector3 position = transform.position + transform.forward * SphereOffset;
		if (ShowSphere && Enabled)
		{
			if ((Object)(object)tk.Sphere == (Object)null)
			{
				tk.CreateSphere(SphereRadius);
			}
			if ((Object)(object)tk.Sphere != (Object)null)
			{
				tk.Sphere.transform.position = position;
				tk.Sphere.transform.localScale = Vector3.one * SphereRadius * 2f;
			}
		}
		else
		{
			tk.DestroySphere();
		}
		float primaryAxis = controller._primaryAxis;
		if (!tk.IsActive)
		{
			if (primaryAxis >= GrabThreshold && (Object)(object)hand.m_CurrentAttachedGO == (Object)null)
			{
				if (!tk.InputWasDown)
				{
					tk.InputWasDown = true;
					TryForceGrab(tk, hand);
				}
			}
			else if (primaryAxis < ReleaseThreshold)
			{
				tk.InputWasDown = false;
			}
			return;
		}
		if (primaryAxis < ReleaseThreshold)
		{
			tk.InputWasDown = false;
			tk.Drop(FlingBoost);
			return;
		}
		if ((Object)(object)hand.m_CurrentAttachedGO != (Object)null)
		{
			tk.Drop(0f);
			return;
		}
		if ((Object)(object)tk.RB == (Object)null)
		{
			tk.Drop(0f);
			return;
		}
		try
		{
			if ((Object)(object)((Component)tk.RB).gameObject == (Object)null || !((Component)tk.RB).gameObject.activeInHierarchy)
			{
				tk.Drop(0f);
				return;
			}
		}
		catch
		{
			tk.Drop(0f);
			return;
		}
		float y = controller._thumbstickAxis.y;
		if (Mathf.Abs(y) > 0.15f)
		{
			tk.Distance += y * DistanceScrollSpeed * Time.deltaTime;
			tk.Distance = Mathf.Clamp(tk.Distance, 0.5f, 100f);
		}
		Vector3 val = (transform.position + transform.forward * tk.Distance - tk.RB.position) * HoldStiffness;
		tk.RB.velocity = Vector3.Lerp(tk.RB.velocity, val, 0.5f);
		tk.RB.AddForce(-Physics.gravity, (ForceMode)5);
		Rigidbody rB = tk.RB;
		rB.angularVelocity *= 0.9f;
		if (ShowBeam)
		{
			if ((Object)(object)tk.Beam == (Object)null)
			{
				tk.CreateBeam();
			}
			if ((Object)(object)tk.Beam != (Object)null)
			{
				tk.Beam.SetPosition(0, transform.position);
				tk.Beam.SetPosition(1, tk.RB.position);
			}
		}
		else
		{
			tk.DestroyBeam();
		}
	}

	private void TryForceGrab(TKState tk, Hand hand)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: 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_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: 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_009a: Unknown result type (might be due to invalid IL or missing references)
		Transform transform = ((Component)hand).transform;
		Vector3 val = transform.position + transform.forward * SphereOffset;
		Collider[] array = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(val, SphereRadius, -1, (QueryTriggerInteraction)1));
		if (array == null || array.Length == 0)
		{
			return;
		}
		Rigidbody val2 = null;
		float num = float.MaxValue;
		Collider[] array2 = array;
		foreach (Collider val3 in array2)
		{
			if (val3.isTrigger)
			{
				continue;
			}
			Rigidbody componentInParent = ((Component)val3).GetComponentInParent<Rigidbody>();
			if ((Object)(object)componentInParent == (Object)null || componentInParent.isKinematic)
			{
				continue;
			}
			RigManager componentInParent2 = ((Component)componentInParent).GetComponentInParent<RigManager>();
			if (!((Object)(object)componentInParent2 != (Object)null) || !FusionPlayer.IsLocalPlayer(componentInParent2))
			{
				float num2 = Vector3.Distance(val, componentInParent.position);
				if (num2 < num)
				{
					num = num2;
					val2 = componentInParent;
				}
			}
		}
		if (!((Object)(object)val2 == (Object)null))
		{
			float num3 = Vector3.Distance(transform.position, val2.position);
			if (num3 < 0.5f)
			{
				num3 = 0.5f;
			}
			tk.Activate(val2, num3);
			MelonLogger.Msg($"[TK] Force grabbed: {((Object)((Component)val2).gameObject).name} at {num3:F1}m");
		}
	}

	public override void OnDeinitializeMelon()
	{
		RightTK.Drop(0f);
		RightTK.DestroySphere();
		LeftTK.Drop(0f);
		LeftTK.DestroySphere();
		SavePrefs();
	}
}
public class TKState
{
	public bool IsActive;

	public Rigidbody RB;

	public float Distance = 5f;

	public bool InputWasDown;

	public LineRenderer Beam;

	public GameObject Sphere;

	private float _origDrag;

	private float _origAngDrag = 0.05f;

	private bool _origGravity = true;

	public void Activate(Rigidbody rb, float dist)
	{
		_origDrag = rb.drag;
		_origAngDrag = rb.angularDrag;
		_origGravity = rb.useGravity;
		rb.useGravity = false;
		rb.drag = 0f;
		rb.angularDrag = 2f;
		RB = rb;
		Distance = dist;
		IsActive = true;
	}

	public void Drop(float flingBoost)
	{
		//IL_0058: 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)
		if ((Object)(object)RB != (Object)null)
		{
			try
			{
				RB.useGravity = _origGravity;
				RB.drag = _origDrag;
				RB.angularDrag = _origAngDrag;
				if (flingBoost > 0f && flingBoost != 1f)
				{
					Rigidbody rB = RB;
					rB.velocity *= flingBoost;
				}
			}
			catch
			{
			}
		}
		RB = null;
		IsActive = false;
		DestroyBeam();
	}

	public void CreateBeam()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Expected O, but got Unknown
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			GameObject val = new GameObject("TK_Beam");
			Object.DontDestroyOnLoad((Object)(object)val);
			Beam = val.AddComponent<LineRenderer>();
			Beam.positionCount = 2;
			Beam.startWidth = 0.005f;
			Beam.endWidth = 0.005f;
			((Renderer)Beam).material = new Material(Shader.Find("Sprites/Default"));
			Beam.startColor = new Color(0.6f, 0.2f, 1f, 0.7f);
			Beam.endColor = new Color(1f, 0.4f, 1f, 0.3f);
		}
		catch
		{
			Beam = null;
		}
	}

	public void DestroyBeam()
	{
		if ((Object)(object)Beam != (Object)null)
		{
			try
			{
				Object.Destroy((Object)(object)((Component)Beam).gameObject);
			}
			catch
			{
			}
			Beam = null;
		}
	}

	public void CreateSphere(float radius)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Expected O, but got Unknown
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Sphere = GameObject.CreatePrimitive((PrimitiveType)0);
			((Object)Sphere).name = "TK_DetectionSphere";
			Object.DontDestroyOnLoad((Object)(object)Sphere);
			Sphere.transform.localScale = Vector3.one * radius * 2f;
			Collider component = Sphere.GetComponent<Collider>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			MeshRenderer component2 = Sphere.GetComponent<MeshRenderer>();
			if ((Object)(object)component2 != (Object)null)
			{
				Material val = new Material(Shader.Find("Sprites/Default"));
				val.color = new Color(0.6f, 0.2f, 1f, 0.15f);
				((Renderer)component2).material = val;
			}
		}
		catch
		{
			Sphere = null;
		}
	}

	public void DestroySphere()
	{
		if ((Object)(object)Sphere != (Object)null)
		{
			try
			{
				Object.Destroy((Object)(object)Sphere);
			}
			catch
			{
			}
			Sphere = null;
		}
	}

	public void UpdateSphereSize(float radius)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: 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)
		if ((Object)(object)Sphere != (Object)null)
		{
			Sphere.transform.localScale = Vector3.one * radius * 2f;
		}
	}
}