Decompiled source of Telekinesis v2.1.1

Mods/Telekinesis.dll

Decompiled 6 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BoneLib;
using BoneLib.BoneMenu;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.AI;
using Il2CppSLZ.Marrow.Combat;
using Il2CppSLZ.Marrow.Data;
using Il2CppSLZ.Marrow.Interaction;
using Il2CppSLZ.Marrow.PuppetMasta;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using Telekinesis;
using Telekinesis.Audio;
using Telekinesis.Config;
using Telekinesis.Force;
using Telekinesis.Menu;
using Telekinesis.Net;
using Telekinesis.Render;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(TelekinesisMod), "Telekinesis", "2.1.1", "Yamama", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Telekinesis
{
	public sealed class TelekinesisMod : MelonMod
	{
		private const int MaxAssetAttempts = 12;

		private readonly Caster _left = new Caster(left: true);

		private readonly Caster _right = new Caster(left: false);

		private Caster[] _casters;

		private Action _onUnloaded;

		private bool _wasEnabled = true;

		private int _assetAttempts;

		private float _nextAssetAttemptAt;

		public static TelekinesisMod Instance { get; private set; }

		internal Caster Left => _left;

		internal Caster Right => _right;

		public override void OnInitializeMelon()
		{
			Instance = this;
			_casters = new Caster[2] { _left, _right };
			Step("preferences", Prefs.Load);
			Step("sounds", Sfx.Build);
			Step("fusion", Fusion.Probe);
			Step("level hook", delegate
			{
				_onUnloaded = OnLevelUnloaded;
				Hooking.OnLevelUnloaded += _onUnloaded;
			});
			((MelonBase)this).LoggerInstance.Msg("Telekinesis 2.1.1 ready.");
		}

		private void Step(string what, Action action)
		{
			try
			{
				action();
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Error("Startup step '" + what + "' failed: " + ex);
			}
		}

		public override void OnUpdate()
		{
			try
			{
				MenuPage.EnsureBuilt();
				EnsureAssets();
				if (!Prefs.Enabled)
				{
					if (_wasEnabled)
					{
						_wasEnabled = false;
						Shutdown();
					}
					return;
				}
				_wasEnabled = true;
				float unscaledDeltaTime = Time.unscaledDeltaTime;
				_left.Tick(unscaledDeltaTime);
				_right.Tick(unscaledDeltaTime);
				Blast.Tick();
				if (_left.Holding)
				{
					Haptics.Strain(left: true, _left.Strain);
				}
				if (_right.Holding)
				{
					Haptics.Strain(left: false, _right.Strain);
				}
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Error("Update failed: " + ex);
				try
				{
					Shutdown();
				}
				catch
				{
				}
			}
		}

		public override void OnFixedUpdate()
		{
			try
			{
				if (Prefs.Enabled)
				{
					float fixedDeltaTime = Time.fixedDeltaTime;
					_left.Fixed(fixedDeltaTime);
					_right.Fixed(fixedDeltaTime);
				}
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Error("Physics step failed: " + ex);
			}
		}

		public override void OnLateUpdate()
		{
			try
			{
				Gfx.BeginFrame();
				if (Prefs.Enabled && Assets.Ready)
				{
					Camera main = Camera.main;
					if (!((Object)(object)main == (Object)null))
					{
						Fx.Draw(_casters, main);
					}
				}
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Error("Draw failed: " + ex);
			}
		}

		private void EnsureAssets()
		{
			if (!Assets.Ready && _assetAttempts < 12 && !(Time.unscaledTime < _nextAssetAttemptAt))
			{
				_assetAttempts++;
				_nextAssetAttemptAt = Time.unscaledTime + 1f;
				Assets.Build();
				if (!Assets.Ready && _assetAttempts >= 12)
				{
					((MelonBase)this).LoggerInstance.Error($"Gave up building render assets after {12} attempts. " + "Grabbing and throwing still work; the beam and reticle will not draw.");
				}
			}
		}

		private void Shutdown()
		{
			_left.DropAll(0f);
			_right.DropAll(0f);
			Blast.ReleaseAll();
			Freezer.ThawAll();
			Puppets.ReleaseAll();
			Claims.Clear();
		}

		private void OnLevelUnloaded()
		{
			try
			{
				Forget();
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("Level reset failed: " + ex.Message);
			}
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			try
			{
				Forget();
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("Scene reset failed: " + ex.Message);
			}
		}

		private void Forget()
		{
			_left.Forget();
			_right.Forget();
			Blast.Forget();
			Freezer.Clear();
			Puppets.Clear();
			Claims.Clear();
		}

		public override void OnDeinitializeMelon()
		{
			try
			{
				if (_onUnloaded != null)
				{
					Hooking.OnLevelUnloaded -= _onUnloaded;
				}
			}
			catch
			{
			}
			try
			{
				Shutdown();
			}
			catch
			{
			}
			try
			{
				Sfx.Dispose();
			}
			catch
			{
			}
			try
			{
				Assets.Dispose();
			}
			catch
			{
			}
			try
			{
				Prefs.Save();
			}
			catch
			{
			}
		}
	}
}
namespace Telekinesis.Render
{
	internal static class Assets
	{
		private static readonly string[] Candidates = new string[6] { "GUI/Text Shader", "Sprites/Default", "UI/Default", "Unlit/Transparent", "Particles/Standard Unlit", "Hidden/Internal-Colored" };

		private static Texture2D _white;

		private static Texture2D _glow;

		private static Texture2D _spark;

		public static FxMaterial Beam { get; private set; }

		public static FxMaterial Soft { get; private set; }

		public static FxMaterial Flat { get; private set; }

		public static Mesh BeamMesh { get; private set; }

		public static Mesh OverlayMesh { get; private set; }

		public static bool Ready { get; private set; }

		public static string ShaderName { get; private set; } = "none";

		public static bool ThroughWalls { get; private set; }

		public static void Build()
		{
			if (Ready)
			{
				return;
			}
			try
			{
				Shader val = Resolve();
				if ((Object)(object)val == (Object)null)
				{
					Melon<TelekinesisMod>.Logger.Warning("No usable shader yet; will retry.");
					return;
				}
				ShaderName = ((Object)val).name;
				ThroughWalls = ShaderName == "GUI/Text Shader";
				_white = Solid();
				_glow = Glow();
				_spark = Spark();
				Beam = Make(val, _glow, 4200);
				Soft = Make(val, _spark, 4210);
				Flat = Make(val, _white, 4205);
				BeamMesh = Dynamic("TK_Beam");
				OverlayMesh = Dynamic("TK_Overlay");
				Ready = true;
				Melon<TelekinesisMod>.Logger.Msg($"Render ready on '{ShaderName}' (through walls: {ThroughWalls}).");
			}
			catch (Exception ex)
			{
				Melon<TelekinesisMod>.Logger.Error("Building render assets failed: " + ex);
			}
		}

		private static Shader Resolve()
		{
			for (int i = 0; i < Candidates.Length; i++)
			{
				try
				{
					Shader val = Shader.Find(Candidates[i]);
					if ((Object)(object)val != (Object)null)
					{
						return val;
					}
				}
				catch
				{
				}
			}
			return null;
		}

		private static FxMaterial Make(Shader shader, Texture2D texture, int queue)
		{
			//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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			Material material = new Material(shader)
			{
				hideFlags = (HideFlags)61,
				mainTexture = (Texture)(object)texture,
				color = Color.white,
				renderQueue = queue
			};
			return new FxMaterial
			{
				Material = material,
				Tiling = Vector2.one
			};
		}

		private static Mesh Dynamic(string name)
		{
			//IL_0000: 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)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Mesh val = new Mesh
			{
				name = name,
				hideFlags = (HideFlags)61
			};
			val.MarkDynamic();
			return val;
		}

		private static Texture2D Solid()
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_001b: 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_002c: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false)
			{
				hideFlags = (HideFlags)61,
				wrapMode = (TextureWrapMode)1
			};
			val.SetPixel(0, 0, Color.white);
			val.Apply();
			return val;
		}

		private static Texture2D Glow()
		{
			//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_0013: 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_0022: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				hideFlags = (HideFlags)61,
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)1
			};
			Color[] array = (Color[])(object)new Color[4096];
			float num = 32f;
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num2 = ((float)j + 0.5f - num) / num;
					float num3 = ((float)i + 0.5f - num) / num;
					float num4 = Mathf.Sqrt(num2 * num2 + num3 * num3);
					float num5 = Mathf.Pow(1f - Mathf.Clamp01(num4), 2f);
					array[i * 64 + j] = new Color(1f, 1f, 1f, num5);
				}
			}
			val.SetPixels(Il2CppStructArray<Color>.op_Implicit(array));
			val.Apply();
			return val;
		}

		private static Texture2D Spark()
		{
			//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_0013: 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_0022: Expected O, but got Unknown
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false)
			{
				hideFlags = (HideFlags)61,
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)1
			};
			Color[] array = (Color[])(object)new Color[1024];
			float num = 16f;
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					float num2 = ((float)j + 0.5f - num) / num;
					float num3 = ((float)i + 0.5f - num) / num;
					float num4 = Mathf.Sqrt(num2 * num2 + num3 * num3);
					float num5 = Mathf.Pow(1f - Mathf.Clamp01(num4 * 1.3f), 3f);
					float num6 = (1f - Mathf.Clamp01(Mathf.Abs(num2) * 5f)) * (1f - Mathf.Clamp01(Mathf.Abs(num3) * 1.1f)) + (1f - Mathf.Clamp01(Mathf.Abs(num3) * 5f)) * (1f - Mathf.Clamp01(Mathf.Abs(num2) * 1.1f));
					array[i * 32 + j] = new Color(1f, 1f, 1f, Mathf.Clamp01(Mathf.Max(num5, num6 * 0.55f)));
				}
			}
			val.SetPixels(Il2CppStructArray<Color>.op_Implicit(array));
			val.Apply();
			return val;
		}

		public static void Dispose()
		{
			Destroy(Beam);
			Destroy(Soft);
			Destroy(Flat);
			Beam = null;
			Soft = null;
			Flat = null;
			Kill(ref _white);
			Kill(ref _glow);
			Kill(ref _spark);
			KillMesh(BeamMesh);
			KillMesh(OverlayMesh);
			BeamMesh = null;
			OverlayMesh = null;
			Ready = false;
			ShaderName = "none";
		}

		private static void Destroy(FxMaterial fx)
		{
			try
			{
				if (fx != null && (Object)(object)fx.Material != (Object)null)
				{
					Object.Destroy((Object)(object)fx.Material);
				}
			}
			catch
			{
			}
		}

		private static void Kill(ref Texture2D texture)
		{
			try
			{
				if ((Object)(object)texture != (Object)null)
				{
					Object.Destroy((Object)(object)texture);
				}
			}
			catch
			{
			}
			texture = null;
		}

		private static void KillMesh(Mesh mesh)
		{
			try
			{
				if ((Object)(object)mesh != (Object)null)
				{
					Object.Destroy((Object)(object)mesh);
				}
			}
			catch
			{
			}
		}
	}
	internal static class Fx
	{
		private static readonly MeshBuilder _beam = new MeshBuilder(512);

		private static readonly MeshBuilder _overlay = new MeshBuilder(512);

		public static Color Accent => Color.HSVToRGB(Prefs.Hue, 0.72f, 1f);

		public static Color Denied => new Color(1f, 0.3f, 0.22f);

		public static void Draw(Caster[] casters, Camera camera)
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_0073: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			if (!Assets.Ready || (Object)(object)camera == (Object)null || casters == null)
			{
				return;
			}
			Transform transform;
			try
			{
				transform = ((Component)camera).transform;
			}
			catch
			{
				return;
			}
			Vector3 position = transform.position;
			_beam.Clear();
			_overlay.Clear();
			foreach (Caster caster in casters)
			{
				if (caster != null && !((Object)(object)caster.HandTransform == (Object)null))
				{
					Vector3 position2;
					try
					{
						position2 = caster.HandTransform.position;
					}
					catch
					{
						continue;
					}
					if (Prefs.Beam)
					{
						Beams(caster, position2, position);
					}
					if (!caster.Holding)
					{
						Aiming(caster, position);
					}
				}
			}
			if (_beam.Commit(Assets.BeamMesh))
			{
				Gfx.Mesh(Assets.BeamMesh, Matrix4x4.identity, Assets.Beam, Color.white);
			}
			if (_overlay.Commit(Assets.OverlayMesh))
			{
				Gfx.Mesh(Assets.OverlayMesh, Matrix4x4.identity, Assets.Soft, Color.white);
			}
		}

		private static void Beams(Caster caster, Vector3 hand, Vector3 eye)
		{
			//IL_0007: 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_002d: 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_004d: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			Hold[] holds = caster.Holds;
			Color accent = Accent;
			float time = Time.time;
			foreach (Hold hold in holds)
			{
				if (hold.Alive)
				{
					Vector3 worldCenterOfMass;
					try
					{
						worldCenterOfMass = hold.Body.worldCenterOfMass;
					}
					catch
					{
						continue;
					}
					float num = Mathf.Clamp01(hold.Lag / 2.5f);
					Color color = Color.Lerp(accent, Denied, num * 0.7f);
					Ribbon(hand, worldCenterOfMass, eye, color, time);
				}
			}
		}

		private static void Ribbon(Vector3 from, Vector3 to, Vector3 eye, Color color, float now)
		{
			//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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_002a: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_004f: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: 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_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: 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_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = to - from;
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (!(magnitude < 0.05f))
			{
				Vector3 val2 = val / magnitude;
				Vector3 val3 = eye - from;
				Vector3 val4 = Vector3.Cross(val2, val3);
				Vector3 normalized = ((Vector3)(ref val4)).normalized;
				if (((Vector3)(ref normalized)).sqrMagnitude < 0.0001f)
				{
					val4 = Vector3.Cross(val2, Vector3.up);
					normalized = ((Vector3)(ref val4)).normalized;
				}
				Vector3 val5 = Vector3.Cross(val2, normalized);
				float num = Mathf.Clamp(magnitude * 0.012f, 0.008f, 0.05f);
				Vector3 a = from;
				Color color2 = default(Color);
				for (int i = 1; i <= 14; i++)
				{
					float num2 = (float)i / 14f;
					float num3 = (float)(i - 1) / 14f;
					float num4 = Mathf.Sin(num2 * 9f + now * 7f) * num * 1.6f;
					Vector3 val6 = Vector3.Lerp(from, to, num2) + val5 * num4;
					float num5 = Mathf.Pow(Mathf.Max(0f, Mathf.Sin((num2 - now * 1.1f) * (float)Math.PI * 3f)), 6f);
					float widthA = num * Mathf.Lerp(0.55f, 1.25f, num3);
					float widthB = num * Mathf.Lerp(0.55f, 1.25f, num2);
					float num6 = Mathf.Lerp(0.85f, 0.5f, num2) + num5 * 0.5f;
					((Color)(ref color2))..ctor(Mathf.Min(1f, color.r + num5 * 0.5f), Mathf.Min(1f, color.g + num5 * 0.5f), Mathf.Min(1f, color.b + num5 * 0.5f), Mathf.Clamp01(num6));
					Strip(a, val6, normalized, widthA, widthB, color2);
					a = val6;
				}
			}
		}

		private static void Strip(Vector3 a, Vector3 b, Vector3 side, float widthA, float widthB, Color color)
		{
			//IL_0010: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			int vertexCount = _beam.VertexCount;
			_beam.Vertex(a - side * widthA, color, new Vector2(0f, 0f));
			_beam.Vertex(a + side * widthA, color, new Vector2(1f, 0f));
			_beam.Vertex(b + side * widthB, color, new Vector2(1f, 1f));
			_beam.Vertex(b - side * widthB, color, new Vector2(0f, 1f));
			_beam.Triangle(vertexCount, vertexCount + 1, vertexCount + 2);
			_beam.Triangle(vertexCount, vertexCount + 2, vertexCount + 3);
		}

		private static void Aiming(Caster caster, Vector3 eye)
		{
			//IL_001f: 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_0024: 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_002b: 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_002d: 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_0033: 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_004a: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_006d: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: 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_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: 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_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: 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_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			Aim currentAim = caster.CurrentAim;
			if (!currentAim.Found)
			{
				return;
			}
			Color val = (currentAim.TooHeavy ? Denied : Accent);
			Vector3 point = currentAim.Point;
			Vector3 val2 = eye - point;
			float magnitude = ((Vector3)(ref val2)).magnitude;
			if (magnitude < 0.05f)
			{
				return;
			}
			Vector3 val3 = val2 / magnitude;
			Vector3 val4 = Vector3.Cross(Vector3.up, val3);
			if (((Vector3)(ref val4)).sqrMagnitude < 0.0001f)
			{
				val4 = Vector3.right;
			}
			((Vector3)(ref val4)).Normalize();
			Vector3 val5 = Vector3.Cross(val3, val4);
			float num = Mathf.Clamp(magnitude * 0.035f, 0.02f, 0.5f);
			if (Prefs.Reticle)
			{
				float num2 = Time.time * 40f * ((float)Math.PI / 180f);
				Vector3 val6 = val4 * Mathf.Cos(num2) + val5 * Mathf.Sin(num2);
				Vector3 val7 = Vector3.Cross(val3, val6);
				_overlay.Ring(point, val6, val7, num, num * 0.22f, new Color(val.r, val.g, val.b, 0.85f));
				_overlay.Quad(point, val4, val5, num * 0.18f, num * 0.18f, new Color(val.r, val.g, val.b, 0.95f));
				for (int i = 0; i < 4; i++)
				{
					float num3 = (float)i * (float)Math.PI * 0.5f + num2;
					Vector3 val8 = val6 * Mathf.Cos(num3) + val7 * Mathf.Sin(num3);
					Vector3 side = Vector3.Cross(val3, val8);
					_overlay.Chevron(point + val8 * (num * 1.45f), -val8, side, num * 0.5f, num * 0.24f, new Color(val.r, val.g, val.b, 0.7f));
				}
			}
			if (Prefs.Highlight && (Object)(object)currentAim.Body != (Object)null)
			{
				Box(currentAim.Body, val3, val);
			}
		}

		private static void Box(Rigidbody body, Vector3 viewDirection, Color color)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//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_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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_00e6: 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_00e9: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: 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_0146: 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_014f: 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_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: 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_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//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_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: 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_01de: 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_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			Bounds bounds;
			try
			{
				Collider componentInChildren = ((Component)body).GetComponentInChildren<Collider>();
				if ((Object)(object)componentInChildren == (Object)null)
				{
					return;
				}
				bounds = componentInChildren.bounds;
			}
			catch
			{
				return;
			}
			Vector3 center = ((Bounds)(ref bounds)).center;
			Vector3 extents = ((Bounds)(ref bounds)).extents;
			if (((Vector3)(ref extents)).sqrMagnitude < 0.0001f)
			{
				return;
			}
			float num = Mathf.Clamp(((Vector3)(ref extents)).magnitude * 0.03f, 0.004f, 0.04f);
			Color color2 = default(Color);
			((Color)(ref color2))..ctor(color.r, color.g, color.b, 0.55f);
			for (int i = 0; i < 3; i++)
			{
				for (int j = 0; j < 4; j++)
				{
					Vector3 zero = Vector3.zero;
					int num2 = 0;
					for (int k = 0; k < 3; k++)
					{
						if (k != i)
						{
							float num3 = ((((j >> num2) & 1) == 0) ? (-1f) : 1f);
							((Vector3)(ref zero))[k] = ((Vector3)(ref extents))[k] * num3;
							num2++;
						}
					}
					Vector3 val = center + zero;
					Vector3 val2 = center + zero;
					ref Vector3 reference = ref val;
					int num4 = i;
					((Vector3)(ref reference))[num4] = ((Vector3)(ref reference))[num4] - ((Vector3)(ref extents))[i];
					reference = ref val2;
					num4 = i;
					((Vector3)(ref reference))[num4] = ((Vector3)(ref reference))[num4] + ((Vector3)(ref extents))[i];
					Vector3 val3 = val2 - val;
					Vector3 val4 = Vector3.Cross(((Vector3)(ref val3)).normalized, viewDirection);
					if (!(((Vector3)(ref val4)).sqrMagnitude < 0.0001f))
					{
						((Vector3)(ref val4)).Normalize();
						int vertexCount = _overlay.VertexCount;
						_overlay.Vertex(val - val4 * num, color2, new Vector2(0.5f, 0.5f));
						_overlay.Vertex(val + val4 * num, color2, new Vector2(0.5f, 0.5f));
						_overlay.Vertex(val2 + val4 * num, color2, new Vector2(0.5f, 0.5f));
						_overlay.Vertex(val2 - val4 * num, color2, new Vector2(0.5f, 0.5f));
						_overlay.Triangle(vertexCount, vertexCount + 1, vertexCount + 2);
						_overlay.Triangle(vertexCount, vertexCount + 2, vertexCount + 3);
					}
				}
			}
		}
	}
	internal sealed class FxMaterial
	{
		public Material Material;

		public Vector2 Tiling = Vector2.one;
	}
	internal static class Gfx
	{
		public static readonly int ColorId = Shader.PropertyToID("_Color");

		public static readonly int MainTexStId = Shader.PropertyToID("_MainTex_ST");

		private const int Layer = 0;

		private static MaterialPropertyBlock _block;

		public static int Calls { get; private set; }

		public static void BeginFrame()
		{
			Calls = 0;
		}

		public static void Mesh(Mesh mesh, Matrix4x4 matrix, FxMaterial fx, Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//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)
			Mesh(mesh, matrix, fx, color, Vector2.zero);
		}

		public static void Mesh(Mesh mesh, Matrix4x4 matrix, FxMaterial fx, Color color, Vector2 scroll)
		{
			//IL_001a: 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_0073: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			if (!((Object)(object)mesh == (Object)null) && fx != null && !((Object)(object)fx.Material == (Object)null) && !(color.a <= 0.003f))
			{
				if (_block == null)
				{
					_block = new MaterialPropertyBlock();
				}
				_block.Clear();
				_block.SetColor(ColorId, color);
				_block.SetVector(MainTexStId, new Vector4(fx.Tiling.x, fx.Tiling.y, scroll.x, scroll.y));
				Graphics.DrawMesh(mesh, matrix, fx.Material, 0, (Camera)null, 0, _block);
				Calls++;
			}
		}
	}
	internal sealed class MeshBuilder
	{
		private readonly List<Vector3> _verts;

		private readonly List<Color> _colors;

		private readonly List<Vector2> _uvs;

		private readonly List<int> _indices;

		public int VertexCount => _verts.Count;

		public bool Empty => _verts.Count == 0;

		public MeshBuilder(int capacity)
		{
			_verts = new List<Vector3>(capacity);
			_colors = new List<Color>(capacity);
			_uvs = new List<Vector2>(capacity);
			_indices = new List<int>(capacity * 2);
		}

		public void Clear()
		{
			_verts.Clear();
			_colors.Clear();
			_uvs.Clear();
			_indices.Clear();
		}

		public void Vertex(Vector3 position, Color color, Vector2 uv)
		{
			//IL_0006: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			_verts.Add(position);
			_colors.Add(color);
			_uvs.Add(uv);
		}

		public void Triangle(int a, int b, int c)
		{
			_indices.Add(a);
			_indices.Add(b);
			_indices.Add(c);
		}

		public void Quad(Vector3 center, Vector3 right, Vector3 up, float halfWidth, float halfHeight, Color color)
		{
			//IL_000c: 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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_0021: 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_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_0038: 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_0044: 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_004a: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_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_0080: 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_008c: 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_0093: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			int count = _verts.Count;
			Vector3 val = right * halfWidth;
			Vector3 val2 = up * halfHeight;
			Vertex(center - val - val2, color, new Vector2(0f, 0f));
			Vertex(center + val - val2, color, new Vector2(1f, 0f));
			Vertex(center + val + val2, color, new Vector2(1f, 1f));
			Vertex(center - val + val2, color, new Vector2(0f, 1f));
			Triangle(count, count + 1, count + 2);
			Triangle(count, count + 2, count + 3);
		}

		public void Diamond(Vector3 center, Vector3 right, Vector3 up, float radius, Color edge, Color core)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_0026: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_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_0058: 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_0070: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			int count = _verts.Count;
			Vertex(center, core, new Vector2(0.5f, 0.5f));
			Vertex(center + up * radius, edge, new Vector2(0.5f, 1f));
			Vertex(center + right * radius, edge, new Vector2(1f, 0.5f));
			Vertex(center - up * radius, edge, new Vector2(0.5f, 0f));
			Vertex(center - right * radius, edge, new Vector2(0f, 0.5f));
			Triangle(count, count + 1, count + 2);
			Triangle(count, count + 2, count + 3);
			Triangle(count, count + 3, count + 4);
			Triangle(count, count + 4, count + 1);
		}

		public void Ring(Vector3 center, Vector3 right, Vector3 up, float radius, float thickness, Color color, int segments = 14)
		{
			//IL_0043: 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_004a: 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_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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_0063: 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_0074: 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_0080: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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)
			int count = _verts.Count;
			float num = Mathf.Max(0f, radius - thickness);
			for (int i = 0; i <= segments; i++)
			{
				float num2 = (float)i / (float)segments * (float)Math.PI * 2f;
				float num3 = Mathf.Cos(num2);
				float num4 = Mathf.Sin(num2);
				Vector3 val = right * num3 + up * num4;
				Vertex(center + val * num, color, new Vector2(0.5f, 0.5f));
				Vertex(center + val * radius, color, new Vector2(0.5f, 0.5f));
			}
			for (int j = 0; j < segments; j++)
			{
				int num5 = count + j * 2;
				Triangle(num5, num5 + 1, num5 + 3);
				Triangle(num5, num5 + 3, num5 + 2);
			}
		}

		public void Chevron(Vector3 center, Vector3 direction, Vector3 side, float length, float width, Color color)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_0033: 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_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_004c: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			int count = _verts.Count;
			Vertex(center + direction * length, color, new Vector2(0.5f, 1f));
			Vertex(center - side * width, color, new Vector2(0f, 0f));
			Vertex(center + side * width, color, new Vector2(1f, 0f));
			Triangle(count, count + 1, count + 2);
		}

		public void Arc(Vector3 center, Vector3 right, Vector3 up, float innerRadius, float outerRadius, float startAngle, float sweepAngle, Color color, int segments = 12)
		{
			//IL_002c: 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_0033: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_007c: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			int count = _verts.Count;
			Color val2 = default(Color);
			for (int i = 0; i <= segments; i++)
			{
				float num = startAngle + (float)i / (float)segments * sweepAngle;
				float num2 = Mathf.Cos(num);
				float num3 = Mathf.Sin(num);
				Vector3 val = right * num2 + up * num3;
				float num4 = Mathf.Sin((float)i / (float)segments * (float)Math.PI);
				((Color)(ref val2))..ctor(color.r, color.g, color.b, color.a * num4);
				Vertex(center + val * innerRadius, new Color(val2.r, val2.g, val2.b, 0f), new Vector2(0f, 0.5f));
				Vertex(center + val * outerRadius, val2, new Vector2(1f, 0.5f));
			}
			for (int j = 0; j < segments; j++)
			{
				int num5 = count + j * 2;
				Triangle(num5, num5 + 1, num5 + 3);
				Triangle(num5, num5 + 3, num5 + 2);
			}
		}

		public bool Commit(Mesh mesh)
		{
			if (_verts.Count == 0 || (Object)(object)mesh == (Object)null)
			{
				return false;
			}
			mesh.Clear();
			mesh.vertices = Il2CppStructArray<Vector3>.op_Implicit(_verts.ToArray());
			mesh.colors = Il2CppStructArray<Color>.op_Implicit(_colors.ToArray());
			mesh.uv = Il2CppStructArray<Vector2>.op_Implicit(_uvs.ToArray());
			mesh.triangles = Il2CppStructArray<int>.op_Implicit(_indices.ToArray());
			return true;
		}
	}
}
namespace Telekinesis.Net
{
	internal static class Fusion
	{
		private static bool _probed;

		private static object _cache;

		private static MethodInfo _tryGet;

		private static MethodInfo _takeOwnership;

		private static PropertyInfo _hasServer;

		public static bool Available { get; private set; }

		public static string Status { get; private set; } = "not probed";

		public static int Takeovers { get; private set; }

		public static bool InLobby
		{
			get
			{
				if (!Available || _hasServer == null)
				{
					return false;
				}
				try
				{
					return (bool)_hasServer.GetValue(null);
				}
				catch
				{
					return false;
				}
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static void Probe()
		{
			if (_probed)
			{
				return;
			}
			_probed = true;
			try
			{
				Assembly assembly = null;
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				foreach (Assembly assembly2 in assemblies)
				{
					if (!(assembly2.GetName().Name != "LabFusion"))
					{
						assembly = assembly2;
						break;
					}
				}
				if (assembly == null)
				{
					Status = "LabFusion not installed";
					Melon<TelekinesisMod>.Logger.Msg("Fusion not found; multiplayer features are off.");
					return;
				}
				_cache = (assembly.GetType("LabFusion.Entities.IMarrowEntityExtender")?.GetField("Cache", BindingFlags.Static | BindingFlags.Public))?.GetValue(null);
				if (_cache != null)
				{
					_tryGet = _cache.GetType().GetMethod("TryGet");
				}
				_takeOwnership = assembly.GetType("LabFusion.Entities.NetworkEntityManager")?.GetMethod("TakeOwnership", BindingFlags.Static | BindingFlags.Public);
				_hasServer = assembly.GetType("LabFusion.Network.NetworkInfo")?.GetProperty("HasServer", BindingFlags.Static | BindingFlags.Public);
				Available = _cache != null && _tryGet != null && _takeOwnership != null;
				Status = (Available ? "ready" : $"partial (cache={_cache != null} tryGet={_tryGet != null} takeOwnership={_takeOwnership != null})");
				Melon<TelekinesisMod>.Logger.Msg(Available ? "Fusion found; networked objects and player shoves are available." : ("Fusion found but its API did not match: " + Status));
			}
			catch (Exception ex)
			{
				Status = "probe failed: " + ex.Message;
				Melon<TelekinesisMod>.Logger.Warning("Fusion probe failed: " + ex.Message);
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		public static bool TakeOwnership(GameObject target)
		{
			if ((Object)(object)target == (Object)null || !Available || !InLobby)
			{
				return false;
			}
			try
			{
				MarrowEntity componentInParent = target.GetComponentInParent<MarrowEntity>();
				if ((Object)(object)componentInParent == (Object)null)
				{
					return false;
				}
				object[] array = new object[2] { componentInParent, null };
				if (!(bool)_tryGet.Invoke(_cache, array) || array[1] == null)
				{
					return false;
				}
				_takeOwnership.Invoke(null, new object[1] { array[1] });
				Takeovers++;
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static void Reset()
		{
			Takeovers = 0;
		}
	}
}
namespace Telekinesis.Menu
{
	internal static class MenuPage
	{
		private static bool _built;

		private static Color Accent => Fx.Accent;

		public static void EnsureBuilt()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if (_built)
			{
				return;
			}
			Page root;
			try
			{
				if (Page.Root == null)
				{
					return;
				}
				root = Page.Root.CreatePage("Telekinesis", Accent, 0, true);
			}
			catch (Exception ex)
			{
				Melon<TelekinesisMod>.Logger.Warning("BoneMenu root page failed: " + ex.Message);
				return;
			}
			Section("main", delegate
			{
				Main(root);
			});
			Section("feel", delegate
			{
				Feel(root);
			});
			Section("powers", delegate
			{
				Powers(root);
			});
			Section("multiplayer", delegate
			{
				Multiplayer(root);
			});
			Section("look", delegate
			{
				Look(root);
			});
			Section("diagnostics", delegate
			{
				Diagnostics(root);
			});
			_built = true;
			Melon<TelekinesisMod>.Logger.Msg("BoneMenu ready.");
		}

		private static void Section(string name, Action build)
		{
			try
			{
				build();
			}
			catch (Exception ex)
			{
				Melon<TelekinesisMod>.Logger.Error("BoneMenu section '" + name + "' failed: " + ex);
			}
		}

		private static void Main(Page root)
		{
			//IL_0000: 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)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			Color accent = Accent;
			root.CreateBool("Enabled", accent, Prefs.Enabled, (Action<bool>)delegate(bool value)
			{
				Prefs.Enabled = value;
				Prefs.Save();
			});
			root.CreateFloat("Reach", accent, Prefs.Range, 1f, 1f, 150f, (Action<float>)delegate(float value)
			{
				Prefs.Range = value;
				Prefs.Save();
			});
			root.CreateFloat("Aim Assist", accent, Prefs.AimAssist, 0.05f, 0.02f, 2f, (Action<float>)delegate(float value)
			{
				Prefs.AimAssist = value;
				Prefs.Save();
			});
			root.CreateFloat("Max Mass", accent, Prefs.MaxMass, 25f, 1f, 10000f, (Action<float>)delegate(float value)
			{
				Prefs.MaxMass = value;
				Prefs.Save();
			});
			root.CreateInt("Max Held Per Hand", accent, Prefs.MaxHeld, 1, 1, 12, (Action<int>)delegate(int value)
			{
				Prefs.MaxHeld = value;
				Prefs.Save();
			});
			root.CreateFloat("Push / Pull Speed", accent, Prefs.PullSpeed, 0.5f, 0.5f, 40f, (Action<float>)delegate(float value)
			{
				Prefs.PullSpeed = value;
				Prefs.Save();
			});
		}

		private static void Feel(Page root)
		{
			//IL_0000: 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)
			//IL_000c: 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_005a: 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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			Color accent = Accent;
			Page obj = root.CreatePage("Feel", accent, 0, true);
			obj.CreateFloat("Strength", accent, Prefs.Strength, 250f, 50f, 60000f, (Action<float>)delegate(float value)
			{
				Prefs.Strength = value;
				Prefs.Save();
			});
			obj.CreateFloat("Stiffness", accent, Prefs.Stiffness, 0.5f, 1f, 40f, (Action<float>)delegate(float value)
			{
				Prefs.Stiffness = value;
				Prefs.Save();
			});
			obj.CreateFloat("Max Speed", accent, Prefs.MaxSpeed, 1f, 1f, 120f, (Action<float>)delegate(float value)
			{
				Prefs.MaxSpeed = value;
				Prefs.Save();
			});
			obj.CreateBool("Match Wrist Rotation", accent, Prefs.MatchRotation, (Action<bool>)delegate(bool value)
			{
				Prefs.MatchRotation = value;
				Prefs.Save();
			});
			obj.CreateFloat("Spin Rate", accent, Prefs.Spin, 1f, 0f, 40f, (Action<float>)delegate(float value)
			{
				Prefs.Spin = value;
				Prefs.Save();
			});
			obj.CreateFloat("Throw Boost", accent, Prefs.ThrowBoost, 0.1f, 0.1f, 8f, (Action<float>)delegate(float value)
			{
				Prefs.ThrowBoost = value;
				Prefs.Save();
			});
			obj.CreateFloat("Charge Time", accent, Prefs.ChargeSeconds, 0.1f, 0.1f, 5f, (Action<float>)delegate(float value)
			{
				Prefs.ChargeSeconds = value;
				Prefs.Save();
			});
			obj.CreateFloat("Charged Throw", accent, Prefs.ChargeBoost, 0.2f, 1f, 15f, (Action<float>)delegate(float value)
			{
				Prefs.ChargeBoost = value;
				Prefs.Save();
			});
			obj.CreateFloat("Min Hold Distance", accent, Prefs.MinDistance, 0.1f, 0.2f, 5f, (Action<float>)delegate(float value)
			{
				Prefs.MinDistance = value;
				Prefs.Save();
			});
		}

		private static void Powers(Page root)
		{
			//IL_0000: 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)
			//IL_000c: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			Color accent = Accent;
			Page obj = root.CreatePage("Powers", accent, 0, true);
			obj.CreateBool("Grab NPCs", accent, Prefs.GrabNpcs, (Action<bool>)delegate(bool value)
			{
				Prefs.GrabNpcs = value;
				Prefs.Save();
			});
			obj.CreateBool("NPCs Go Limp", accent, Prefs.LimpNpcs, (Action<bool>)delegate(bool value)
			{
				Prefs.LimpNpcs = value;
				Prefs.Save();
				if (!value)
				{
					Blast.ReleaseAll();
				}
			});
			obj.CreateBool("Force Push", accent, Prefs.Blast, (Action<bool>)delegate(bool value)
			{
				Prefs.Blast = value;
				Prefs.Save();
			});
			obj.CreateFloat("Push Force", accent, Prefs.BlastForce, 1f, 1f, 120f, (Action<float>)delegate(float value)
			{
				Prefs.BlastForce = value;
				Prefs.Save();
			});
			obj.CreateFloat("Push Radius", accent, Prefs.BlastRadius, 0.5f, 1f, 30f, (Action<float>)delegate(float value)
			{
				Prefs.BlastRadius = value;
				Prefs.Save();
			});
			obj.CreateFloat("Push Cooldown", accent, Prefs.BlastCooldown, 0.1f, 0f, 15f, (Action<float>)delegate(float value)
			{
				Prefs.BlastCooldown = value;
				Prefs.Save();
			});
			obj.CreateBool("Freeze In Place", accent, Prefs.Freeze, (Action<bool>)delegate(bool value)
			{
				Prefs.Freeze = value;
				Prefs.Save();
			});
			obj.CreateFunction("Unfreeze Everything", Color.green, (Action)delegate
			{
				int value = Freezer.ThawAll();
				Melon<TelekinesisMod>.Logger.Msg($"Thawed {value} objects.");
			});
		}

		private static void Multiplayer(Page root)
		{
			//IL_0000: 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)
			//IL_000c: 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_004b: 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_00cb: 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)
			Color accent = Accent;
			Page obj = root.CreatePage("Multiplayer", accent, 0, true);
			obj.CreateBool("Shove Players", accent, Prefs.ShovePlayers, (Action<bool>)delegate(bool value)
			{
				Prefs.ShovePlayers = value;
				Prefs.Save();
			});
			obj.CreateFloat("Shove Force", accent, Prefs.ShoveForce, 5f, 1f, 200f, (Action<float>)delegate(float value)
			{
				Prefs.ShoveForce = value;
				Prefs.Save();
			});
			obj.CreateFloat("Shove Damage", accent, Prefs.ShoveDamage, 5f, 0f, 100f, (Action<float>)delegate(float value)
			{
				Prefs.ShoveDamage = value;
				Prefs.Save();
			});
			obj.CreateBool("Claim Networked Objects", accent, Prefs.TakeOwnership, (Action<bool>)delegate(bool value)
			{
				Prefs.TakeOwnership = value;
				Prefs.Save();
			});
			obj.CreateFunction("Fusion Status", accent, (Action)delegate
			{
				Melon<TelekinesisMod>.Logger.Msg($"Fusion: available={Fusion.Available} inLobby={Fusion.InLobby} status='{Fusion.Status}' takeovers={Fusion.Takeovers} shoves={Players.Shoves}");
			});
		}

		private static void Look(Page root)
		{
			//IL_0000: 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)
			//IL_000c: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			Color accent = Accent;
			Page obj = root.CreatePage("Look & Sound", accent, 0, true);
			obj.CreateBool("Beam", accent, Prefs.Beam, (Action<bool>)delegate(bool value)
			{
				Prefs.Beam = value;
				Prefs.Save();
			});
			obj.CreateBool("Aim Reticle", accent, Prefs.Reticle, (Action<bool>)delegate(bool value)
			{
				Prefs.Reticle = value;
				Prefs.Save();
			});
			obj.CreateBool("Target Highlight", accent, Prefs.Highlight, (Action<bool>)delegate(bool value)
			{
				Prefs.Highlight = value;
				Prefs.Save();
			});
			obj.CreateFloat("Hue", accent, Prefs.Hue, 0.02f, 0f, 1f, (Action<float>)delegate(float value)
			{
				Prefs.Hue = value;
				Prefs.Save();
			});
			obj.CreateBool("Sound", accent, Prefs.Sound, (Action<bool>)delegate(bool value)
			{
				Prefs.Sound = value;
				Prefs.Save();
			});
			obj.CreateFloat("Volume", accent, Prefs.Volume, 0.05f, 0f, 1f, (Action<float>)delegate(float value)
			{
				Prefs.Volume = value;
				Prefs.Save();
			});
			obj.CreateBool("Haptics", accent, Prefs.Haptics, (Action<bool>)delegate(bool value)
			{
				Prefs.Haptics = value;
				Prefs.Save();
			});
		}

		private static void Diagnostics(Page root)
		{
			//IL_0000: 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)
			//IL_000c: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			Color accent = Accent;
			Page obj = root.CreatePage("Diagnostics", accent, 0, true);
			obj.CreateFunction("Report State", accent, (Action)Report);
			obj.CreateFunction("Test Sounds", accent, (Action)delegate
			{
				//IL_0019: 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_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				Vector3 at = (((Object)(object)Player.Head != (Object)null) ? Player.Head.position : Vector3.zero);
				Sfx.Grab(at, 5f, npc: false);
				Sfx.Blast(at);
				Sfx.Freeze(at);
			});
			obj.CreateBool("Log Events", accent, Prefs.LogEvents, (Action<bool>)delegate(bool value)
			{
				Prefs.LogEvents = value;
				Prefs.Save();
			});
		}

		private static void Report()
		{
			Instance logger = Melon<TelekinesisMod>.Logger;
			TelekinesisMod instance = TelekinesisMod.Instance;
			logger.Msg("---- Telekinesis ----");
			logger.Msg($"render: ready={Assets.Ready} shader='{Assets.ShaderName}' throughWalls={Assets.ThroughWalls} calls={Gfx.Calls}");
			logger.Msg($"audio: built={Sfx.Built} ready={Sfx.Ready} volume={Prefs.Volume:0.00}");
			if (instance != null)
			{
				Describe(logger, instance.Left);
				Describe(logger, instance.Right);
			}
			else
			{
				logger.Msg("hands: mod instance missing");
			}
			logger.Msg($"push: fired={Blast.Pushes} staggered={Blast.Staggered}");
			logger.Msg($"registries: frozen={Freezer.Count} claimed={Claims.Count} limp={Puppets.Count}");
			logger.Msg($"fusion: available={Fusion.Available} inLobby={Fusion.InLobby} status='{Fusion.Status}' takeovers={Fusion.Takeovers} shoves={Players.Shoves}");
			logger.Msg($"limits: reach={Prefs.Range:0}m maxMass={Prefs.MaxMass:0}kg strength={Prefs.Strength:0}N maxHeld={Prefs.MaxHeld}");
			logger.Msg("---------------------");
		}

		private static void Describe(Instance log, Caster caster)
		{
			if (caster != null)
			{
				Aim currentAim = caster.CurrentAim;
				string value = (currentAim.Found ? ($"{Name(currentAim.Body)} {currentAim.Mass:0.0}kg at {currentAim.Distance:0.0}m" + (currentAim.TooHeavy ? " TOO HEAVY" : string.Empty) + (currentAim.IsNpc ? " [npc]" : string.Empty)) : "nothing");
				log.Msg($"{caster.Name,-5}: hand={(Object)(object)caster.HandTransform != (Object)null} held={caster.HeldCount} strain={caster.Strain:0.00} charge={caster.Charge:0.00}s aim={value}");
			}
		}

		private static string Name(Rigidbody body)
		{
			try
			{
				return ((Object)(object)body == (Object)null) ? "?" : ((Object)((Component)body).gameObject).name;
			}
			catch
			{
				return "?";
			}
		}
	}
}
namespace Telekinesis.Force
{
	internal static class Blast
	{
		private sealed class Stagger
		{
			public PuppetMaster Puppet;

			public float RestoreAt;
		}

		private const float StaggerSeconds = 2.2f;

		private static readonly Dictionary<int, Stagger> _staggered = new Dictionary<int, Stagger>(16);

		private static readonly List<int> _due = new List<int>(16);

		private static readonly HashSet<int> _seen = new HashSet<int>(64);

		private static readonly HashSet<int> _shoved = new HashSet<int>(8);

		public static int Pushes { get; private set; }

		public static int Staggered => _staggered.Count;

		public static void Push(Transform hand)
		{
			//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_0013: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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_010f: 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_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: 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)
			if ((Object)(object)hand == (Object)null)
			{
				return;
			}
			Vector3 position;
			Vector3 forward;
			try
			{
				position = hand.position;
				forward = hand.forward;
			}
			catch
			{
				return;
			}
			if (((Vector3)(ref forward)).sqrMagnitude < 0.0001f)
			{
				return;
			}
			((Vector3)(ref forward)).Normalize();
			float blastRadius = Prefs.BlastRadius;
			float blastForce = Prefs.BlastForce;
			Vector3 val = position + forward * (blastRadius * 0.55f);
			int num = 0;
			_seen.Clear();
			_shoved.Clear();
			try
			{
				Il2CppReferenceArray<Collider> val2 = Physics.OverlapSphere(val, blastRadius, -1, (QueryTriggerInteraction)1);
				if (val2 == null)
				{
					return;
				}
				for (int i = 0; i < ((Il2CppArrayBase<Collider>)(object)val2).Length; i++)
				{
					Collider val3 = ((Il2CppArrayBase<Collider>)(object)val2)[i];
					if ((Object)(object)val3 == (Object)null)
					{
						continue;
					}
					Rigidbody attachedRigidbody = val3.attachedRigidbody;
					if ((Object)(object)attachedRigidbody == (Object)null || attachedRigidbody.isKinematic)
					{
						continue;
					}
					int instanceID;
					try
					{
						instanceID = ((Object)attachedRigidbody).GetInstanceID();
					}
					catch
					{
						continue;
					}
					if (!_seen.Add(instanceID))
					{
						continue;
					}
					Vector3 val4 = attachedRigidbody.position - position;
					float magnitude = ((Vector3)(ref val4)).magnitude;
					if (magnitude < 0.05f)
					{
						val4 = forward;
					}
					Vector3 normalized = ((Vector3)(ref val4)).normalized;
					if (Vector3.Dot(normalized, forward) < 0.35f)
					{
						continue;
					}
					RigManager val5 = Players.Owner(attachedRigidbody);
					if ((Object)(object)val5 != (Object)null)
					{
						if (!Players.IsLocal(val5) && Prefs.ShovePlayers)
						{
							int instanceID2;
							try
							{
								instanceID2 = ((Object)val5).GetInstanceID();
							}
							catch
							{
								continue;
							}
							if (_shoved.Add(instanceID2) && Players.Shove(val5, normalized, position))
							{
								num++;
							}
						}
						continue;
					}
					float num2 = 1f - Mathf.Clamp01(magnitude / Mathf.Max(0.5f, blastRadius));
					num2 *= num2;
					PuppetMaster val6 = Targeting.Puppet(attachedRigidbody);
					if ((Object)(object)val6 != (Object)null)
					{
						Knock(val6);
					}
					Vector3 val7 = normalized + Vector3.up * 0.28f;
					Vector3 val8 = ((Vector3)(ref val7)).normalized * (blastForce * num2);
					try
					{
						attachedRigidbody.AddForce(val8, (ForceMode)2);
					}
					catch
					{
						continue;
					}
					num++;
				}
			}
			catch (Exception ex)
			{
				Melon<TelekinesisMod>.Logger.Warning("Push failed: " + ex.Message);
				return;
			}
			Pushes++;
			Sfx.Blast(position);
			Haptics.Both(0.9f, 0.09f);
			if (Prefs.LogEvents)
			{
				Melon<TelekinesisMod>.Logger.Msg($"Push moved {num} bodies.");
			}
		}

		private static void Knock(PuppetMaster puppet)
		{
			if (!Prefs.LimpNpcs)
			{
				return;
			}
			try
			{
				int instanceID = ((Object)puppet).GetInstanceID();
				if (_staggered.TryGetValue(instanceID, out var value))
				{
					value.RestoreAt = Time.time + 2.2f;
					return;
				}
				Puppets.Claim(puppet);
				_staggered[instanceID] = new Stagger
				{
					Puppet = puppet,
					RestoreAt = Time.time + 2.2f
				};
			}
			catch
			{
			}
		}

		public static void Tick()
		{
			if (_staggered.Count == 0)
			{
				return;
			}
			float time = Time.time;
			_due.Clear();
			foreach (KeyValuePair<int, Stagger> item in _staggered)
			{
				if (time >= item.Value.RestoreAt)
				{
					_due.Add(item.Key);
				}
			}
			for (int i = 0; i < _due.Count; i++)
			{
				Restore(_due[i]);
			}
		}

		private static void Restore(int id)
		{
			if (_staggered.TryGetValue(id, out var value))
			{
				Puppets.Release(value.Puppet);
				_staggered.Remove(id);
			}
		}

		public static void ReleaseAll()
		{
			_due.Clear();
			foreach (KeyValuePair<int, Stagger> item in _staggered)
			{
				_due.Add(item.Key);
			}
			for (int i = 0; i < _due.Count; i++)
			{
				Restore(_due[i]);
			}
			_staggered.Clear();
		}

		public static void Forget()
		{
			_staggered.Clear();
			_due.Clear();
			_seen.Clear();
		}
	}
	internal struct BodyState
	{
		public bool Gravity;

		public bool Kinematic;

		public float Drag;

		public float AngularDrag;

		public CollisionDetectionMode Collision;

		public bool CollisionValid;

		public bool Valid;

		public static BodyState Capture(Rigidbody body)
		{
			//IL_0063: 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)
			BodyState result = default(BodyState);
			if ((Object)(object)body == (Object)null)
			{
				return result;
			}
			try
			{
				result.Gravity = body.useGravity;
				result.Kinematic = body.isKinematic;
				result.Drag = body.drag;
				result.AngularDrag = body.angularDrag;
				result.Valid = true;
			}
			catch
			{
				return default(BodyState);
			}
			try
			{
				result.Collision = body.collisionDetectionMode;
				result.CollisionValid = true;
			}
			catch
			{
				result.CollisionValid = false;
			}
			return result;
		}

		public void Restore(Rigidbody body)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (!Valid || (Object)(object)body == (Object)null)
			{
				return;
			}
			try
			{
				if (CollisionValid)
				{
					try
					{
						body.collisionDetectionMode = Collision;
					}
					catch
					{
					}
				}
				body.useGravity = Gravity;
				body.drag = Drag;
				body.angularDrag = AngularDrag;
				body.isKinematic = Kinematic;
			}
			catch
			{
			}
		}
	}
	internal sealed class Caster
	{
		private const float GrabThreshold = 0.6f;

		private const float ReleaseThreshold = 0.3f;

		private const float DwellSeconds = 0.35f;

		private readonly bool _left;

		private readonly Hold[] _holds = new Hold[12];

		private bool _triggerDown;

		private float _charge;

		private float _nextBlastAt;

		private float _hum;

		private int _dwellId;

		private float _dwellSince;

		public string Name
		{
			get
			{
				if (!_left)
				{
					return "right";
				}
				return "left";
			}
		}

		public Aim CurrentAim { get; private set; }

		public Transform HandTransform { get; private set; }

		public int HeldCount { get; private set; }

		public float Charge => _charge;

		public float Strain { get; private set; }

		public Hold[] Holds => _holds;

		public bool Holding => HeldCount > 0;

		public Caster(bool left)
		{
			_left = left;
			for (int i = 0; i < _holds.Length; i++)
			{
				_holds[i] = new Hold();
			}
		}

		public void Tick(float delta)
		{
			Hand val = Resolve();
			if ((Object)(object)val == (Object)null)
			{
				DropAll(0f);
				HandTransform = null;
				CurrentAim = default(Aim);
				return;
			}
			Transform transform;
			BaseController controller;
			try
			{
				transform = ((Component)val).transform;
				controller = val.Controller;
			}
			catch
			{
				return;
			}
			HandTransform = transform;
			if ((Object)(object)controller == (Object)null)
			{
				return;
			}
			Prune();
			float primaryAxis;
			bool thumbStickDown;
			try
			{
				primaryAxis = controller._primaryAxis;
				thumbStickDown = controller.GetThumbStickDown();
			}
			catch
			{
				return;
			}
			bool triggerDown = _triggerDown;
			if (_triggerDown)
			{
				if (primaryAxis < 0.3f)
				{
					_triggerDown = false;
				}
			}
			else if (primaryAxis >= 0.6f)
			{
				_triggerDown = true;
			}
			bool pressed = _triggerDown && !triggerDown;
			bool released = !_triggerDown && triggerDown;
			bool empty = Empty(val);
			if (Holding)
			{
				Carrying(transform, controller, released, thumbStickDown, empty, delta);
			}
			else
			{
				Idle(transform, pressed, thumbStickDown, empty);
			}
		}

		private void Idle(Transform handTransform, bool pressed, bool thumbDown, bool empty)
		{
			_charge = 0f;
			Strain = 0f;
			_dwellId = 0;
			CurrentAim = (empty ? Targeting.Resolve(handTransform) : default(Aim));
			if (Prefs.Blast && thumbDown && empty && !_triggerDown && Time.time >= _nextBlastAt)
			{
				_nextBlastAt = Time.time + Prefs.BlastCooldown;
				Blast.Push(handTransform);
			}
			else if (pressed && empty)
			{
				TryGrab(handTransform);
			}
		}

		private void Carrying(Transform handTransform, BaseController controller, bool released, bool thumbDown, bool empty, float delta)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_0034: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			if (!empty)
			{
				DropAll(0f);
				return;
			}
			if (released)
			{
				Throw();
				return;
			}
			_charge = Mathf.Min(_charge + delta, Prefs.ChargeSeconds);
			Vector2 val;
			try
			{
				val = controller._thumbstickAxis;
			}
			catch
			{
				val = Vector2.zero;
			}
			if (Mathf.Abs(val.y) > 0.15f)
			{
				float num = val.y * Prefs.PullSpeed * delta;
				for (int i = 0; i < _holds.Length; i++)
				{
					Hold hold = _holds[i];
					if (hold.Alive)
					{
						hold.Distance = Mathf.Clamp(hold.Distance + num, Prefs.MinDistance, Prefs.Range);
					}
				}
			}
			if (Prefs.Freeze && thumbDown)
			{
				FreezeAll();
				return;
			}
			Dwell(handTransform);
			Sfx.Hum(handTransform.position, ref _hum, HeldCount, Strain, delta);
		}

		private void Dwell(Transform handTransform)
		{
			if (HeldCount >= Prefs.MaxHeld)
			{
				CurrentAim = default(Aim);
				_dwellId = 0;
				return;
			}
			CurrentAim = Targeting.Resolve(handTransform);
			if (!CurrentAim.Found || CurrentAim.TooHeavy || (Object)(object)CurrentAim.Body == (Object)null)
			{
				_dwellId = 0;
				return;
			}
			int instanceID;
			try
			{
				instanceID = ((Object)CurrentAim.Body).GetInstanceID();
			}
			catch
			{
				_dwellId = 0;
				return;
			}
			if (instanceID != _dwellId)
			{
				_dwellId = instanceID;
				_dwellSince = Time.unscaledTime;
			}
			else if (!(Time.unscaledTime - _dwellSince < 0.35f))
			{
				_dwellId = 0;
				TryGrab(handTransform);
			}
		}

		public void Fixed(float fixedDelta)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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)
			if ((Object)(object)HandTransform == (Object)null || !Holding)
			{
				return;
			}
			Vector3 position;
			Vector3 forward;
			Quaternion rotation;
			Vector3 right;
			Vector3 up;
			try
			{
				position = HandTransform.position;
				forward = HandTransform.forward;
				rotation = HandTransform.rotation;
				right = HandTransform.right;
				up = HandTransform.up;
			}
			catch
			{
				return;
			}
			int num = 0;
			for (int i = 0; i < _holds.Length; i++)
			{
				if (_holds[i].Alive)
				{
					num++;
				}
			}
			float num2 = 0f;
			int num3 = 0;
			for (int j = 0; j < _holds.Length; j++)
			{
				Hold hold = _holds[j];
				if (hold.Alive)
				{
					Vector3 target = Formation(position, forward, right, up, hold.Distance, num3, num);
					hold.Drive(target, rotation, fixedDelta);
					if (hold.Lag > num2)
					{
						num2 = hold.Lag;
					}
					num3++;
				}
			}
			Strain = num2;
		}

		private static Vector3 Formation(Vector3 origin, Vector3 forward, Vector3 right, Vector3 up, float distance, int slot, int count)
		{
			//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_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = origin + forward * distance;
			if (count <= 1)
			{
				return val;
			}
			float num = Mathf.Clamp(distance * 0.28f, 0.4f, 2.2f);
			float num2 = (float)slot / (float)count * (float)Math.PI * 2f + Time.time * 0.6f;
			return val + (right * Mathf.Cos(num2) + up * Mathf.Sin(num2)) * num;
		}

		private void TryGrab(Transform handTransform)
		{
			//IL_0028: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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_014e: Unknown result type (might be due to invalid IL or missing references)
			Aim currentAim = CurrentAim;
			if (!currentAim.Found || (Object)(object)currentAim.Body == (Object)null)
			{
				return;
			}
			if (currentAim.IsPlayer)
			{
				Vector3 direction = currentAim.Point - handTransform.position;
				if (Players.Shove(currentAim.PlayerRig, direction, handTransform.position))
				{
					Sfx.Blast(currentAim.Point);
					Haptics.Pulse(_left, 0.85f, 0.08f);
				}
				return;
			}
			if (currentAim.TooHeavy)
			{
				Sfx.Deny(handTransform.position);
				Haptics.Pulse(_left, 0.35f, 0.05f);
				if (Prefs.LogEvents)
				{
					Melon<TelekinesisMod>.Logger.Msg($"Too heavy: {currentAim.Mass:0}kg > {Prefs.MaxMass:0}kg");
				}
				return;
			}
			Hold hold = Free();
			if (hold == null)
			{
				return;
			}
			float num = Mathf.Clamp(currentAim.Distance, Prefs.MinDistance, Prefs.Range);
			if (hold.Take(currentAim.Body, handTransform, num, currentAim.Puppet))
			{
				HeldCount++;
				Sfx.Grab(currentAim.Point, currentAim.Mass, currentAim.IsNpc);
				Haptics.Pulse(_left, Mathf.Lerp(0.4f, 0.9f, Mathf.Clamp01(currentAim.Mass / 60f)), 0.06f);
				if (Prefs.LogEvents)
				{
					Melon<TelekinesisMod>.Logger.Msg($"Grabbed {Describe(currentAim.Body)} ({currentAim.Mass:0.0}kg) at {num:0.0}m" + (currentAim.IsNpc ? " [npc]" : string.Empty));
				}
			}
		}

		private void Throw()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			float num = ((Prefs.ChargeSeconds <= 0.001f) ? 1f : Mathf.Clamp01(_charge / Prefs.ChargeSeconds));
			float boost = Mathf.Lerp(Prefs.ThrowBoost, Prefs.ChargeBoost, num);
			Vector3 at = (((Object)(object)HandTransform != (Object)null) ? HandTransform.position : Vector3.zero);
			int heldCount = HeldCount;
			DropAll(boost);
			if (heldCount > 0)
			{
				Sfx.Throw(at, num);
				Haptics.Pulse(_left, Mathf.Lerp(0.45f, 1f, num), 0.08f);
			}
		}

		private void FreezeAll()
		{
			//IL_0051: 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)
			int num = 0;
			for (int i = 0; i < _holds.Length; i++)
			{
				Hold hold = _holds[i];
				if (hold.Alive && hold.Freeze())
				{
					num++;
				}
			}
			if (num != 0)
			{
				Sfx.Freeze(((Object)(object)HandTransform != (Object)null) ? HandTransform.position : Vector3.zero);
				Haptics.Pulse(_left, 0.5f, 0.05f);
				DropAll(0f);
			}
		}

		public void DropAll(float boost)
		{
			for (int i = 0; i < _holds.Length; i++)
			{
				_holds[i].Release(boost);
			}
			HeldCount = 0;
			Strain = 0f;
			_charge = 0f;
			_dwellId = 0;
		}

		public void Forget()
		{
			for (int i = 0; i < _holds.Length; i++)
			{
				_holds[i].Abandon();
			}
			HeldCount = 0;
			Strain = 0f;
			_charge = 0f;
			_dwellId = 0;
			_triggerDown = false;
		}

		private void Prune()
		{
			int num = 0;
			for (int i = 0; i < _holds.Length; i++)
			{
				Hold hold = _holds[i];
				if (hold.Id != 0)
				{
					if (!hold.Alive)
					{
						hold.Abandon();
					}
					else
					{
						num++;
					}
				}
			}
			HeldCount = num;
		}

		private Hold Free()
		{
			int num = Mathf.Min(_holds.Length, Prefs.MaxHeld);
			for (int i = 0; i < num; i++)
			{
				if (!_holds[i].Alive)
				{
					return _holds[i];
				}
			}
			return null;
		}

		private Hand Resolve()
		{
			try
			{
				if (!Player.HandsExist)
				{
					return null;
				}
				return _left ? Player.LeftHand : Player.RightHand;
			}
			catch
			{
				return null;
			}
		}

		private static bool Empty(Hand hand)
		{
			if ((Object)(object)hand == (Object)null)
			{
				return false;
			}
			try
			{
				return !hand.HasAttachedObject();
			}
			catch
			{
				return false;
			}
		}

		private static string Describe(Rigidbody body)
		{
			try
			{
				return ((Object)((Component)body).gameObject).name;
			}
			catch
			{
				return "?";
			}
		}
	}
	internal static class Claims
	{
		private static readonly HashSet<int> _held = new HashSet<int>();

		public static int Count => _held.Count;

		public static bool IsClaimed(int id)
		{
			return _held.Contains(id);
		}

		public static bool Claim(int id)
		{
			return _held.Add(id);
		}

		public static void Release(int id)
		{
			_held.Remove(id);
		}

		public static void Clear()
		{
			_held.Clear();
		}
	}
	internal static class Puppets
	{
		private sealed class Entry
		{
			public PuppetMaster Puppet;

			public float Weight;

			public int Holders;
		}

		private static readonly Dictionary<int, Entry> _limp = new Dictionary<int, Entry>(16);

		private static readonly List<int> _scratch = new List<int>(16);

		public static int Count => _limp.Count;

		public static void Claim(PuppetMaster puppet)
		{
			if ((Object)(object)puppet == (Object)null)
			{
				return;
			}
			try
			{
				int instanceID = ((Object)puppet).GetInstanceID();
				if (_limp.TryGetValue(instanceID, out var value))
				{
					value.Holders++;
					return;
				}
				_limp[instanceID] = new Entry
				{
					Puppet = puppet,
					Weight = puppet.muscleWeight,
					Holders = 1
				};
				puppet.muscleWeight = 0f;
			}
			catch
			{
			}
		}

		public static void Release(PuppetMaster puppet)
		{
			if (!((Object)(object)puppet == (Object)null))
			{
				int instanceID;
				try
				{
					instanceID = ((Object)puppet).GetInstanceID();
				}
				catch
				{
					return;
				}
				Release(instanceID);
			}
		}

		private static void Release(int id)
		{
			if (!_limp.TryGetValue(id, out var value))
			{
				return;
			}
			value.Holders--;
			if (value.Holders > 0)
			{
				return;
			}
			try
			{
				if ((Object)(object)value.Puppet != (Object)null)
				{
					value.Puppet.muscleWeight = value.Weight;
				}
			}
			catch
			{
			}
			_limp.Remove(id);
		}

		public static void ReleaseAll()
		{
			_scratch.Clear();
			foreach (KeyValuePair<int, Entry> item in _limp)
			{
				_scratch.Add(item.Key);
			}
			for (int i = 0; i < _scratch.Count; i++)
			{
				if (_limp.TryGetValue(_scratch[i], out var value))
				{
					value.Holders = 1;
				}
				Release(_scratch[i]);
			}
			_limp.Clear();
		}

		public static void Clear()
		{
			_limp.Clear();
			_scratch.Clear();
		}
	}
	internal static class Freezer
	{
		private sealed class Entry
		{
			public Rigidbody Body;

			public BodyState State;
		}

		private static readonly Dictionary<int, Entry> _frozen = new Dictionary<int, Entry>(32);

		private static readonly List<int> _scratch = new List<int>(32);

		public static int Count
		{
			get
			{
				Prune();
				return _frozen.Count;
			}
		}

		public static bool IsFrozen(int id)
		{
			return _frozen.ContainsKey(id);
		}

		public static void Remember(Rigidbody body, BodyState state)
		{
			if (!((Object)(object)body == (Object)null) && state.Valid)
			{
				int instanceID;
				try
				{
					instanceID = ((Object)body).GetInstanceID();
				}
				catch
				{
					return;
				}
				if (!_frozen.ContainsKey(instanceID))
				{
					_frozen[instanceID] = new Entry
					{
						Body = body,
						State = state
					};
				}
			}
		}

		public static bool TryAdopt(Rigidbody body, out BodyState state)
		{
			state = default(BodyState);
			if ((Object)(object)body == (Object)null)
			{
				return false;
			}
			int instanceID;
			try
			{
				instanceID = ((Object)body).GetInstanceID();
			}
			catch
			{
				return false;
			}
			if (!_frozen.TryGetValue(instanceID, out var value))
			{
				return false;
			}
			state = value.State;
			_frozen.Remove(instanceID);
			return true;
		}

		public static int ThawAll()
		{
			int num = 0;
			_scratch.Clear();
			foreach (KeyValuePair<int, Entry> item in _frozen)
			{
				_scratch.Add(item.Key);
			}
			for (int i = 0; i < _scratch.Count; i++)
			{
				if (_frozen.TryGetValue(_scratch[i], out var value))
				{
					bool flag;
					try
					{
						flag = (Object)(object)value.Body == (Object)null;
					}
					catch
					{
						flag = true;
					}
					if (!flag)
					{
						value.State.Restore(value.Body)