Decompiled source of CursedIrisTelekinesis v0.7.2

Mods/IrisTelekinesis.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BoneLib.BoneMenu;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Bonelab;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Warehouse;
using Il2CppSystem;
using IrisTelekinesis;
using MelonLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.XR;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(IrisMod), "Cursed Iris Telekinesis", "0.7.2", "Alway's Iris", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("IrisTelekinesis")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("IrisTelekinesis")]
[assembly: AssemblyTitle("IrisTelekinesis")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace IrisTelekinesis
{
	public class IrisMod : MelonMod
	{
		private const string AvatarBarcode = "AlwaysIris.CursedIris.Avatar.CursedIris";

		private const float GrabThreshold = 0.65f;

		private const float ReleaseThreshold = 0.3f;

		private const float MinDistance = 0.7f;

		private const float MaxDistance = 15f;

		private float zoomSpeed = 3f;

		private float dezoomSpeed = 3f;

		private static readonly Color Purple = new Color(0.65f, 0.12f, 1f, 1f);

		private bool masterEnabled = true;

		private bool lasersEnabled = true;

		private bool npcEnabled = true;

		private bool distanceEnabled = true;

		private bool useLeftHand = false;

		private bool bothHandsEnabled = true;

		private bool avatarActive;

		private bool shortcutLatched;

		private float nextToggleAllowed;

		private float nextAvatarCheck;

		private float nextErrorLog;

		private string lastAvatar = "";

		private RigManager? currentRig;

		private Material? laserMaterial;

		private readonly TKState leftTK = new TKState();

		private readonly TKState rightTK = new TKState();

		private GameObject? popupObject;

		private TextMesh? popupText;

		private float popupExpires;

		public override void OnInitializeMelon()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_010f: Unknown result type (might be due to invalid IL or missing references)
			MelonLogger.Msg("Cursed Iris Telekinesis v0.7.2 - une ou deux mains, commandes PSVR2");
			try
			{
				Page val = Page.Root.CreatePage("Cursed Iris Telekinesis", Purple, 0, true);
				val.CreateBool("Telekinesie (general)", Color.white, true, (Action<bool>)delegate(bool value)
				{
					SetMaster(value);
				});
				val.CreateBool("Lasers violets", Purple, true, (Action<bool>)delegate(bool value)
				{
					lasersEnabled = value;
					if (!value)
					{
						HideLasers();
					}
				});
				val.CreateBool("Telekinesie PNJ", Color.white, true, (Action<bool>)delegate(bool value)
				{
					npcEnabled = value;
				});
				val.CreateBool("Distance grip / bouton", Color.white, true, (Action<bool>)delegate(bool value)
				{
					distanceEnabled = value;
				});
				val.CreateBool("Utiliser main gauche (sinon droite)", Color.white, false, (Action<bool>)delegate(bool value)
				{
					SetActiveHand(value);
				});
				val.CreateBool("Telekinesie sur les deux mains", Color.white, false, (Action<bool>)delegate(bool value)
				{
					SetBothHands(value);
				});
				val.CreateFloat("Vitesse Zoom (Croix / Carre)", Color.white, 3f, 0.5f, 0.5f, 10f, (Action<float>)delegate(float value)
				{
					zoomSpeed = value;
				});
				val.CreateFloat("Vitesse Dezoom (R1 / L1)", Color.white, 3f, 0.5f, 0.5f, 10f, (Action<float>)delegate(float value)
				{
					dezoomSpeed = value;
				});
			}
			catch (Exception ex)
			{
				MelonLogger.Error("[MENU] " + ex);
			}
		}

		public override void OnUpdate()
		{
			try
			{
				CheckJoystickShortcut();
				UpdatePopup();
				if (!masterEnabled)
				{
					ReleaseAll();
					HideLasers();
					return;
				}
				PlayerRefs val = Object.FindObjectOfType<PlayerRefs>();
				if ((Object)(object)val == (Object)null || (Object)(object)val.PlayerRigManager == (Object)null)
				{
					ResetPlayer();
					return;
				}
				RigManager val2 = (currentRig = val.PlayerRigManager);
				if (Time.time >= nextAvatarCheck)
				{
					nextAvatarCheck = Time.time + 0.25f;
					CheckAvatar(val2);
				}
				if (!avatarActive || (Object)(object)val2.physicsRig == (Object)null)
				{
					ReleaseAll();
					HideLasers();
					return;
				}
				Hand leftHand = val2.physicsRig.leftHand;
				Hand rightHand = val2.physicsRig.rightHand;
				if (bothHandsEnabled)
				{
					UpdateActiveHand(leftTK, leftHand, "GAUCHE", isLeft: true);
					UpdateActiveHand(rightTK, rightHand, "DROITE", isLeft: false);
					return;
				}
				TKState tKState = (useLeftHand ? rightTK : leftTK);
				tKState.Release(0f);
				HideLaser(tKState);
				if (useLeftHand)
				{
					UpdateActiveHand(leftTK, leftHand, "GAUCHE", isLeft: true);
				}
				else
				{
					UpdateActiveHand(rightTK, rightHand, "DROITE", isLeft: false);
				}
			}
			catch (Exception ex)
			{
				ReleaseAll();
				HideLasers();
				if (Time.time >= nextErrorLog)
				{
					nextErrorLog = Time.time + 5f;
					MelonLogger.Error("[TK] " + ex);
				}
			}
		}

		private void UpdateActiveHand(TKState state, Hand? hand, string side, bool isLeft)
		{
			UpdateHand(state, hand, side);
			if (distanceEnabled && state.Active && (Object)(object)state.Body != (Object)null)
			{
				float? obj;
				if (hand == null)
				{
					obj = null;
				}
				else
				{
					BaseController controller = hand.Controller;
					obj = ((controller != null) ? new float?(controller.GetGripForce()) : ((float?)null));
				}
				float? num = obj;
				float valueOrDefault = num.GetValueOrDefault();
				bool flag = valueOrDefault > 0.5f;
				bool primaryButton = GetPrimaryButton(isLeft);
				if (primaryButton != flag)
				{
					float delta = (flag ? dezoomSpeed : (0f - zoomSpeed)) * Time.deltaTime;
					ChangeDistance(state, delta);
				}
			}
			UpdateHeldObject(state, hand);
			UpdateLaser(state, hand);
		}

		private void SetActiveHand(bool left)
		{
			if (useLeftHand != left)
			{
				ReleaseAll();
				HideLasers();
				useLeftHand = left;
				leftTK.InputWasDown = true;
				rightTK.InputWasDown = true;
				MelonLogger.Msg("[MAIN] " + (useLeftHand ? "GAUCHE" : "DROITE"));
			}
		}

		private void SetBothHands(bool enabled)
		{
			if (bothHandsEnabled != enabled)
			{
				ReleaseAll();
				HideLasers();
				bothHandsEnabled = enabled;
				leftTK.InputWasDown = true;
				rightTK.InputWasDown = true;
				MelonLogger.Msg("[MAINS] " + (enabled ? "DEUX MAINS" : "UNE MAIN"));
			}
		}

		private bool GetPrimaryButton(bool isLeft)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			XRNode val = (XRNode)(isLeft ? 4 : 5);
			InputDevice deviceAtXRNode = InputDevices.GetDeviceAtXRNode(val);
			bool flag = false;
			return ((InputDevice)(ref deviceAtXRNode)).isValid && ((InputDevice)(ref deviceAtXRNode)).TryGetFeatureValue(CommonUsages.primaryButton, ref flag) && flag;
		}

		private void CheckJoystickShortcut()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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)
			InputDevice deviceAtXRNode = InputDevices.GetDeviceAtXRNode((XRNode)4);
			InputDevice deviceAtXRNode2 = InputDevices.GetDeviceAtXRNode((XRNode)5);
			bool flag = false;
			bool flag2 = false;
			bool flag3 = ((InputDevice)(ref deviceAtXRNode)).isValid && ((InputDevice)(ref deviceAtXRNode)).TryGetFeatureValue(CommonUsages.primary2DAxisClick, ref flag);
			bool flag4 = ((InputDevice)(ref deviceAtXRNode2)).isValid && ((InputDevice)(ref deviceAtXRNode2)).TryGetFeatureValue(CommonUsages.primary2DAxisClick, ref flag2);
			if (!(flag3 && flag4 && flag && flag2))
			{
				shortcutLatched = false;
			}
			else if (!shortcutLatched && !(Time.unscaledTime < nextToggleAllowed))
			{
				shortcutLatched = true;
				nextToggleAllowed = Time.unscaledTime + 0.5f;
				SetMaster(!masterEnabled);
			}
		}

		private void SetMaster(bool value)
		{
			if (masterEnabled != value)
			{
				masterEnabled = value;
				if (!masterEnabled)
				{
					ReleaseAll();
					HideLasers();
					leftTK.InputWasDown = false;
					rightTK.InputWasDown = false;
				}
				else
				{
					leftTK.InputWasDown = true;
					rightTK.InputWasDown = true;
				}
				string message = (masterEnabled ? "Votre telekinesie a ete activee\n- Iris" : "Votre telekinesie a ete desactivee\n- Iris");
				ShowPopup(message);
				MelonLogger.Msg("[MASTER] " + (masterEnabled ? "ACTIVEE" : "DESACTIVEE"));
			}
		}

		private void ShowPopup(string message)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)popupObject == (Object)null)
			{
				popupObject = new GameObject("CursedIris_StatusPopup");
				popupText = popupObject.AddComponent<TextMesh>();
				popupText.fontSize = 64;
				popupText.characterSize = 0.009f;
				popupText.anchor = (TextAnchor)4;
				popupText.alignment = (TextAlignment)1;
				popupText.color = Color.white;
			}
			if ((Object)(object)popupText != (Object)null)
			{
				popupText.text = message;
			}
			popupExpires = Time.unscaledTime + 2.5f;
			popupObject.SetActive(true);
			PositionPopup();
		}

		private void UpdatePopup()
		{
			if (!((Object)(object)popupObject == (Object)null))
			{
				if (Time.unscaledTime >= popupExpires)
				{
					popupObject.SetActive(false);
				}
				else
				{
					PositionPopup();
				}
			}
		}

		private void PositionPopup()
		{
			//IL_003c: 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_004c: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)popupObject == (Object)null))
			{
				Camera main = Camera.main;
				if (!((Object)(object)main == (Object)null))
				{
					Transform transform = ((Component)main).transform;
					popupObject.transform.position = transform.position + transform.forward * 1.5f - transform.up * 0.18f;
					popupObject.transform.rotation = Quaternion.LookRotation(-transform.forward, transform.up);
				}
			}
		}

		private void ChangeDistance(TKState state, float delta)
		{
			if (state.Active && !((Object)(object)state.Body == (Object)null))
			{
				state.Distance = Mathf.Clamp(state.Distance + delta, 0.7f, 15f);
			}
		}

		private void UpdateHand(TKState state, Hand? hand, string side)
		{
			//IL_0053: 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_0093: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)hand == (Object)null || (Object)(object)hand.Controller == (Object)null)
			{
				state.Release(0f);
				state.InputWasDown = false;
				state.HasPreviousPosition = false;
				return;
			}
			Transform transform = ((Component)hand).transform;
			float primaryAxis = hand.Controller._primaryAxis;
			Vector3 position = transform.position;
			if (state.HasPreviousPosition && Time.deltaTime > 0.0001f)
			{
				state.HandVelocity = (position - state.PreviousPosition) / Time.deltaTime;
			}
			state.PreviousPosition = position;
			state.HasPreviousPosition = true;
			bool flag = primaryAxis >= 0.65f;
			bool flag2 = primaryAxis < 0.3f;
			if ((Object)(object)hand.m_CurrentAttachedGO != (Object)null)
			{
				state.Release(0f);
				state.InputWasDown = flag;
			}
			else if (!state.Active)
			{
				if (flag2)
				{
					state.InputWasDown = false;
				}
				if (flag && !state.InputWasDown)
				{
					state.InputWasDown = true;
					TryGrab(state, transform, side);
				}
			}
			else if (flag2)
			{
				state.InputWasDown = false;
				state.Release(1.5f);
				MelonLogger.Msg("[TK] " + side + " : projection");
			}
		}

		private void UpdateHeldObject(TKState state, Hand? hand)
		{
			//IL_003b: 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_004c: 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_0056: 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)
			//IL_0059: 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)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_0075: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			if (state.Active && !((Object)(object)state.Body == (Object)null) && !((Object)(object)hand == (Object)null))
			{
				Rigidbody body = state.Body;
				Transform transform = ((Component)hand).transform;
				Vector3 val = transform.position + transform.forward * state.Distance;
				Vector3 val2 = (val - body.position) * 15f;
				body.velocity = Vector3.Lerp(body.velocity, val2, 0.5f);
				body.AddForce(-Physics.gravity, (ForceMode)5);
				body.angularVelocity *= 0.9f;
			}
		}

		private void TryGrab(TKState state, Transform handTransform, string side)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = handTransform.position;
			Vector3 forward = handTransform.forward;
			Collider[] array = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(position + forward * 0.5f, 0.3f, -1, (QueryTriggerInteraction)1));
			Rigidbody val = null;
			float num = float.MaxValue;
			Collider[] array2 = array;
			foreach (Collider val2 in array2)
			{
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				Rigidbody attachedRigidbody = val2.attachedRigidbody;
				if (IsValidBody(attachedRigidbody))
				{
					float num2 = Vector3.Distance(position, attachedRigidbody.position);
					if (num2 < num)
					{
						num = num2;
						val = attachedRigidbody;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				RaycastHit[] array3 = Il2CppArrayBase<RaycastHit>.op_Implicit((Il2CppArrayBase<RaycastHit>)(object)Physics.RaycastAll(new Ray(position, forward), 15f, -1, (QueryTriggerInteraction)1));
				RaycastHit[] array4 = array3;
				for (int j = 0; j < array4.Length; j++)
				{
					RaycastHit val3 = array4[j];
					if (!((Object)(object)((RaycastHit)(ref val3)).collider == (Object)null))
					{
						Rigidbody attachedRigidbody2 = ((RaycastHit)(ref val3)).collider.attachedRigidbody;
						if (IsValidBody(attachedRigidbody2) && ((RaycastHit)(ref val3)).distance < num)
						{
							num = ((RaycastHit)(ref val3)).distance;
							val = attachedRigidbody2;
						}
					}
				}
			}
			if (!((Object)(object)val == (Object)null))
			{
				state.Body = val;
				state.Active = true;
				state.Distance = Mathf.Clamp(num, 0.7f, 15f);
				MelonLogger.Msg("[TK] " + side + " : OBJET SAISI : " + ((Object)val).name);
			}
		}

		private bool IsValidBody(Rigidbody? body)
		{
			if ((Object)(object)body == (Object)null || body.isKinematic)
			{
				return false;
			}
			Transform transform = ((Component)body).transform;
			if ((Object)(object)currentRig != (Object)null)
			{
				Transform transform2 = ((Component)currentRig).transform;
				if ((Object)(object)transform == (Object)(object)transform2 || transform.IsChildOf(transform2))
				{
					return false;
				}
				if ((Object)(object)currentRig.physicsRig != (Object)null)
				{
					Transform transform3 = ((Component)currentRig.physicsRig).transform;
					if ((Object)(object)transform == (Object)(object)transform3 || transform.IsChildOf(transform3))
					{
						return false;
					}
				}
			}
			if ((Object)(object)((Component)body).GetComponentInParent<RigManager>() != (Object)null)
			{
				return false;
			}
			if (!npcEnabled && IsLikelyNPC(transform))
			{
				return false;
			}
			if ((Object)(object)leftTK.Body == (Object)(object)body || (Object)(object)rightTK.Body == (Object)(object)body)
			{
				return false;
			}
			return true;
		}

		private bool IsLikelyNPC(Transform transform)
		{
			Transform val = transform;
			while ((Object)(object)val != (Object)null)
			{
				string text = ((Object)val).name.ToLowerInvariant();
				if (text.Contains("npc") || text.Contains("ford") || text.Contains("nullbody"))
				{
					return true;
				}
				val = val.parent;
			}
			return false;
		}

		private void EnsureLaser(TKState state)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0051: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)state.Laser != (Object)null)
			{
				return;
			}
			GameObject val = new GameObject("CursedIris_Telekinesis_Laser");
			LineRenderer val2 = val.AddComponent<LineRenderer>();
			val2.useWorldSpace = true;
			val2.positionCount = 2;
			val2.startWidth = 0.012f;
			val2.endWidth = 0.006f;
			val2.startColor = Purple;
			val2.endColor = Purple;
			val2.numCapVertices = 6;
			if ((Object)(object)laserMaterial == (Object)null)
			{
				Shader val3 = Shader.Find("Sprites/Default");
				if ((Object)(object)val3 != (Object)null)
				{
					laserMaterial = new Material(val3);
					laserMaterial.color = Purple;
				}
			}
			if ((Object)(object)laserMaterial != (Object)null)
			{
				((Renderer)val2).material = laserMaterial;
			}
			((Renderer)val2).enabled = false;
			state.Laser = val2;
		}

		private void UpdateLaser(TKState state, Hand? hand)
		{
			//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_0083: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			if (!lasersEnabled || (Object)(object)hand == (Object)null || (Object)(object)hand.Controller == (Object)null || hand.Controller._primaryAxis < 0.65f || (Object)(object)hand.m_CurrentAttachedGO != (Object)null)
			{
				HideLaser(state);
				return;
			}
			Transform transform = ((Component)hand).transform;
			EnsureLaser(state);
			if ((Object)(object)state.Laser == (Object)null)
			{
				return;
			}
			Vector3 position = transform.position;
			Vector3 forward = transform.forward;
			Vector3 val = position + forward * 15f;
			if (state.Active && (Object)(object)state.Body != (Object)null)
			{
				val = state.Body.position;
			}
			else
			{
				RaycastHit[] array = Il2CppArrayBase<RaycastHit>.op_Implicit((Il2CppArrayBase<RaycastHit>)(object)Physics.RaycastAll(new Ray(position, forward), 15f, -1, (QueryTriggerInteraction)1));
				float num = 15f;
				RaycastHit[] array2 = array;
				for (int i = 0; i < array2.Length; i++)
				{
					RaycastHit val2 = array2[i];
					if (!((Object)(object)((RaycastHit)(ref val2)).collider == (Object)null))
					{
						Rigidbody attachedRigidbody = ((RaycastHit)(ref val2)).collider.attachedRigidbody;
						if (IsValidBody(attachedRigidbody) && ((RaycastHit)(ref val2)).distance < num)
						{
							num = ((RaycastHit)(ref val2)).distance;
							val = ((RaycastHit)(ref val2)).point;
						}
					}
				}
			}
			state.Laser.SetPosition(0, position);
			state.Laser.SetPosition(1, val);
			((Renderer)state.Laser).enabled = true;
		}

		private void HideLaser(TKState state)
		{
			if ((Object)(object)state.Laser != (Object)null)
			{
				((Renderer)state.Laser).enabled = false;
			}
		}

		private void HideLasers()
		{
			HideLaser(leftTK);
			HideLaser(rightTK);
		}

		private void ReleaseAll()
		{
			leftTK.Release(0f);
			rightTK.Release(0f);
		}

		private void ResetPlayer()
		{
			currentRig = null;
			avatarActive = false;
			lastAvatar = "";
			ReleaseAll();
			HideLasers();
		}

		private void CheckAvatar(RigManager rig)
		{
			string text = "";
			try
			{
				AvatarCrateReference avatarCrate = rig.AvatarCrate;
				if (avatarCrate != null && ((ScannableReference)avatarCrate).Barcode != (Barcode)null)
				{
					text = ((Object)((ScannableReference)avatarCrate).Barcode).ToString();
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("[AVATAR] " + ex.Message);
			}
			if (text != lastAvatar)
			{
				lastAvatar = text;
				MelonLogger.Msg("[AVATAR] " + text);
			}
			bool flag = string.Equals(text, "AlwaysIris.CursedIris.Avatar.CursedIris", StringComparison.Ordinal);
			if (flag != avatarActive)
			{
				avatarActive = flag;
				if (flag)
				{
					MelonLogger.Msg("[TK] Cursed Iris detecte !");
					return;
				}
				ReleaseAll();
				HideLasers();
			}
		}

		public override void OnDeinitializeMelon()
		{
			ReleaseAll();
			if ((Object)(object)leftTK.Laser != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)leftTK.Laser).gameObject);
			}
			if ((Object)(object)rightTK.Laser != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)rightTK.Laser).gameObject);
			}
			if ((Object)(object)laserMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)laserMaterial);
			}
			if ((Object)(object)popupObject != (Object)null)
			{
				Object.Destroy((Object)(object)popupObject);
			}
		}
	}
	public class TKState
	{
		public Rigidbody? Body;

		public LineRenderer? Laser;

		public bool Active;

		public bool InputWasDown;

		public float Distance;

		public Vector3 PreviousPosition;

		public Vector3 HandVelocity;

		public bool HasPreviousPosition;

		public void Release(float throwStrength)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if (Active && (Object)(object)Body != (Object)null && throwStrength > 0f)
			{
				Vector3 val = Vector3.ClampMagnitude(HandVelocity, 12f);
				Rigidbody? body = Body;
				body.velocity += val * throwStrength;
			}
			Body = null;
			Active = false;
		}
	}
}