Decompiled source of Electricity v1.0.0

Mods/Electricity.dll

Decompiled 9 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BoneLib;
using BoneLib.BoneMenu;
using BoneLib.Notifications;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Bonelab;
using Il2CppSLZ.Data;
using Il2CppSLZ.Interaction;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Pool;
using Il2CppSLZ.Marrow.Warehouse;
using MelonLoader;
using MelonLoader.Utils;
using ThirdEyeBonelabMod;
using ThirdEyeBonelabMod.Devices;
using ThirdEyeBonelabMod.Guns;
using ThirdEyeBonelabMod.Motor;
using ThirdEyeBonelabMod.Power;
using ThirdEyeBonelabMod.Props;
using ThirdEyeBonelabMod.Tools;
using ThirdEyeElectricity;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Electricity), "ThirdEye Electricity", "1.0.0", "RUDYHILL", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("ThirdEyeElectricity")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ThirdEyeElectricity")]
[assembly: AssemblyTitle("ThirdEyeElectricity")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ThirdEyeBonelabMod
{
	public class PropShell
	{
		public readonly Rigidbody body;

		public readonly Transform parts;

		public readonly Material template;

		public readonly int layer;

		private readonly Vector3 originalScale;

		private readonly float originalMass;

		private readonly List<Renderer> hiddenRenderers = new List<Renderer>();

		private readonly List<SphereCollider> shrunkColliders = new List<SphereCollider>();

		private readonly List<float> shrunkRadii = new List<float>();

		private readonly List<Collider> disabledColliders = new List<Collider>();

		private Grips grips;

		public static bool OwnBodies;

		public bool SurfaceGrips = true;

		private readonly List<Collider> hiddenReach = new List<Collider>();

		private static Material levelTemplate;

		private static Texture2D matteMap;

		public static void TakeOwnBody(ref GameObject prop, ref Rigidbody body)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_005d: 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)
			if (OwnBodies && !((Object)(object)prop == (Object)null) && !((Object)(object)body == (Object)null))
			{
				Poolee val = prop.GetComponent<Poolee>();
				if ((Object)(object)val == (Object)null)
				{
					val = ((Component)body).GetComponentInParent<Poolee>();
				}
				if (!((Object)(object)val == (Object)null))
				{
					GameObject val2 = new GameObject("ThirdEyeItem");
					val2.layer = 1024;
					val2.transform.SetPositionAndRotation(body.position, body.rotation);
					val2.AddComponent<SphereCollider>().radius = 0.02f;
					Rigidbody val3 = val2.AddComponent<Rigidbody>();
					val3.mass = 1f;
					val3.angularDrag = 0.5f;
					MotorManager.Forget(body);
					val.Despawn();
					prop = val2;
					body = val3;
				}
			}
		}

		public static GameObject Owner(Rigidbody body)
		{
			if ((Object)(object)body == (Object)null)
			{
				return null;
			}
			Poolee componentInParent = ((Component)body).GetComponentInParent<Poolee>();
			if (!((Object)(object)componentInParent != (Object)null))
			{
				return ((Component)body).gameObject;
			}
			return ((Component)componentInParent).gameObject;
		}

		public static void Discard(GameObject owner)
		{
			if ((Object)(object)owner == (Object)null)
			{
				return;
			}
			Poolee component = owner.GetComponent<Poolee>();
			if ((Object)(object)component != (Object)null)
			{
				if (owner.activeInHierarchy)
				{
					component.Despawn();
				}
			}
			else
			{
				Object.Destroy((Object)(object)owner);
			}
		}

		public PropShell(GameObject prop, Rigidbody body, float scale, float mass, string name)
		{
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Expected O, but got Unknown
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			this.body = body;
			Transform transform = ((Component)body).transform;
			foreach (Renderer componentsInChild in prop.GetComponentsInChildren<Renderer>())
			{
				if (!((Object)(object)componentsInChild == (Object)null) && componentsInChild.enabled)
				{
					if ((Object)(object)template == (Object)null)
					{
						template = componentsInChild.sharedMaterial;
					}
					componentsInChild.enabled = false;
					hiddenRenderers.Add(componentsInChild);
				}
			}
			if ((Object)(object)template == (Object)null)
			{
				template = LevelTemplate();
			}
			layer = ((Component)body).gameObject.layer;
			Collider componentInChildren = prop.GetComponentInChildren<Collider>();
			if ((Object)(object)componentInChildren != (Object)null)
			{
				layer = ((Component)componentInChildren).gameObject.layer;
			}
			foreach (Collider componentsInChild2 in prop.GetComponentsInChildren<Collider>())
			{
				if (!((Object)(object)componentsInChild2 == (Object)null) && !componentsInChild2.isTrigger && componentsInChild2.enabled)
				{
					SphereCollider val = ((Il2CppObjectBase)componentsInChild2).TryCast<SphereCollider>();
					if ((Object)(object)val != (Object)null)
					{
						shrunkColliders.Add(val);
						shrunkRadii.Add(val.radius);
						val.radius = 0.005f;
					}
					else
					{
						componentsInChild2.enabled = false;
						disabledColliders.Add(componentsInChild2);
					}
				}
			}
			originalScale = transform.localScale;
			originalMass = body.mass;
			transform.localScale = originalScale * scale;
			body.mass = mass;
			GameObject val2 = new GameObject(name);
			val2.layer = layer;
			val2.transform.SetParent(transform, false);
			float x = transform.lossyScale.x;
			val2.transform.localScale = Vector3.one / ((x > 0.0001f) ? x : 1f);
			parts = val2.transform;
		}

		public void RecalculateMass()
		{
			body.ResetCenterOfMass();
			body.ResetInertiaTensor();
			if (SurfaceGrips)
			{
				if (grips == null)
				{
					grips = new Grips(body, parts);
				}
				grips.Refresh();
			}
		}

		public void HideBallGrip()
		{
			GameObject val = Owner(body);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			foreach (Grip componentsInChild in val.GetComponentsInChildren<Grip>(true))
			{
				if ((Object)(object)componentsInChild == (Object)null || ((Object)((Component)componentsInChild).gameObject).name.StartsWith("ThirdEye", StringComparison.Ordinal))
				{
					continue;
				}
				foreach (Collider component in ((Component)componentsInChild).GetComponents<Collider>())
				{
					if ((Object)(object)component != (Object)null && component.isTrigger && component.enabled)
					{
						component.enabled = false;
						hiddenReach.Add(component);
					}
				}
			}
		}

		public void LetGo()
		{
			try
			{
				InteractableHost val = (((Object)(object)body != (Object)null) ? ((Component)body).GetComponentInParent<InteractableHost>() : null);
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				foreach (Grip componentsInChild in ((Component)val).GetComponentsInChildren<Grip>(true))
				{
					if ((Object)(object)componentsInChild != (Object)null && componentsInChild.attachedHands != null && componentsInChild.attachedHands.Count > 0)
					{
						componentsInChild.ForceDetach();
					}
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("An item could not be let go of: " + ex.Message);
			}
		}

		public void Restore()
		{
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			grips?.Clear();
			grips = null;
			Handles.Clear(body);
			MotorManager.Forget(body);
			if ((Object)(object)parts != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)parts).gameObject);
			}
			for (int i = 0; i < shrunkColliders.Count; i++)
			{
				if ((Object)(object)shrunkColliders[i] != (Object)null)
				{
					shrunkColliders[i].radius = shrunkRadii[i];
				}
			}
			foreach (Collider disabledCollider in disabledColliders)
			{
				if ((Object)(object)disabledCollider != (Object)null)
				{
					disabledCollider.enabled = true;
				}
			}
			foreach (Collider item in hiddenReach)
			{
				if ((Object)(object)item != (Object)null)
				{
					item.enabled = true;
				}
			}
			hiddenReach.Clear();
			foreach (Renderer hiddenRenderer in hiddenRenderers)
			{
				if ((Object)(object)hiddenRenderer != (Object)null)
				{
					hiddenRenderer.enabled = true;
				}
			}
			if ((Object)(object)body != (Object)null)
			{
				((Component)body).transform.localScale = originalScale;
				body.mass = originalMass;
				body.ResetCenterOfMass();
				body.ResetInertiaTensor();
			}
		}

		public static Material LevelTemplate()
		{
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Expected O, but got Unknown
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Expected O, but got Unknown
			if ((Object)(object)levelTemplate != (Object)null)
			{
				return levelTemplate;
			}
			Material val = null;
			Material val2 = null;
			foreach (MeshRenderer item in Object.FindObjectsOfType<MeshRenderer>())
			{
				Material val3 = (((Object)(object)item != (Object)null) ? ((Renderer)item).sharedMaterial : null);
				if (!((Object)(object)val3 == (Object)null) && !((Object)(object)val3.shader == (Object)null) && !(((Object)(object)((Component)item).transform.root != (Object)null) ? ((Object)((Component)item).transform.root).name : "").StartsWith("ThirdEye", StringComparison.Ordinal) && Solid(val3))
				{
					string name = ((Object)val3.shader).name;
					if (name == "SLZ/LitMAS/LitMAS Standard")
					{
						val2 = val3;
						break;
					}
					string text = name.ToLowerInvariant();
					if ((Object)(object)val == (Object)null && text.Contains("lit") && !text.Contains("unlit") && val3.HasProperty("_BaseMap"))
					{
						val = val3;
					}
				}
			}
			Material val4 = (((Object)(object)val2 != (Object)null) ? val2 : val);
			if ((Object)(object)val4 == (Object)null)
			{
				foreach (Shader item2 in Resources.FindObjectsOfTypeAll<Shader>())
				{
					if ((Object)(object)item2 != (Object)null && ((Object)item2).name == "SLZ/LitMAS/LitMAS Standard")
					{
						val4 = new Material(item2);
						break;
					}
				}
			}
			if ((Object)(object)val4 == (Object)null)
			{
				return null;
			}
			levelTemplate = new Material(val4);
			MakeSolid(levelTemplate);
			return levelTemplate;
		}

		public static void ForgetLevel()
		{
			levelTemplate = null;
		}

		private static bool Solid(Material material)
		{
			if (material.renderQueue >= 2450)
			{
				return false;
			}
			if (material.HasProperty("_Surface") && material.GetFloat("_Surface") > 0.5f)
			{
				return false;
			}
			if (material.HasProperty("_ZWrite") && material.GetFloat("_ZWrite") < 0.5f)
			{
				return false;
			}
			return true;
		}

		private static void MakeSolid(Material material)
		{
			if (material.HasProperty("_Surface"))
			{
				material.SetFloat("_Surface", 0f);
			}
			if (material.HasProperty("_ZWrite"))
			{
				material.SetFloat("_ZWrite", 1f);
			}
			if (material.HasProperty("_BlendSrc"))
			{
				material.SetFloat("_BlendSrc", 1f);
			}
			if (material.HasProperty("_BlendDst"))
			{
				material.SetFloat("_BlendDst", 0f);
			}
			if (material.HasProperty("_SrcBlend"))
			{
				material.SetFloat("_SrcBlend", 1f);
			}
			if (material.HasProperty("_DstBlend"))
			{
				material.SetFloat("_DstBlend", 0f);
			}
			if (material.HasProperty("_AlphaClip"))
			{
				material.SetFloat("_AlphaClip", 0f);
			}
			material.DisableKeyword("_SURFACE_TYPE_TRANSPARENT");
			material.DisableKeyword("_ALPHATEST_ON");
			material.DisableKeyword("_ALPHABLEND_ON");
			material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
			material.SetOverrideTag("RenderType", "Opaque");
			material.renderQueue = 2000;
		}

		public static Material MakeMaterial(Material template, Color color, Texture2D albedo = null)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)template == (Object)null)
			{
				return null;
			}
			Material val = new Material(template);
			string[] array = new string[2] { "_BaseMap", "_MainTex" };
			foreach (string text in array)
			{
				if (val.HasProperty(text))
				{
					val.SetTexture(text, (Texture)(object)albedo);
				}
			}
			array = new string[3] { "_BumpMap", "_MetallicGlossMap", "_DetailMap" };
			foreach (string text2 in array)
			{
				if (val.HasProperty(text2))
				{
					val.SetTexture(text2, (Texture)null);
				}
			}
			SetColor(val, color);
			return val;
		}

		public static Material MakeMatte(Material template, Color color, Texture2D albedo = null)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			Material val = MakeMaterial(template, color, albedo);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			if ((Object)(object)matteMap == (Object)null)
			{
				matteMap = new Texture2D(2, 2, (TextureFormat)4, false, true);
				((Object)matteMap).hideFlags = (HideFlags)32;
				for (int i = 0; i < 4; i++)
				{
					matteMap.SetPixel(i % 2, i / 2, new Color(0f, 1f, 0.12f, 1f));
				}
				matteMap.Apply();
			}
			if (val.HasProperty("_MetallicGlossMap"))
			{
				val.SetTexture("_MetallicGlossMap", (Texture)(object)matteMap);
			}
			if (val.HasProperty("_Metallic"))
			{
				val.SetFloat("_Metallic", 0f);
			}
			if (val.HasProperty("_Smoothness"))
			{
				val.SetFloat("_Smoothness", 0.12f);
			}
			if (val.HasProperty("_Glossiness"))
			{
				val.SetFloat("_Glossiness", 0.12f);
			}
			return val;
		}

		public static void SetColor(Material material, Color color)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)material == (Object)null)
			{
				return;
			}
			string[] array = new string[2] { "_BaseColor", "_Color" };
			foreach (string text in array)
			{
				if (material.HasProperty(text))
				{
					material.SetColor(text, color);
				}
			}
		}

		public static GameObject MakeBox(Transform parent, Vector3 center, Quaternion rotation, Vector3 size, Material material, int layer, bool visible)
		{
			//IL_002c: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)obj).name = "ThirdEyeCollider";
			obj.layer = layer;
			obj.transform.SetParent(parent, false);
			obj.transform.localPosition = center;
			obj.transform.localRotation = rotation;
			obj.transform.localScale = size;
			Renderer component = obj.GetComponent<Renderer>();
			if ((Object)(object)component != (Object)null)
			{
				component.enabled = visible;
				if ((Object)(object)material != (Object)null)
				{
					component.sharedMaterial = material;
				}
			}
			return obj;
		}

		public static GameObject MakeCapsule(Transform parent, Vector3 center, Quaternion rotation, float radius, float height, int direction, int layer)
		{
			//IL_0005: 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_0012: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			GameObject val = new GameObject("ThirdEyeCollider")
			{
				layer = layer
			};
			val.transform.SetParent(parent, false);
			val.transform.localPosition = center;
			val.transform.localRotation = rotation;
			CapsuleCollider obj = val.AddComponent<CapsuleCollider>();
			obj.radius = radius;
			obj.height = height;
			obj.direction = direction;
			return val;
		}

		public static GameObject MakeVisual(PrimitiveType type, string name, Material material, int layer)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive(type);
			((Object)obj).name = name;
			obj.layer = layer;
			Collider component = obj.GetComponent<Collider>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			Renderer component2 = obj.GetComponent<Renderer>();
			if ((Object)(object)component2 != (Object)null && (Object)(object)material != (Object)null)
			{
				component2.sharedMaterial = material;
			}
			return obj;
		}

		public static GameObject MakeMesh(Transform parent, Vector3 localPosition, Mesh mesh, Material material, int layer)
		{
			//IL_0005: 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_0012: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_004f: Expected O, but got Unknown
			GameObject val = new GameObject("ThirdEyeModel")
			{
				layer = layer
			};
			val.transform.SetParent(parent, false);
			val.transform.localPosition = localPosition;
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer val2 = val.AddComponent<MeshRenderer>();
			if ((Object)(object)material != (Object)null)
			{
				((Renderer)val2).sharedMaterial = material;
			}
			return val;
		}

		public static void PlaceLine(Transform line, Vector3 from, Vector3 to, 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_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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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)
			Vector3 val = to - from;
			float magnitude = ((Vector3)(ref val)).magnitude;
			line.position = (from + to) * 0.5f;
			if (magnitude > 0.0001f)
			{
				line.rotation = Quaternion.LookRotation(val / magnitude);
			}
			line.localScale = new Vector3(width, width, Mathf.Max(magnitude, 0.0001f));
		}
	}
	public static class Handles
	{
		private const int GripLayer = 15;

		public const string HandleShape = "CylinderGripSmall";

		private static readonly Dictionary<string, HandPose> poses = new Dictionary<string, HandPose>();

		private static readonly HashSet<string> missing = new HashSet<string>();

		private static readonly Dictionary<IntPtr, List<Grip>> made = new Dictionary<IntPtr, List<Grip>>();

		public static HandPose Pose(string name)
		{
			if (poses.TryGetValue(name, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			if (missing.Contains(name))
			{
				return null;
			}
			try
			{
				foreach (HandPose item in Resources.FindObjectsOfTypeAll<HandPose>())
				{
					if ((Object)(object)item != (Object)null && string.Equals(((Object)item).name, name, StringComparison.OrdinalIgnoreCase))
					{
						value = item;
						break;
					}
				}
				if ((Object)(object)value == (Object)null)
				{
					value = FromFile(name);
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("Handles: the hand shape " + name + " could not be read: " + ex.Message);
			}
			if ((Object)(object)value == (Object)null)
			{
				missing.Add(name);
				MelonLogger.Warning("Handles: the game's hand shape " + name + " was not found; items keep their old grip");
				return null;
			}
			((Object)value).hideFlags = (HideFlags)32;
			poses[name] = value;
			MelonLogger.Msg("Handles: using the game's hand shape " + ((Object)value).name);
			return value;
		}

		private static HandPose FromFile(string name)
		{
			string path = Path.Combine(Application.streamingAssetsPath, "aa", "StandaloneWindows64", "deduped_assets_handpose");
			if (!Directory.Exists(path))
			{
				return null;
			}
			string[] files = Directory.GetFiles(path, name.ToLowerInvariant() + "_*.bundle");
			if (files.Length == 0)
			{
				return null;
			}
			AssetBundle val = AssetBundle.LoadFromFile(files[0]);
			if ((Object)(object)val == (Object)null)
			{
				string text = Path.GetFileName(files[0]).ToLowerInvariant();
				foreach (AssetBundle item in (Il2CppArrayBase<AssetBundle>)(object)AssetBundle.GetAllLoadedAssetBundles_Native())
				{
					if ((Object)(object)item == (Object)null || !((Object)item).name.ToLowerInvariant().Contains(name.ToLowerInvariant()))
					{
						continue;
					}
					foreach (Object item2 in (Il2CppArrayBase<Object>)(object)item.LoadAllAssets())
					{
						HandPose val2 = ((item2 != (Object)null) ? ((Il2CppObjectBase)item2).TryCast<HandPose>() : null);
						if ((Object)(object)val2 != (Object)null)
						{
							return val2;
						}
					}
				}
				MelonLogger.Warning("Handles: " + text + " could not be opened");
				return null;
			}
			HandPose result = null;
			try
			{
				foreach (Object item3 in (Il2CppArrayBase<Object>)(object)val.LoadAllAssets())
				{
					HandPose val3 = ((item3 != (Object)null) ? ((Il2CppObjectBase)item3).TryCast<HandPose>() : null);
					if ((Object)(object)val3 != (Object)null)
					{
						result = val3;
						break;
					}
				}
			}
			finally
			{
				val.Unload(false);
			}
			return result;
		}

		public static Grip Fixed(Rigidbody body, Transform parent, Vector3 centre, Vector3 axis, Vector3 across, float radius, float halfLength, IList<Collider> solids, bool eitherWay = true)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return Make(sliding: false, body, parent, centre, axis, across, radius, halfLength, solids, eitherWay);
		}

		public static Grip Sliding(Rigidbody body, Transform parent, Vector3 centre, Vector3 axis, Vector3 across, float radius, float halfLength, IList<Collider> solids)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return Make(sliding: true, body, parent, centre, axis, across, radius, halfLength, solids, eitherWay: true);
		}

		private static Grip Make(bool sliding, Rigidbody body, Transform parent, Vector3 centre, Vector3 axis, Vector3 across, float radius, float halfLength, IList<Collider> solids, bool eitherWay)
		{
			//IL_0043: 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_004a: 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_004e: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_00a8: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Expected O, but got Unknown
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Expected O, but got Unknown
			//IL_008b: 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)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				InteractableHost val = (((Object)(object)body != (Object)null) ? ((Component)body).GetComponentInParent<InteractableHost>() : null);
				HandPose val2 = Pose("CylinderGripSmall");
				if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)parent == (Object)null)
				{
					return null;
				}
				axis = ((Vector3)(ref axis)).normalized;
				Vector3 val3 = Vector3.ProjectOnPlane(across, axis);
				across = ((Vector3)(ref val3)).normalized;
				if (((Vector3)(ref across)).sqrMagnitude < 0.5f)
				{
					val3 = Vector3.ProjectOnPlane((Mathf.Abs(axis.y) < 0.9f) ? Vector3.up : Vector3.forward, axis);
					across = ((Vector3)(ref val3)).normalized;
				}
				GameObject val4 = new GameObject("ThirdEyeHandle");
				val4.SetActive(false);
				val4.layer = 15;
				val4.transform.SetParent(parent, false);
				val4.transform.localPosition = centre;
				val4.transform.localRotation = Quaternion.LookRotation(across, axis);
				val4.transform.localScale = Vector3.one;
				CapsuleCollider val5 = val4.AddComponent<CapsuleCollider>();
				((Collider)val5).isTrigger = true;
				val5.direction = 1;
				val5.radius = Mathf.Max(radius + 0.02f, 0.035f);
				val5.height = halfLength * 2f + val5.radius * 2f;
				GameObject val6 = new GameObject("ThirdEyeHandleTarget");
				val6.transform.SetParent(val4.transform, false);
				val6.transform.localRotation = Quaternion.LookRotation(Vector3.up, Vector3.forward);
				TargetGrip val7;
				if (sliding)
				{
					CylinderGrip obj = val4.AddComponent<CylinderGrip>();
					obj.dynamicFriction = 0.7f;
					obj.staticFriction = 0.9f;
					obj.limit = halfLength;
					obj.hasCapA = true;
					obj.hasCapB = true;
					obj.ignoreFlipOnZ = false;
					obj.rotationalFrictionMult = 1f;
					obj.aspectRatio = 2f;
					obj.variableRadius = false;
					obj.RadiusCurve = new AnimationCurve();
					val7 = (TargetGrip)(object)obj;
				}
				else
				{
					val7 = val4.AddComponent<TargetGrip>();
				}
				((Grip)val7).isThrowable = true;
				((Grip)val7).ignoreGripTargetOnAttach = false;
				((Grip)val7).handPose = val2;
				((Grip)val7).primaryMovementAxis = Vector3.forward;
				((Grip)val7).secondaryMovementAxis = Vector3.up;
				((Grip)val7).gripOptions = (InteractionOptions)8;
				((Grip)val7).priority = 3f;
				((Grip)val7).minBreakForce = float.PositiveInfinity;
				((Grip)val7).maxBreakForce = float.PositiveInfinity;
				((Grip)val7).defaultGripDistance = float.PositiveInfinity;
				((Grip)val7).radius = radius;
				((Grip)val7).targetTransform = val6.transform;
				val7.rotationLimit = 180f;
				val7.rotationPriorityBuffer = 20f;
				val7.targetFlipOnPrimaryAxis = eitherWay;
				val7.targetFlipOnTertiaryAxis = false;
				AnimationCurve val8 = new AnimationCurve();
				val8.AddKey(-180f, -30f);
				val8.AddKey(-50f, -30f);
				val8.AddKey(0f, 0f);
				val8.AddKey(50f, 30f);
				val8.AddKey(180f, 30f);
				((Grip)val7).handleAmplifyCurve = val8;
				List<Collider> list = new List<Collider>();
				if (solids != null)
				{
					foreach (Collider solid in solids)
					{
						if ((Object)(object)solid != (Object)null && !solid.isTrigger)
						{
							list.Add(solid);
						}
					}
				}
				Il2CppReferenceArray<Collider> val9 = new Il2CppReferenceArray<Collider>((long)list.Count);
				for (int i = 0; i < list.Count; i++)
				{
					((Il2CppArrayBase<Collider>)(object)val9)[i] = list[i];
				}
				((Grip)val7).additionalGripColliders = val9;
				ForcePullGrip val10 = val4.GetComponent<ForcePullGrip>();
				if ((Object)(object)val10 == (Object)null)
				{
					val10 = val4.AddComponent<ForcePullGrip>();
				}
				val10._grip = (Grip)(object)val7;
				val10.maxForce = 200f;
				val10.maxSpeed = 6f;
				val4.SetActive(true);
				val.DecorateHostOnChildGrips(val4.transform);
				if (!made.TryGetValue(((Il2CppObjectBase)body).Pointer, out var value))
				{
					value = (made[((Il2CppObjectBase)body).Pointer] = new List<Grip>());
				}
				value.Add((Grip)(object)val7);
				GrabAssist.Register((Grip)(object)val7, val5, val4.transform, body, radius, halfLength);
				return (Grip)(object)val7;
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("Handles: a handle could not be made: " + ex);
				return null;
			}
		}

		public static void Clear(Rigidbody body)
		{
			if ((Object)(object)body == (Object)null || !made.TryGetValue(((Il2CppObjectBase)body).Pointer, out var value))
			{
				return;
			}
			made.Remove(((Il2CppObjectBase)body).Pointer);
			InteractableHost componentInParent = ((Component)body).GetComponentInParent<InteractableHost>();
			foreach (Grip item in value)
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				try
				{
					if (item.attachedHands != null && item.attachedHands.Count > 0)
					{
						item.ForceDetach();
					}
					if ((Object)(object)componentInParent != (Object)null && componentInParent._grips != null)
					{
						componentInParent._grips.Remove(item);
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Warning("Handles: a handle did not let go cleanly. " + ex.Message);
				}
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
		}

		public static void ForgetLevel()
		{
			made.Clear();
			List<string> list = new List<string>();
			foreach (KeyValuePair<string, HandPose> pose in poses)
			{
				if ((Object)(object)pose.Value == (Object)null)
				{
					list.Add(pose.Key);
				}
			}
			foreach (string item in list)
			{
				poses.Remove(item);
			}
		}
	}
	public static class GrabAssist
	{
		private class Entry
		{
			public Grip grip;

			public CapsuleCollider zone;

			public float zoneRadius;

			public float zoneHeight;

			public Transform holder;

			public Rigidbody body;

			public float radius;

			public float half;

			public int state;

			public List<Renderer> look;

			public bool lit;
		}

		public static bool Enabled = true;

		public static bool ShowTarget = true;

		public static float Reach = 0.15f;

		private const float Keep = 0.025f;

		private const float GameFirst = 0.12f;

		private static readonly List<Entry> handles = new List<Entry>();

		private static readonly Entry[] target = new Entry[2];

		private static readonly Vector3[] spots = (Vector3[])(object)new Vector3[2];

		private static readonly Vector3[] palms = (Vector3[])(object)new Vector3[2];

		private static readonly bool[] free = new bool[2];

		private static readonly bool[] down = new bool[2];

		private static readonly float[] takeAt = new float[2] { -1f, -1f };

		private static readonly int[] tries = new int[2];

		private static readonly Entry[] aimed = new Entry[2];

		private static readonly Transform[] dots = (Transform[])(object)new Transform[2];

		private static Material dotMaterial;

		private static Material glowMaterial;

		public static void Initialize(Page root)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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)
			Page obj = root.CreatePage("Easy grab", new Color(0.5f, 1f, 0.9f), 0, true);
			obj.CreateBool("Take the lit handle (smart grab)", Color.white, Enabled, (Action<bool>)delegate(bool v)
			{
				Enabled = v;
			});
			obj.CreateBool("Light up what the hand will take", Color.white, ShowTarget, (Action<bool>)delegate(bool v)
			{
				ShowTarget = v;
			});
			obj.CreateFloat("Reach (cm)", Color.white, Reach * 100f, 1f, 4f, 30f, (Action<float>)delegate(float v)
			{
				Reach = v / 100f;
			});
		}

		public static void Register(Grip grip, CapsuleCollider zone, Transform holder, Rigidbody body, float radius, float half)
		{
			handles.Add(new Entry
			{
				grip = grip,
				zone = zone,
				zoneRadius = (((Object)(object)zone != (Object)null) ? zone.radius : 0f),
				zoneHeight = (((Object)(object)zone != (Object)null) ? zone.height : 0f),
				holder = holder,
				body = body,
				radius = radius,
				half = half
			});
		}

		public static void ForgetLevel()
		{
			handles.Clear();
			for (int i = 0; i < 2; i++)
			{
				target[i] = null;
				aimed[i] = null;
				takeAt[i] = -1f;
				dots[i] = null;
			}
			dotMaterial = null;
			glowMaterial = null;
		}

		public static void Update()
		{
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			for (int num = handles.Count - 1; num >= 0; num--)
			{
				Entry entry = handles[num];
				if ((Object)(object)entry.grip == (Object)null || (Object)(object)entry.holder == (Object)null || (Object)(object)entry.body == (Object)null)
				{
					handles.RemoveAt(num);
				}
			}
			for (int i = 0; i < 2; i++)
			{
				try
				{
					Choose(i, (i == 0) ? Player.LeftHand : Player.RightHand);
				}
				catch (Exception ex)
				{
					MelonLogger.Warning("Easy grab: " + ex.Message);
					target[i] = null;
					free[i] = false;
				}
			}
			Rigidbody val = ((ShowTarget && Enabled && target[0] != null) ? target[0].body : null);
			Rigidbody val2 = ((ShowTarget && Enabled && target[1] != null) ? target[1].body : null);
			foreach (Entry handle in handles)
			{
				try
				{
					Zone(handle);
					Light(handle, (Object)(object)handle.body == (Object)(object)val || (Object)(object)handle.body == (Object)(object)val2);
				}
				catch (Exception ex2)
				{
					MelonLogger.Warning("Easy grab: " + ex2.Message);
				}
			}
			for (int j = 0; j < 2; j++)
			{
				Dot(j, (ShowTarget && Enabled) ? target[j] : null, spots[j]);
				try
				{
					Catch(j, (j == 0) ? Player.LeftHand : Player.RightHand);
				}
				catch (Exception ex3)
				{
					MelonLogger.Warning("Easy grab: " + ex3.Message);
					takeAt[j] = -1f;
				}
			}
		}

		private static void Choose(int h, Hand hand)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: 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_0100: 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)
			free[h] = false;
			if ((Object)(object)hand == (Object)null || (Object)(object)hand.palmPositionTransform == (Object)null || !Enabled)
			{
				target[h] = null;
				return;
			}
			palms[h] = hand.palmPositionTransform.position;
			bool flag = hand.HasAttachedObject() || (Object)(object)Player.GetObjectInHand(hand) != (Object)null;
			free[h] = !flag;
			if (flag || !Ours(hand.HoveringReceiver))
			{
				free[h] = false;
				target[h] = null;
				return;
			}
			Entry entry = null;
			float num = Reach;
			Vector3 val = Vector3.zero;
			foreach (Entry handle in handles)
			{
				if (((Component)handle.holder).gameObject.activeInHierarchy && !Held(handle))
				{
					Vector3 spot;
					float num2 = Apart(handle, palms[h], out spot);
					if (handle == target[h])
					{
						num2 -= 0.025f;
					}
					if (!(num2 >= num))
					{
						num = num2;
						entry = handle;
						val = spot;
					}
				}
			}
			target[h] = entry;
			spots[h] = val;
		}

		private static bool Held(Entry entry)
		{
			if (entry.grip.attachedHands != null)
			{
				return entry.grip.attachedHands.Count > 0;
			}
			return false;
		}

		private static bool Ours(HandReciever reaching)
		{
			if ((Object)(object)reaching == (Object)null)
			{
				return true;
			}
			if (((Object)((Component)reaching).gameObject).name.StartsWith("ThirdEye", StringComparison.Ordinal))
			{
				return true;
			}
			Rigidbody componentInParent = ((Component)reaching).GetComponentInParent<Rigidbody>();
			if ((Object)(object)componentInParent == (Object)null)
			{
				return false;
			}
			foreach (Entry handle in handles)
			{
				if ((Object)(object)handle.body == (Object)(object)componentInParent)
				{
					return true;
				}
			}
			return false;
		}

		private static float Apart(Entry entry, Vector3 palm, out Vector3 spot)
		{
			//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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_0047: 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_004d: 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_0064: 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_005e: 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)
			Vector3 position = entry.holder.position;
			Vector3 up = entry.holder.up;
			float num = Mathf.Clamp(Vector3.Dot(palm - position, up), 0f - entry.half, entry.half);
			Vector3 val = position + up * num;
			Vector3 val2 = palm - val;
			spot = ((((Vector3)(ref val2)).sqrMagnitude > 1E-08f) ? (val + ((Vector3)(ref val2)).normalized * entry.radius) : val);
			return Mathf.Max(0f, ((Vector3)(ref val2)).magnitude - entry.radius);
		}

		private static void Zone(Entry entry)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)entry.zone == (Object)null)
			{
				return;
			}
			int num = 0;
			float num2 = entry.zoneRadius;
			if (Enabled && !Held(entry))
			{
				for (int i = 0; i < 2; i++)
				{
					if (free[i])
					{
						Vector3 spot;
						float num3 = Apart(entry, palms[i], out spot);
						if (entry == target[i])
						{
							num = 1;
							num2 = Mathf.Max(num2, Mathf.Min(num3 + entry.radius + 0.012f, Reach + entry.radius + 0.02f));
						}
						else if (num == 0 && num3 < Reach + 0.08f)
						{
							num = 2;
						}
					}
				}
			}
			switch (num)
			{
			case 1:
				Set(entry.zone, num2, entry.half * 2f + num2 * 2f);
				break;
			case 2:
				Set(entry.zone, 0.002f, entry.half * 2f + 0.004f);
				break;
			default:
				if (entry.state != 0)
				{
					Set(entry.zone, entry.zoneRadius, entry.zoneHeight);
				}
				break;
			}
			entry.state = num;
		}

		private static void Set(CapsuleCollider zone, float radius, float height)
		{
			if (Mathf.Abs(zone.radius - radius) > 0.0005f)
			{
				zone.radius = radius;
			}
			if (Mathf.Abs(zone.height - height) > 0.0005f)
			{
				zone.height = height;
			}
		}

		private static void Catch(int h, Hand hand)
		{
			if ((Object)(object)hand == (Object)null || !Enabled)
			{
				takeAt[h] = -1f;
				return;
			}
			bool flag = (((Object)(object)hand.Controller != (Object)null) ? hand.Controller.GetGripForce() : 0f) > (down[h] ? 0.35f : 0.6f);
			bool flag2 = flag && !down[h];
			down[h] = flag;
			if (!flag)
			{
				takeAt[h] = -1f;
				tries[h] = 0;
				return;
			}
			if (flag2 && target[h] != null)
			{
				aimed[h] = target[h];
				tries[h] = 0;
				takeAt[h] = Time.time + 0.12f;
			}
			if (takeAt[h] < 0f || Time.time < takeAt[h])
			{
				return;
			}
			Entry entry = aimed[h];
			if (entry == null || (Object)(object)entry.grip == (Object)null || hand.HasAttachedObject() || (Object)(object)Player.GetObjectInHand(hand) != (Object)null || Held(entry))
			{
				takeAt[h] = -1f;
				aimed[h] = null;
				tries[h] = 0;
				return;
			}
			takeAt[h] = Time.time + 0.25f;
			Take(hand, entry, tries[h]++);
			if (tries[h] > 1)
			{
				takeAt[h] = -1f;
				aimed[h] = null;
				tries[h] = 0;
			}
		}

		private static void Take(Hand hand, Entry entry, int attempt)
		{
			try
			{
				if (attempt == 0)
				{
					((HandReciever)entry.grip).OnHandHoverBegin(hand);
					((HandReciever)entry.grip).OnHandHoverUpdate(hand);
					hand.AttachObject(((Component)entry.grip).gameObject);
				}
				else
				{
					entry.grip.Snatch(hand, false);
					MelonLogger.Msg("Easy grab: the hand was handed the lit handle");
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("Easy grab: try " + (attempt + 1) + " did not take: " + ex.Message);
			}
		}

		private static void Light(Entry entry, bool on)
		{
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			if (!on && !entry.lit)
			{
				return;
			}
			if (entry.look == null)
			{
				entry.look = new List<Renderer>();
				foreach (MeshRenderer componentsInChild in ((Component)entry.body).GetComponentsInChildren<MeshRenderer>(true))
				{
					if ((Object)(object)componentsInChild != (Object)null && ((Object)((Component)componentsInChild).gameObject).name.StartsWith("ThirdEyeModel", StringComparison.Ordinal))
					{
						entry.look.Add((Renderer)(object)componentsInChild);
					}
				}
			}
			Material val = Glow();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			if (on)
			{
				val.SetColor(GlowColour(val), new Color(0.6f, 0.95f, 1f, 0.16f + 0.08f * Mathf.Sin(Time.time * 6f)));
			}
			foreach (Renderer item in entry.look)
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				Il2CppReferenceArray<Material> sharedMaterials = item.sharedMaterials;
				List<Material> list = new List<Material>();
				bool flag = false;
				for (int i = 0; i < ((Il2CppArrayBase<Material>)(object)sharedMaterials).Length; i++)
				{
					if ((Object)(object)((Il2CppArrayBase<Material>)(object)sharedMaterials)[i] == (Object)(object)val)
					{
						flag = true;
					}
					else
					{
						list.Add(((Il2CppArrayBase<Material>)(object)sharedMaterials)[i]);
					}
				}
				if (on != flag)
				{
					if (on)
					{
						list.Add(val);
					}
					Il2CppReferenceArray<Material> val2 = new Il2CppReferenceArray<Material>((long)list.Count);
					for (int j = 0; j < list.Count; j++)
					{
						((Il2CppArrayBase<Material>)(object)val2)[j] = list[j];
					}
					item.sharedMaterials = val2;
				}
			}
			entry.lit = on;
		}

		private static Material Glow()
		{
			if ((Object)(object)glowMaterial == (Object)null)
			{
				glowMaterial = PropsManager.Unlit((Texture)(object)Texture2D.whiteTexture, 3050);
				if ((Object)(object)glowMaterial != (Object)null)
				{
					((Object)glowMaterial).name = "ThirdEyeGrabGlow";
				}
			}
			return glowMaterial;
		}

		private static string GlowColour(Material material)
		{
			string[] array = new string[3] { "_TintColor", "_Color", "_BaseColor" };
			foreach (string text in array)
			{
				if (material.HasProperty(text))
				{
					return text;
				}
			}
			return "_Color";
		}

		private static void Dot(int h, Entry entry, Vector3 at)
		{
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			Transform val = dots[h];
			if (entry == null)
			{
				if ((Object)(object)val != (Object)null && ((Component)val).gameObject.activeSelf)
				{
					((Component)val).gameObject.SetActive(false);
				}
				return;
			}
			if ((Object)(object)val == (Object)null)
			{
				if ((Object)(object)dotMaterial == (Object)null)
				{
					dotMaterial = PropsManager.Unlit((Texture)(object)Texture2D.whiteTexture, 3100);
					string[] array = new string[3] { "_TintColor", "_Color", "_BaseColor" };
					foreach (string text in array)
					{
						if ((Object)(object)dotMaterial != (Object)null && dotMaterial.HasProperty(text))
						{
							dotMaterial.SetColor(text, new Color(0.55f, 1f, 0.95f, 0.55f));
						}
					}
				}
				GameObject val2 = PropShell.MakeVisual((PrimitiveType)0, "ThirdEyeGrabDot", dotMaterial, 0);
				val = (dots[h] = val2.transform);
			}
			if (!((Component)val).gameObject.activeSelf)
			{
				((Component)val).gameObject.SetActive(true);
			}
			val.position = at;
			val.localScale = Vector3.one * (0.009f + Mathf.Sin(Time.time * 6f) * 0.001f);
		}
	}
	public static class SpawnGuard
	{
		public static void Apply(Harmony harmony)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			int num = 0;
			string[] array = new string[2] { "OnSpawnEvent", "OnSpawn" };
			foreach (string text in array)
			{
				try
				{
					MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(Poolee), text, Type.EmptyTypes, (Type[])null);
					if (!(methodInfo == null))
					{
						harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(SpawnGuard), "Spawned", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						num++;
					}
				}
				catch (Exception ex)
				{
					MelonLogger.Warning("Spawn guard: Poolee." + text + " could not be patched: " + ex.Message);
				}
			}
			if (num > 0)
			{
				MelonLogger.Msg("Spawn guard: the mod's spawnables are hidden as they appear");
			}
			else
			{
				MelonLogger.Warning("Spawn guard: not in place; a baseball may show for a moment when one of the mod's things is spawned");
			}
		}

		private static void Spawned(Poolee __instance)
		{
			try
			{
				if ((Object)(object)__instance == (Object)null)
				{
					return;
				}
				SpawnableCrate spawnableCrate = __instance.SpawnableCrate;
				if ((Object)(object)spawnableCrate == (Object)null || ((Scannable)spawnableCrate).Barcode == (Barcode)null || !MotorCrate.IsOurs(((Scannable)spawnableCrate).Barcode.ID))
				{
					return;
				}
				foreach (Renderer componentsInChild in ((Component)__instance).GetComponentsInChildren<Renderer>(true))
				{
					if ((Object)(object)componentsInChild != (Object)null && !Ours(((Component)componentsInChild).transform, ((Component)__instance).transform))
					{
						componentsInChild.forceRenderingOff = true;
					}
				}
				foreach (Rigidbody componentsInChild2 in ((Component)__instance).GetComponentsInChildren<Rigidbody>(true))
				{
					if ((Object)(object)componentsInChild2 != (Object)null && !Built(componentsInChild2))
					{
						MotorManager.Forget(componentsInChild2);
					}
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("Spawn guard: " + ex.Message);
			}
		}

		private static bool Ours(Transform at, Transform root)
		{
			Transform val = at;
			while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)root)
			{
				if (((Object)val).name.StartsWith("ThirdEye", StringComparison.Ordinal))
				{
					return true;
				}
				val = val.parent;
			}
			return false;
		}

		private static bool Built(Rigidbody body)
		{
			Transform transform = ((Component)body).transform;
			for (int i = 0; i < transform.childCount; i++)
			{
				Transform child = transform.GetChild(i);
				if ((Object)(object)child != (Object)null && ((Object)child).name.StartsWith("ThirdEye", StringComparison.Ordinal))
				{
					return true;
				}
			}
			return false;
		}
	}
	public static class AssetFiles
	{
		public static string Root = "ThirdEyeMotor";

		public static string Folder(string name)
		{
			return Path.Combine(MelonEnvironment.UserDataDirectory, Root, name);
		}

		public static Mesh ReadMesh(string path, string name)
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_008f: 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_00c7: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Expected O, but got Unknown
			if (!File.Exists(path))
			{
				return null;
			}
			using BinaryReader binaryReader = new BinaryReader(File.OpenRead(path));
			int num = binaryReader.ReadInt32();
			int num2 = binaryReader.ReadInt32();
			Vector3[] array = (Vector3[])(object)new Vector3[num];
			Vector3[] array2 = (Vector3[])(object)new Vector3[num];
			Vector2[] array3 = (Vector2[])(object)new Vector2[num];
			for (int i = 0; i < num; i++)
			{
				array[i] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				array2[i] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				array3[i] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
			}
			int[] array4 = new int[num2];
			for (int j = 0; j < num2; j++)
			{
				array4[j] = binaryReader.ReadInt32();
			}
			Mesh val = new Mesh
			{
				name = name,
				hideFlags = (HideFlags)32,
				vertices = Il2CppStructArray<Vector3>.op_Implicit(array),
				normals = Il2CppStructArray<Vector3>.op_Implicit(array2),
				uv = Il2CppStructArray<Vector2>.op_Implicit(array3),
				triangles = Il2CppStructArray<int>.op_Implicit(array4)
			};
			val.RecalculateBounds();
			return val;
		}

		public static Texture2D ReadTexture(string path, bool data = false)
		{
			//IL_001b: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_003b: Expected O, but got Unknown
			if (!File.Exists(path))
			{
				return null;
			}
			Texture2D val = (data ? new Texture2D(2, 2, (TextureFormat)4, true, true) : new Texture2D(2, 2));
			((Object)val).hideFlags = (HideFlags)32;
			ImageConversion.LoadImage(val, Il2CppStructArray<byte>.op_Implicit(File.ReadAllBytes(path)));
			return val;
		}

		public static AudioClip ReadWav(string path, string name)
		{
			if (!File.Exists(path))
			{
				return null;
			}
			byte[] array = File.ReadAllBytes(path);
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = -1;
			int num5 = 0;
			int num6;
			for (int i = 12; i + 8 <= array.Length; i += 8 + num6 + (num6 & 1))
			{
				string text = Encoding.ASCII.GetString(array, i, 4);
				num6 = BitConverter.ToInt32(array, i + 4);
				if (text == "fmt ")
				{
					num = BitConverter.ToInt16(array, i + 10);
					num2 = BitConverter.ToInt32(array, i + 12);
					num3 = BitConverter.ToInt16(array, i + 22);
				}
				else if (text == "data")
				{
					num4 = i + 8;
					num5 = Math.Min(num6, array.Length - num4);
					break;
				}
			}
			if (num4 < 0 || num <= 0 || num3 != 16)
			{
				return null;
			}
			int num7 = num5 / 2;
			float[] array2 = new float[num7];
			for (int j = 0; j < num7; j++)
			{
				array2[j] = (float)BitConverter.ToInt16(array, num4 + j * 2) / 32768f;
			}
			AudioClip obj = AudioClip.Create(name, num7 / num, num, num2, false);
			obj.SetData(Il2CppStructArray<float>.op_Implicit(array2), 0);
			((Object)obj).hideFlags = (HideFlags)32;
			return obj;
		}
	}
	public class Grips
	{
		private class Surface
		{
			public Collider solid;

			public Collider reach;

			public GameObject holder;

			public GenericGrip grip;

			public Transform dot;

			public InteractableIcon icon;

			public Grips owner;
		}

		private class Skin
		{
			public Vector3[] points;

			public int[] corners;

			public Bounds bounds;
		}

		private class Model
		{
			public Transform at;

			public Skin skin;
		}

		private class Pass
		{
			public IntPtr held;

			public Grips item;

			public float endAt = -1f;

			public readonly List<Collider> hand = new List<Collider>();

			public readonly List<Collider> solids = new List<Collider>();
		}

		public static bool Enabled = true;

		public static bool ShowDot = true;

		private const int GripLayer = 15;

		private static readonly Dictionary<IntPtr, Skin> skins = new Dictionary<IntPtr, Skin>();

		private static readonly Dictionary<IntPtr, Surface> byGrip = new Dictionary<IntPtr, Surface>();

		private static bool patched;

		private const float Clearance = 0.004f;

		private const float ModelDepth = 0.06f;

		private static readonly Dictionary<IntPtr, Grips> byBody = new Dictionary<IntPtr, Grips>();

		private static readonly Pass[] passes = new Pass[2]
		{
			new Pass(),
			new Pass()
		};

		private const float PassLingers = 0.25f;

		private const float Touch = 0.045f;

		private static readonly List<HandReciever>[] barred = new List<HandReciever>[2]
		{
			new List<HandReciever>(),
			new List<HandReciever>()
		};

		private static readonly Grips[] barredFor = new Grips[2];

		private static readonly List<Grips> dotless = new List<Grips>();

		private readonly List<Rigidbody> joined = new List<Rigidbody>();

		private readonly List<Model> models = new List<Model>();

		private float modelsReadAt = -100f;

		private static readonly Dictionary<IntPtr, Surface> byHolder = new Dictionary<IntPtr, Surface>();

		private static HandPose surfacePose;

		private static bool failed;

		private readonly Rigidbody body;

		private readonly Transform parts;

		private readonly InteractableHost host;

		private readonly Grip template;

		private readonly List<Surface> surfaces = new List<Surface>();

		public static void Initialize(Page root)
		{
			//IL_0006: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			Page obj = root.CreatePage("Grips", Color.white, 0, true);
			obj.CreateBool("Grab items anywhere", Color.white, Enabled, (Action<bool>)delegate(bool v)
			{
				Enabled = v;
			});
			obj.CreateBool("Show the grab dot", Color.white, ShowDot, (Action<bool>)delegate(bool v)
			{
				ShowDot = v;
			});
		}

		public static void Apply(Harmony harmony)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			try
			{
				harmony.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(GenericGrip), "OnHandHoverUpdate", new Type[1] { typeof(Hand) }, (Type[])null), new HarmonyMethod(typeof(Grips), "HoverPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				patched = true;
				MelonLogger.Msg("Grips: hand placement on the surface is in.");
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("Grips: hand placement on the surface unavailable. " + ex.Message);
			}
		}

		private static void HoverPrefix(GenericGrip __instance, Hand hand)
		{
			//IL_006c: 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_009b: 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)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (byGrip.Count != 0 && !((Object)(object)__instance == (Object)null) && !((Object)(object)hand == (Object)null) && byGrip.TryGetValue(((Il2CppObjectBase)__instance).Pointer, out var value) && value.owner != null && value.owner.Rest(hand, out var point, out var normal))
				{
					if ((Object)(object)value.dot != (Object)null)
					{
						value.dot.position = point;
					}
					HandToGenericGripState val = default(HandToGenericGripState);
					if (__instance.genericHandStates != null && __instance.genericHandStates.TryGetValue(hand, ref val) && val != null)
					{
						Transform transform = ((Component)__instance).transform;
						val.raycastPoint = transform.InverseTransformPoint(point + normal * 0.004f);
						val.raycastNormal = transform.InverseTransformDirection(normal);
						val.isRaycastHit = true;
					}
				}
			}
			catch
			{
			}
		}

		private bool Rest(Hand hand, out Vector3 point, out Vector3 normal)
		{
			//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)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_002e: 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_0036: 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_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)
			//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_0073: 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_008b: 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)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: 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_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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: 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_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: 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)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: 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_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: 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_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			point = Vector3.zero;
			normal = Vector3.up;
			Transform palmPositionTransform = hand.palmPositionTransform;
			if ((Object)(object)palmPositionTransform == (Object)null)
			{
				return false;
			}
			Vector3 position = palmPositionTransform.position;
			float num = float.PositiveInfinity;
			Vector3 val = position;
			Collider val2 = null;
			Vector3 val4;
			foreach (Surface surface in surfaces)
			{
				if (!((Object)(object)surface.reach == (Object)null))
				{
					Vector3 val3 = surface.reach.ClosestPoint(position);
					val4 = val3 - position;
					float sqrMagnitude = ((Vector3)(ref val4)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						val = val3;
						val2 = surface.reach;
					}
				}
			}
			if ((Object)(object)val2 == (Object)null)
			{
				return false;
			}
			num = Mathf.Sqrt(num);
			Vector3 val5;
			float num2;
			if (num > 0.01f)
			{
				val5 = (val - position) / num;
				num2 = 0.08f;
			}
			else
			{
				Bounds bounds = val2.bounds;
				val5 = ((Bounds)(ref bounds)).center - position;
				if (((Vector3)(ref val5)).sqrMagnitude < 1E-06f)
				{
					return false;
				}
				((Vector3)(ref val5)).Normalize();
				val4 = ((Bounds)(ref bounds)).extents;
				num2 = ((Vector3)(ref val4)).magnitude + 0.05f;
			}
			Vector3 val6 = position - val5 * num2;
			float num3 = num2 + num + 0.3f;
			Ray val7 = default(Ray);
			((Ray)(ref val7))..ctor(val6, val5);
			float num4 = float.PositiveInfinity;
			Vector3 val8 = -val5;
			RaycastHit val9 = default(RaycastHit);
			foreach (Surface surface2 in surfaces)
			{
				if ((Object)(object)surface2.reach != (Object)null && surface2.reach.Raycast(val7, ref val9, num3) && ((RaycastHit)(ref val9)).distance < num4)
				{
					num4 = ((RaycastHit)(ref val9)).distance;
					val8 = ((RaycastHit)(ref val9)).normal;
				}
			}
			ReadModels();
			float num5 = float.PositiveInfinity;
			Vector3 val10 = -val5;
			foreach (Model model in models)
			{
				if ((Object)(object)model.at != (Object)null && Meet(model, val6, val5, num3, out var met, out var facing) && met < num5)
				{
					num5 = met;
					val10 = facing;
				}
			}
			float num6;
			if (num5 < float.PositiveInfinity && (num4 == float.PositiveInfinity || num5 <= num4 + 0.06f))
			{
				num6 = num5;
				normal = val10;
			}
			else
			{
				if (!(num4 < float.PositiveInfinity))
				{
					return false;
				}
				num6 = num4;
				normal = val8;
			}
			if (Vector3.Dot(normal, val5) > 0f)
			{
				normal = -normal;
			}
			((Vector3)(ref normal)).Normalize();
			point = val6 + val5 * num6;
			return true;
		}

		private void ReadModels()
		{
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time - modelsReadAt < 1f)
			{
				return;
			}
			modelsReadAt = Time.time;
			models.Clear();
			if ((Object)(object)parts == (Object)null)
			{
				return;
			}
			foreach (MeshFilter componentsInChild in ((Component)parts).GetComponentsInChildren<MeshFilter>())
			{
				Mesh val = (((Object)(object)componentsInChild != (Object)null) ? componentsInChild.sharedMesh : null);
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Renderer component = ((Component)componentsInChild).GetComponent<Renderer>();
				if ((Object)(object)component == (Object)null || !component.enabled || (Object)(object)((Component)componentsInChild).GetComponentInParent<Rigidbody>() != (Object)(object)body)
				{
					continue;
				}
				if (!skins.TryGetValue(((Il2CppObjectBase)val).Pointer, out var value))
				{
					value = null;
					try
					{
						if (val.isReadable)
						{
							Vector3[] array = Il2CppArrayBase<Vector3>.op_Implicit((Il2CppArrayBase<Vector3>)(object)val.vertices);
							int[] array2 = Il2CppArrayBase<int>.op_Implicit((Il2CppArrayBase<int>)(object)val.triangles);
							if (array != null && array2 != null && array2.Length > 36)
							{
								value = new Skin
								{
									points = array,
									corners = array2,
									bounds = val.bounds
								};
							}
						}
					}
					catch
					{
					}
					skins[((Il2CppObjectBase)val).Pointer] = value;
				}
				if (value != null)
				{
					models.Add(new Model
					{
						at = ((Component)componentsInChild).transform,
						skin = value
					});
				}
			}
		}

		private static bool Meet(Model model, Vector3 from, Vector3 look, float length, out float met, out Vector3 facing)
		{
			//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)
			//IL_001c: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_0036: 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_0043: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_012e: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: 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)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: 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_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: 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)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			met = 0f;
			facing = Vector3.up;
			Transform at = model.at;
			Vector3 val = at.InverseTransformPoint(from);
			Vector3 val2 = at.InverseTransformPoint(from + look * length) - val;
			Bounds bounds = model.skin.bounds;
			Vector3 min = ((Bounds)(ref bounds)).min;
			Vector3 max = ((Bounds)(ref bounds)).max;
			float num = 0f;
			float num2 = 1f;
			for (int i = 0; i < 3; i++)
			{
				float num3 = ((Vector3)(ref val))[i];
				float num4 = ((Vector3)(ref val2))[i];
				if (Mathf.Abs(num4) < 1E-09f)
				{
					if (num3 < ((Vector3)(ref min))[i] || num3 > ((Vector3)(ref max))[i])
					{
						return false;
					}
					continue;
				}
				float num5 = (((Vector3)(ref min))[i] - num3) / num4;
				float num6 = (((Vector3)(ref max))[i] - num3) / num4;
				if (num5 > num6)
				{
					float num7 = num5;
					num5 = num6;
					num6 = num7;
				}
				num = Mathf.Max(num, num5);
				num2 = Mathf.Min(num2, num6);
				if (num > num2)
				{
					return false;
				}
			}
			Vector3[] points = model.skin.points;
			int[] corners = model.skin.corners;
			float num8 = float.PositiveInfinity;
			Vector3 val3 = Vector3.zero;
			for (int j = 0; j + 2 < corners.Length; j += 3)
			{
				Vector3 val4 = points[corners[j]];
				Vector3 val5 = points[corners[j + 1]] - val4;
				Vector3 val6 = points[corners[j + 2]] - val4;
				Vector3 val7 = Vector3.Cross(val2, val6);
				float num9 = Vector3.Dot(val5, val7);
				if (num9 > -1E-12f && num9 < 1E-12f)
				{
					continue;
				}
				float num10 = 1f / num9;
				Vector3 val8 = val - val4;
				float num11 = Vector3.Dot(val8, val7) * num10;
				if (num11 < 0f || num11 > 1f)
				{
					continue;
				}
				Vector3 val9 = Vector3.Cross(val8, val5);
				float num12 = Vector3.Dot(val2, val9) * num10;
				if (!(num12 < 0f) && !(num11 + num12 > 1f))
				{
					float num13 = Vector3.Dot(val6, val9) * num10;
					if (!(num13 < 0f) && !(num13 > 1f) && !(num13 >= num8))
					{
						num8 = num13;
						val3 = Vector3.Cross(val5, val6);
					}
				}
			}
			if (num8 == float.PositiveInfinity || ((Vector3)(ref val3)).sqrMagnitude < 1E-20f)
			{
				return false;
			}
			met = num8 * length;
			Vector3 val10 = at.TransformDirection(((Vector3)(ref val3)).normalized);
			facing = ((Vector3)(ref val10)).normalized;
			return true;
		}

		public Grips(Rigidbody body, Transform parts)
		{
			this.body = body;
			this.parts = parts;
			host = (((Object)(object)body != (Object)null) ? ((Component)body).GetComponentInParent<InteractableHost>() : null);
			if ((Object)(object)host != (Object)null)
			{
				template = ((Component)host).GetComponentInChildren<Grip>();
			}
			if ((Object)(object)body != (Object)null)
			{
				byBody[((Il2CppObjectBase)body).Pointer] = this;
			}
		}

		public void Join(Rigidbody other)
		{
			if ((Object)(object)other != (Object)null && !joined.Contains(other))
			{
				joined.Add(other);
			}
		}

		public static bool IsSurface(GameObject held)
		{
			if ((Object)(object)held != (Object)null)
			{
				return byHolder.ContainsKey(((Il2CppObjectBase)held).Pointer);
			}
			return false;
		}

		private float Apart(Vector3 point)
		{
			//IL_0030: 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_0036: 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)
			float num = float.PositiveInfinity;
			foreach (Surface surface in surfaces)
			{
				if (!((Object)(object)surface.reach == (Object)null))
				{
					Vector3 val = surface.reach.ClosestPoint(point) - point;
					float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
					}
				}
			}
			return Mathf.Sqrt(num);
		}

		private void Dots(bool shown)
		{
			foreach (Surface surface in surfaces)
			{
				if ((Object)(object)surface.icon != (Object)null && ((Behaviour)surface.icon).enabled != shown)
				{
					((Behaviour)surface.icon).enabled = shown;
				}
			}
			InteractableIcon val = (((Object)(object)template != (Object)null) ? ((Component)template).GetComponent<InteractableIcon>() : null);
			if ((Object)(object)val != (Object)null && ((Behaviour)val).enabled != shown)
			{
				((Behaviour)val).enabled = shown;
			}
		}

		private static bool InHand(Grips item)
		{
			if (passes[0].item != item)
			{
				return passes[1].item == item;
			}
			return true;
		}

		private static void TendDots()
		{
			Pass[] array = passes;
			foreach (Pass pass in array)
			{
				if (pass.item != null && !dotless.Contains(pass.item))
				{
					pass.item.Dots(shown: false);
					dotless.Add(pass.item);
				}
			}
			for (int num = dotless.Count - 1; num >= 0; num--)
			{
				if (!InHand(dotless[num]))
				{
					dotless[num].Dots(shown: true);
					dotless.RemoveAt(num);
				}
			}
		}

		private static void Bar(Hand hand, int index)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			Grips grips = passes[1 - index].item;
			if (grips != null && (passes[index].item == grips || passes[1 - index].endAt > 0f))
			{
				grips = null;
			}
			bool flag = false;
			if (grips != null && (Object)(object)hand != (Object)null && (Object)(object)hand.palmPositionTransform != (Object)null)
			{
				flag = grips.Apart(hand.palmPositionTransform.position) > 0.045f;
			}
			Grips grips2 = (flag ? grips : null);
			if (grips2 == barredFor[index])
			{
				return;
			}
			Unbar(hand, index);
			if (grips2 == null || (Object)(object)hand == (Object)null || hand.ignoredRecievers == null)
			{
				return;
			}
			foreach (Surface surface in grips2.surfaces)
			{
				if (!((Object)(object)surface.grip == (Object)null))
				{
					HandReciever val = ((Il2CppObjectBase)surface.grip).Cast<HandReciever>();
					if (hand.ignoredRecievers.Add(val))
					{
						barred[index].Add(val);
					}
				}
			}
			if ((Object)(object)grips2.template != (Object)null)
			{
				HandReciever val2 = ((Il2CppObjectBase)grips2.template).Cast<HandReciever>();
				if (hand.ignoredRecievers.Add(val2))
				{
					barred[index].Add(val2);
				}
			}
			barredFor[index] = grips2;
		}

		private static void Unbar(Hand hand, int index)
		{
			if ((Object)(object)hand != (Object)null && hand.ignoredRecievers != null)
			{
				foreach (HandReciever item in barred[index])
				{
					if ((Object)(object)item != (Object)null)
					{
						hand.ignoredRecievers.Remove(item);
					}
				}
			}
			barred[index].Clear();
			barredFor[index] = null;
		}

		private List<Collider> Whole()
		{
			List<Rigidbody> list = new List<Rigidbody> { body };
			foreach (Rigidbody item in joined)
			{
				if ((Object)(object)item != (Object)null && !list.Contains(item))
				{
					list.Add(item);
				}
			}
			foreach (Joint component in ((Component)body).GetComponents<Joint>())
			{
				Rigidbody val = (((Object)(object)component != (Object)null) ? component.connectedBody : null);
				if ((Object)(object)val != (Object)null && !list.Contains(val))
				{
					list.Add(val);
				}
			}
			foreach (Grips value in byBody.Values)
			{
				if (value == this || (Object)(object)value.body == (Object)null || list.Contains(value.body))
				{
					continue;
				}
				foreach (Joint component2 in ((Component)value.body).GetComponents<Joint>())
				{
					if ((Object)(object)component2 != (Object)null && (Object)(object)component2.connectedBody == (Object)(object)body)
					{
						list.Add(value.body);
						break;
					}
				}
			}
			List<Collider> list2 = new List<Collider>();
			foreach (Rigidbody item2 in list)
			{
				foreach (Collider componentsInChild in ((Component)item2).GetComponentsInChildren<Collider>())
				{
					if ((Object)(object)componentsInChild != (Object)null && !componentsInChild.isTrigger && (Object)(object)componentsInChild.attachedRigidbody == (Object)(object)item2)
					{
						list2.Add(componentsInChild);
					}
				}
			}
			return list2;
		}

		private static void Track(Hand hand, Pass pass)
		{
			GameObject val = (((Object)(object)hand != (Object)null) ? hand.m_CurrentAttachedGO : null);
			IntPtr intPtr = (((Object)(object)val != (Object)null) ? ((Il2CppObjectBase)val).Pointer : IntPtr.Zero);
			if (intPtr != pass.held)
			{
				pass.held = intPtr;
				Grips value = null;
				if ((Object)(object)val != (Object)null)
				{
					Rigidbody componentInParent = val.GetComponentInParent<Rigidbody>();
					if ((Object)(object)componentInParent != (Object)null)
					{
						byBody.TryGetValue(((Il2CppObjectBase)componentInParent).Pointer, out value);
					}
				}
				if (value != null)
				{
					if (value != pass.item)
					{
						End(pass);
						pass.item = value;
						if ((Object)(object)hand.rb != (Object)null)
						{
							foreach (Collider componentsInChild in ((Component)hand.rb).GetComponentsInChildren<Collider>())
							{
								if ((Object)(object)componentsInChild != (Object)null && !componentsInChild.isTrigger)
								{
									pass.hand.Add(componentsInChild);
								}
							}
						}
						pass.solids.AddRange(value.Whole());
						Set(pass, ignore: true);
					}
					pass.endAt = -1f;
				}
				else if (pass.item != null)
				{
					pass.endAt = Time.time + 0.25f;
				}
			}
			if (pass.endAt > 0f && Time.time >= pass.endAt)
			{
				End(pass);
			}
		}

		private static void Set(Pass pass, bool ignore)
		{
			foreach (Collider item in pass.hand)
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				foreach (Collider solid in pass.solids)
				{
					if ((Object)(object)solid != (Object)null)
					{
						Physics.IgnoreCollision(item, solid, ignore);
					}
				}
			}
		}

		private static void End(Pass pass)
		{
			if (pass.item != null)
			{
				Set(pass, ignore: false);
			}
			pass.item = null;
			pass.endAt = -1f;
			pass.hand.Clear();
			pass.solids.Clear();
		}

		public void Refresh()
		{
			if (!Enabled || failed || (Object)(object)host == (Object)null || (Object)(object)template == (Object)null || (Object)(object)parts == (Object)null)
			{
				return;
			}
			try
			{
				for (int num = surfaces.Count - 1; num >= 0; num--)
				{
					if ((Object)(object)surfaces[num].solid == (Object)null || !surfaces[num].solid.enabled)
					{
						Remove(surfaces[num]);
						surfaces.RemoveAt(num);
					}
				}
				List<Collider> list = new List<Collider>();
				foreach (Collider componentsInChild in ((Component)parts).GetComponentsInChildren<Collider>())
				{
					if (!((Object)(object)componentsInChild == (Object)null) && !componentsInChild.isTrigger && componentsInChild.enabled && !((Object)(object)componentsInChild.attachedRigidbody != (Object)(object)body))
					{
						list.Add(componentsInChild);
					}
				}
				bool flag = false;
				foreach (Collider solid in list)
				{
					if (!surfaces.Exists((Surface s) => (Object)(object)s.solid == (Object)(object)solid))
					{
						Surface surface = Add(solid);
						if (surface != null)
						{
							surfaces.Add(surface);
							flag = true;
						}
					}
				}
				if (!flag && list.Count <= 0)
				{
					return;
				}
				Il2CppReferenceArray<Collider> val = new Il2CppReferenceArray<Collider>((long)list.Count);
				for (int num2 = 0; num2 < list.Count; num2++)
				{
					((Il2CppArrayBase<Collider>)(object)val)[num2] = list[num2];
				}
				foreach (Surface surface2 in surfaces)
				{
					if ((Object)(object)surface2.grip != (Object)null && ((Grip)surface2.grip).attachedHands.Count == 0)
					{
						((Grip)surface2.grip).additionalGripColliders = val;
					}
				}
			}
			catch (Exception ex)
			{
				failed = true;
				MelonLogger.Warning("Grips: could not be added, items keep their centre grip only. " + ex.Message);
			}
		}

		private Surface Add(Collider solid)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_004d: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Expected O, but got Unknown
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)solid).transform;
			Transform val = (((Object)(object)transform.parent != (Object)null) ? transform.parent : transform);
			GameObject val2 = new GameObject("ThirdEyeGrip");
			val2.SetActive(false);
			val2.layer = 15;
			val2.transform.SetParent(val, false);
			val2.transform.localPosition = transform.localPosition;
			val2.transform.localRotation = transform.localRotation;
			val2.transform.localScale = Vector3.one;
			Collider val3 = Reach(val2, solid, ((Object)(object)transform == (Object)(object)val) ? Vector3.one : transform.localScale);
			if ((Object)(object)val3 == (Object)null)
			{
				Object.Destroy((Object)(object)val2);
				return null;
			}
			val3.isTrigger = true;
			GenericGrip val4 = val2.AddComponent<GenericGrip>();
			((Grip)val4).isThrowable = true;
			((Grip)val4).handPose = SurfacePose();
			((Grip)val4).gripOptions = (InteractionOptions)1;
			((Grip)val4).priority = 2f;
			((Grip)val4).minBreakForce = float.PositiveInfinity;
			((Grip)val4).maxBreakForce = float.PositiveInfinity;
			((Grip)val4).defaultGripDistance = float.PositiveInfinity;
			((Grip)val4).radius = 0f;
			Surface surface = new Surface
			{
				solid = solid,
				reach = val3,
				holder = val2,
				grip = val4,
				owner = this
			};
			InteractableIcon component = ((Component)template).GetComponent<InteractableIcon>();
			if (ShowDot && (Object)(object)component != (Object)null)
			{
				GameObject val5 = new GameObject("ThirdEyeGripDot");
				val5.layer = 15;
				val5.transform.SetParent(val2.transform, false);
				surface.dot = val5.transform;
				InteractableIcon val6 = val2.AddComponent<InteractableIcon>();
				val6.targetCenter = val5.transform;
				val6.gripIconType = component.gripIconType;
				val6.LocalOverride = component.LocalOverride;
				val6.IconTex = component.IconTex;
				val6.IconSize = component.IconSize;
				val6.AnimationDuration = component.AnimationDuration;
				surface.icon = val6;
			}
			val2.SetActive(true);
			host.DecorateHostOnChildGrips(val2.transform);
			byHolder[((Il2CppObjectBase)val2).Pointer] = surface;
			byGrip[((Il2CppObjectBase)val4).Pointer] = surface;
			return surface;
		}

		private static Collider Reach(GameObject holder, Collider solid, Vector3 scale)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_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)
			//IL_0058: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			((Vector3)(ref scale))..ctor(Mathf.Abs(scale.x), Mathf.Abs(scale.y), Mathf.Abs(scale.z));
			BoxCollider val = ((Il2CppObjectBase)solid).TryCast<BoxCollider>();
			if ((Object)(object)val != (Object)null)
			{
				BoxCollider obj = holder.AddComponent<BoxCollider>();
				obj.center = Vector3.Scale(val.center, scale);
				obj.size = Vector3.Scale(val.size, scale);
				return (Collider)(object)obj;
			}
			SphereCollider val2 = ((Il2CppObjectBase)solid).TryCast<SphereCollider>();
			if ((Object)(object)val2 != (Object)null)
			{
				SphereCollider obj2 = holder.AddComponent<SphereCollider>();
				obj2.center = Vector3.Scale(val2.center, scale);
				obj2.radius = val2.radius * Mathf.Max(scale.x, Mathf.Max(scale.y, scale.z));
				return (Collider)(object)obj2;
			}
			CapsuleCollider val3 = ((Il2CppObjectBase)solid).TryCast<CapsuleCollider>();
			if ((Object)(object)val3 != (Object)null)
			{
				int direction = val3.direction;
				float num = Mathf.Max(((Vector3)(ref scale))[(direction + 1) % 3], ((Vector3)(ref scale))[(direction + 2) % 3]);
				CapsuleCollider obj3 = holder.AddComponent<CapsuleCollider>();
				obj3.center = Vector3.Scale(val3.center, scale);
				obj3.direction = direction;
				obj3.radius = val3.radius * num;
				obj3.height = val3.height * ((Vector3)(ref scale))[direction];
				return (Collider)(object)obj3;
			}
			MeshCollider val4 = ((Il2CppObjectBase)solid).TryCast<MeshCollider>();
			if ((Object)(object)val4 != (Object)null && (Object)(object)val4.sharedMesh != (Object)null)
			{
				holder.transform.localScale = (((Object)(object)((Component)solid).transform.parent != (Object)null) ? ((Component)solid).transform.localScale : Vector3.one);
				MeshCollider obj4 = holder.AddComponent<MeshCollider>();
				obj4.sharedMesh = val4.sharedMesh;
				obj4.convex = true;
				return (Collider)(object)obj4;
			}
			return null;
		}

		private HandPose SurfacePose()
		{
			if ((Object)(object)surfacePose != (Object)null)
			{
				return surfacePose;
			}
			try
			{
				foreach (GenericGrip item in Resources.FindObjectsOfTypeAll<GenericGrip>())
				{
					if ((Object)(object)item != (Object)null && (Object)(object)((Grip)item).handPose != (Object)null && ((Object)((Component)item).gameObject).name != "ThirdEyeGrip")
					{
						surfacePose = ((Grip)item).handPose;
						MelonLogger.Msg("Grips: surface hand pose taken from " + ((Object)((Component)item).gameObject).name);
						return surfacePose;
					}
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("Grips: no surface hand pose found. " + ex.Message);
			}
			return template.handPose;
		}

		private void Remove(Surface surface)
		{
			if ((Object)(object)surface.holder != (Object)null)
			{
				byHolder.Remove(((Il2CppObjectBase)surface.holder).Pointer);
			}
			if ((Object)(object)surface.grip != (Object)null)
			{
				byGrip.Remove(((Il2CppObjectBase)surface.grip).Pointer);
			}
			surface.owner = null;
			try
			{
				if ((Object)(object)surface.grip != (Object)null)
				{
					if (((Grip)surface.grip).attachedHands != null && ((Grip)surface.grip).attachedHands.Count > 0)
					{
						((Grip)surface.grip).ForceDetach();
					}
					if ((Object)(object)host != (Object)null && host._grips != null)
					{
						host._grips.Remove((Grip)(object)surface.grip);
					}
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("Grips: a grip did not let go cleanly. " + ex.Message);
			}
			if ((Object)(object)surface.holder != (Object)null)
			{
				Object.Destroy((Object)(object)surface.holder);
			}
		}

		public void Clear()
		{
			foreach (Surface surface in surfaces)
			{
				Remove(surface);
			}
			surfaces.Clear();
			if ((Object)(object)body != (Object)null)
			{
				byBody.Remove(((Il2CppObjectBase)body).Pointer);
			}
			Pass[] array = passes;
			foreach (Pass pass in array)
			{
				if (pass.item == this)
				{
					End(pass);
				}
			}
			try
			{
				if (barredFor[0] == this)
				{
					Unbar(Player.LeftHand, 0);
				}
				if (barredFor[1] == this)
				{
					Unbar(Player.RightHand, 1);
				}
				if (dotless.Remove(this))
				{
					Dots(shown: true);
				}
			}
			catch
			{
			}
		}

		public static void Update()
		{
			try
			{
				if (byBody.Count > 0 || passes[0].item != null || passes[1].item != null)
				{
					Track(Player.LeftHand, passes[0]);
					Track(Player.RightHand, passes[1]);
					TendDots();
					Bar(Player.LeftHand, 0);
					Bar(Player.RightHand, 1);
				}
			}
			catch
			{
			}
			if (patched || byHolder.Count == 0)
			{
				return;
			}
			try
			{
				Place(Player.LeftHand);
				Place(Player.RightHand);
			}
			catch
			{
			}
		}

		private static void Place(Hand hand)
		{
			//IL_0072: 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)
			if (!((Object)(object)hand == (Object)null) && !((Object)(object)hand.palmPositionTransform == (Object)null))
			{
				HandReciever hoveringReceiver = hand.HoveringReceiver;
				if (!((Object)(object)hoveringReceiver == (Object)null) && byHolder.TryGetValue(((Il2CppObjectBase)((Component)hoveringReceiver).gameObject).Pointer, out var value) && !((Object)(object)value.dot == (Object)null) && !((Object)(object)value.reach == (Object)null))
				{
					value.dot.position = value.reach.ClosestPoint(hand.palmPositionTransform.position);
				}
			}
		}

		public static void ForgetLevel()
		{
			byHolder.Clear();
			byGrip.Clear();
			byBody.Clear();
			dotless.Clear();
			for (int i = 0; i < 2; i++)
			{
				barred[i].Clear();
				barredFor[i] = null;
			}
			Pass[] array = passes;
			foreach (Pass obj in array)
			{
				obj.item = null;
				obj.held = IntPtr.Zero;
				obj.endAt = -1f;
				obj.hand.Clear();
				obj.solids.Clear();
			}
			surfacePose = null;
			failed = false;
		}
	}
}
namespace ThirdEyeBonelabMod.Tools
{
	public static class JointFirm
	{
		private class Firm
		{
			public ConfigurableJoint joint;

			public Rigidbody body;
		}

		private const float MostBoost = 500f;

		private static readonly List<Firm> joints = new List<Firm>();

		private static readonly Dictionary<int, int> group = new Dictionary<int, int>();

		private static readonly Dictionary<int, float> heaviest = new Dictionary<int, float>();

		private static bool hooked;

		public static void Add(ConfigurableJoint joint, bool project = true)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)joint == (Object)null)
			{
				return;
			}
			if (!hooked)
			{
				hooked = true;
				Hooking.OnLevelUnloaded += delegate
				{
					joints.Clear();
				};
			}
			Rigidbody component = ((Component)joint).GetComponent<Rigidbody>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			if (project)
			{
				if ((int)joint.projectionMode == 0)
				{
					joint.projectionDistance = 0.005f;
					joint.projectionAngle = 1f;
				}
				joint.projectionMode = (JointProjectionMode)1;
				joint.projectionDistance = Mathf.Clamp(joint.projectionDistance, 0.001f, 0.01f);
				joint.projectionAngle = Mathf.Clamp(joint.projectionAngle, 0.5f, 2f);
			}
			Thorough(component);
			Thorough(((Joint)joint).connectedBody);
			joints.Add(new Firm
			{
				joint = joint,
				body = component
			});
			Balance();
		}

		public static float Boost(ConfigurableJoint joint)
		{
			if (!((Object)(object)joint != (Object)null) || !(((Joint)joint).massScale > 0f))
			{
				return 1f;
			}
			return 1f / ((Joint)joint).massScale;
		}

		private static void Thorough(Rigidbody body)
		{
			if (!((Object)(object)body == (Object)null))
			{
				if (body.solverIterations < 30)
				{
					body.solverIterations = 30;
				}
				if (body.solverVelocityIterations < 10)
				{
					body.solverVelocityIterations = 10;
				}
			}
		}

		public static void FixedUpdate()
		{
			for (int num = joints.Count - 1; num >= 0; num--)
			{
				Firm firm = joints[num];
				if ((Object)(object)firm.joint == (Object)null || (O