Decompiled source of TrueDesktopMod v1.0.7

TrueDesktopMod.dll

Decompiled 28 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.Json;
using System.Text.RegularExpressions;
using BoneLib;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Data;
using Il2CppSLZ.Marrow.Input;
using Il2CppSLZ.Marrow.Pool;
using Il2CppSLZ.Marrow.Utilities;
using Il2CppSLZ.Marrow.Warehouse;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using TrueDesktopMod;
using Unity.XR.MockHMD;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.XR;
using UnityEngine.XR.Management;

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

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

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TrueDesktopMod
{
	internal static class R
	{
		private const BindingFlags All = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		public static object Get(object o, string name)
		{
			if (o == null)
			{
				return null;
			}
			Type type = o.GetType();
			while (type != null)
			{
				PropertyInfo property = type.GetProperty(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				if (property != null && property.CanRead && property.GetIndexParameters().Length == 0)
				{
					try
					{
						return property.GetValue(o);
					}
					catch
					{
						return null;
					}
				}
				FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				if (field != null)
				{
					try
					{
						return field.GetValue(o);
					}
					catch
					{
						return null;
					}
				}
				type = type.BaseType;
			}
			return null;
		}

		public static bool TryCall(object o, string name, out object result, params object[] args)
		{
			result = null;
			if (o == null)
			{
				return false;
			}
			Type type = o.GetType();
			while (type != null)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					if (!(methodInfo.Name != name) && methodInfo.GetParameters().Length == args.Length)
					{
						try
						{
							result = methodInfo.Invoke(methodInfo.IsStatic ? null : o, args);
							return true;
						}
						catch
						{
						}
					}
				}
				type = type.BaseType;
			}
			return false;
		}

		public static List<string> MemberNames(object o)
		{
			List<string> list = new List<string>();
			Type type = o.GetType();
			while (type != null)
			{
				string text = type.Namespace ?? "";
				if (text.StartsWith("Il2CppSystem") || text == "System" || text == "UnityEngine")
				{
					break;
				}
				PropertyInfo[] properties = type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (PropertyInfo propertyInfo in properties)
				{
					list.Add("P:" + propertyInfo.Name);
				}
				FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (FieldInfo fieldInfo in fields)
				{
					list.Add("F:" + fieldInfo.Name);
				}
				MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					if (!methodInfo.IsSpecialName && !methodInfo.Name.StartsWith("get_") && !methodInfo.Name.StartsWith("set_"))
					{
						list.Add("M:" + methodInfo.Name + "(" + methodInfo.GetParameters().Length + ")");
					}
				}
				type = type.BaseType;
			}
			return list.Distinct().ToList();
		}
	}
	public class Core : MelonMod
	{
		private sealed class CatalogEntry
		{
			public string Title;

			public string Barcode;

			public string Source;

			public string Category;

			public bool IsLevel;
		}

		private float lookSpeed = 6f;

		private float fov = 90f;

		private int menuPage = 0;

		private object boneMenuCurrentPage;

		private int boneMenuOffset;

		private string spawnSearch = "";

		private bool focusSpawnSearch;

		private string menuMessage = "";

		private Vector2 menuScroll;

		private int spawnListOffset;

		private int levelListOffset;

		private string spawnCategory = "All";

		private string spawnSubcategory = "";

		private readonly List<CatalogEntry> spawnCatalog = new List<CatalogEntry>();

		private readonly List<CatalogEntry> levelCatalog = new List<CatalogEntry>();

		private readonly List<CatalogEntry> avatarCatalog = new List<CatalogEntry>();

		private int avatarListOffset;

		private bool catalogScanned;

		private readonly Stack<GameObject> spawnHistory = new Stack<GameObject>();

		private float propYaw;

		private float propPitch;

		private bool gunFireMode = true;

		private bool gunLockActive;

		private bool meleeLockActive;

		private int meleeHandCache = -1;

		private float swingStart = -10f;

		private const float SwingTime = 0.18f;

		private float SwingBoostSpeed = 20f;

		private float walkSpeed = 16f;

		private float sprintSpeed = 25f;

		private float curMoveSpeed = 16f;

		private const float StickSpeed = 16f;

		private float adsBlend;

		private static readonly Vector3 AdsLocal = new Vector3(0f, -0.1f, 0.55f);

		private static readonly Quaternion AdsRot = Quaternion.Euler(327.5f, 0f, 0f);

		private readonly int[] regripFrames = new int[2];

		private readonly float[] nextRegrip = new float[2];

		private float CallbackRange = 8f;

		private const float CallbackRadius = 0.3f;

		private const float CallbackMaxMass = 30f;

		private Type interactableHostType;

		private bool interactableHostLooked;

		private float gunDropUntil;

		private float curFov = 90f;

		private float ZoomFov = 50f;

		private int leftXFrames;

		private bool xPrev;

		private bool noclip;

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

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

		private readonly List<bool> noclipGravity = new List<bool>();

		private float NoclipSpeed = 6f;

		private float NoclipFastSpeed = 18f;

		private Light flashlight;

		private bool flashlightOn;

		private float FlashlightRange = 45f;

		private const float FlashlightAngle = 65f;

		private const float FlashlightInnerAngle = 35f;

		private float FlashlightIntensity = 3.5f;

		private bool godMode;

		private bool godErrorLogged;

		private bool npcAiOff;

		private float nextNpcAiCheck;

		private Type aiBrainType;

		private bool aiBrainLooked;

		private readonly HashSet<int> aiDisabledByUs = new HashSet<int>();

		private const float HudDelay = 4f;

		private const bool UnlockFps = true;

		private string sceneName_;

		private float sceneStart;

		private bool warnedCam;

		private float nextReloadCheck;

		private readonly RaycastHit[] rayBuf = (RaycastHit[])(object)new RaycastHit[16];

		private const float BaseReach = 1f;

		private const float MaxReach = 3f;

		private const float ScrollStep = 1f / 3f;

		private HmdActionMap hmd;

		private LeftControllerActionMap leftMap;

		private RightControllerActionMap rightMap;

		private Camera cam;

		private float yaw;

		private float pitch;

		private float extend = 1f / 3f;

		private bool menuOpen;

		private bool spawnOpen;

		private bool armsAtSide = true;

		private readonly int[] sourceSlotForHand = new int[2] { -1, -1 };

		private readonly bool[] grip = new bool[2];

		private readonly bool[] gripPrev = new bool[2];

		private int leftBFrames;

		private bool bPrev;

		private float nextReload;

		private bool dumpedScene;

		private bool driveErrorLogged;

		private bool handErrorLogged;

		private readonly HashSet<string> dumped = new HashSet<string>();

		private static readonly Vector3[] RestPos = (Vector3[])(object)new Vector3[2]
		{
			new Vector3(-0.32f, -0.65f, 0.08f),
			new Vector3(0.32f, -0.65f, 0.08f)
		};

		private static readonly Vector3[] CarryPos = (Vector3[])(object)new Vector3[2]
		{
			new Vector3(-0.34f, -0.25f, 0.45f),
			new Vector3(0.34f, -0.25f, 0.45f)
		};

		private static readonly Quaternion[] RestRot = (Quaternion[])(object)new Quaternion[2]
		{
			Quaternion.Euler(50f, 0f, 0f),
			Quaternion.Euler(50f, 0f, 0f)
		};

		private static readonly Quaternion[] ReachRot = (Quaternion[])(object)new Quaternion[2]
		{
			Quaternion.Euler(327.5f, 353f, 0f),
			Quaternion.Euler(327.5f, 7f, 0f)
		};

		private readonly GameObject[] heldCache = (GameObject[])(object)new GameObject[2];

		private int gunHandCache;

		private float nextHeldCheck;

		private Gun heldGun;

		private string magText = "";

		private static Core Instance;

		private bool camTweaked;

		private Texture2D whiteTex;

		private GUIStyle labelStyle;

		private GUIStyle bigStyle;

		private GUIStyle smallStyle;

		private static readonly Color HudAmber = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)208, (byte)0, byte.MaxValue));

		private static readonly Color HudRed = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)56, (byte)40, byte.MaxValue));

		private static readonly Color HudBack = new Color(0f, 0f, 0f, 0.45f);

		private GUIStyle menuTitle;

		private GUIStyle menuButton;

		private GUIStyle menuNormal;

		private GUIStyle menuSub;

		private GUIStyle menuTag;

		private GUIStyle menuField;

		private GUIStyle menuToggle;

		private GUIStyle menuSliderTrack;

		private GUIStyle menuThumb;

		private float menuStyleScale = -1f;

		private Texture2D texBtn;

		private Texture2D texBtnHover;

		private Texture2D texBtnActive;

		private Texture2D texBtnOn;

		private Texture2D texField;

		private Texture2D texFieldFocus;

		private Texture2D texThumb;

		private Texture2D texThumbHover;

		private float themeR = 1f;

		private float themeG = 0.16f;

		private float themeB = 0.16f;

		private int themeTextMode;

		private string themeFont = "Default";

		private float themeFontScale = 1f;

		private bool themeBold = true;

		private bool themeScanlines = true;

		private bool themeAnimated = true;

		private bool themeBrackets = true;

		private int themeBtnStyle;

		private float themeOpacity = 0.96f;

		private int settingsTab;

		private int themeTab;

		private string themeSig = "";

		private Color ThAccent;

		private Color ThMid;

		private Color ThDim;

		private Color ThText;

		private Color ThSub;

		private Color ThPanel;

		private static readonly Color[] AccentPresets = (Color[])(object)new Color[8]
		{
			new Color(1f, 0.16f, 0.16f),
			new Color(1f, 0.5f, 0.1f),
			new Color(1f, 0.78f, 0.1f),
			new Color(0.2f, 1f, 0.4f),
			new Color(0.1f, 0.85f, 1f),
			new Color(0.3f, 0.5f, 1f),
			new Color(0.7f, 0.3f, 1f),
			new Color(1f, 0.2f, 0.6f)
		};

		private static readonly string[] TextPresetNames = new string[5] { "AUTO", "WHITE", "ICE", "AMBER", "MINT" };

		private static readonly Color[] TextPresets = (Color[])(object)new Color[5]
		{
			Color.white,
			Color.white,
			new Color(0.85f, 0.95f, 1f),
			new Color(1f, 0.85f, 0.55f),
			new Color(0.8f, 1f, 0.85f)
		};

		private static readonly string[] FontChoices = new string[10] { "Default", "Consolas", "Courier New", "Lucida Console", "Segoe UI", "Bahnschrift", "Verdana", "Trebuchet MS", "Impact", "Arial Black" };

		private static readonly string[] BtnStyleNames = new string[3] { "FILLED", "OUTLINE", "FLAT" };

		private readonly Dictionary<string, Font> fontCache = new Dictionary<string, Font>();

		private MelonPreferences_Category cfg;

		private readonly List<Action> cfgLoad = new List<Action>();

		private readonly List<Action> cfgSave = new List<Action>();

		private static readonly string[] MenuTitles = new string[10] { "PAUSE", "SETTINGS", "INVENTORY", "DEV TOOLS", "SPAWN MENU", "LEVEL SELECT", "AVATARS", "BONELIB MENU", "QUICK COMMANDS", "THEME" };

		private readonly HashSet<string> loggedBoneTypes = new HashSet<string>();

		private Hand HandOf(int i)
		{
			return (i == 0) ? Player.LeftHand : Player.RightHand;
		}

		private XRController PadOf(int i)
		{
			return (XRController)((i == 0) ? ((object)leftMap) : ((object)rightMap));
		}

		private ControllerActionMap MapOf(int i)
		{
			return (ControllerActionMap)((i == 0) ? ((object)leftMap) : ((object)rightMap));
		}

		private GameObject HeldObject(Hand h)
		{
			object obj = R.Get(h, "m_CurrentAttachedGO");
			return (GameObject)((obj is GameObject) ? obj : null);
		}

		private void RefreshHeld()
		{
			if (Time.time < nextHeldCheck)
			{
				return;
			}
			nextHeldCheck = Time.time + 0.1f;
			heldCache[0] = HeldObject(Player.LeftHand);
			heldCache[1] = HeldObject(Player.RightHand);
			Gun componentInHand = Player.GetComponentInHand<Gun>(Player.RightHand);
			Gun val = (((Object)(object)componentInHand != (Object)null) ? componentInHand : Player.GetComponentInHand<Gun>(Player.LeftHand));
			gunHandCache = (((Object)(object)componentInHand != (Object)null) ? 1 : 0);
			heldGun = val;
			magText = (((Object)(object)val == (Object)null) ? "" : ReadMagazine(val));
			meleeHandCache = -1;
			if (!((Object)(object)val == (Object)null))
			{
				return;
			}
			for (int i = 0; i < 2; i++)
			{
				if ((Object)(object)heldCache[i] != (Object)null && IsMeleeObject(heldCache[i]))
				{
					meleeHandCache = i;
					break;
				}
			}
		}

		private bool IsMeleeObject(GameObject go)
		{
			if ((Object)(object)go == (Object)null)
			{
				return false;
			}
			string text = ((Object)go.transform.root).name.ToLowerInvariant();
			if (text.Contains("battery") || text.Contains("combat"))
			{
				return false;
			}
			return HasAny(text, "sword", "knife", "blade", "axe", "bat", "baseball", "crowbar", "dagger", "spear", "hammer", "wrench", "melee", "machete", "katana", "mace", "club", "shovel", "pipe");
		}

		private string ReadMagazine(Gun gun)
		{
			Dump("Gun", gun);
			string[] array = new string[2] { "magazineState", "MagazineState" };
			string[] array2 = array;
			foreach (string name in array2)
			{
				object o = R.Get(gun, name);
				string[] array3 = new string[4] { "AmmoCount", "ammoCount", "rounds", "Rounds" };
				foreach (string name2 in array3)
				{
					if (R.Get(o, name2) is int num)
					{
						return num.ToString();
					}
				}
			}
			object o2 = R.Get(R.Get(gun, "ammoSocket"), "_magazinePlug");
			object o3 = R.Get(o2, "magazine");
			object o4 = R.Get(o3, "magazineState");
			string[] array4 = new string[4] { "AmmoCount", "ammoCount", "rounds", "Rounds" };
			foreach (string name3 in array4)
			{
				if (R.Get(o4, name3) is int num2)
				{
					return num2.ToString();
				}
			}
			return "--";
		}

		private void Dump(string label, object o)
		{
			if (o == null)
			{
				((MelonBase)this).LoggerInstance.Msg("[dump] " + label + " = null");
			}
			else
			{
				if (!dumped.Add(label))
				{
					return;
				}
				List<string> list = R.MemberNames(o);
				((MelonBase)this).LoggerInstance.Msg("[dump] " + label + " (" + o.GetType().FullName + ") " + list.Count + " members");
				string text = "";
				foreach (string item in list)
				{
					if (text.Length + item.Length > 900)
					{
						((MelonBase)this).LoggerInstance.Msg("[dump]   " + text);
						text = "";
					}
					text = text + item + " ";
				}
				if (text.Length > 0)
				{
					((MelonBase)this).LoggerInstance.Msg("[dump]   " + text);
				}
			}
		}

		private void LockCursor(bool locked)
		{
			Cursor.lockState = (CursorLockMode)(locked ? 1 : 0);
			Cursor.visible = !locked;
		}

		private bool Connect()
		{
			try
			{
				if ((Object)(object)cam == (Object)null)
				{
					cam = Camera.main;
				}
				if ((Object)(object)cam != (Object)null && !camTweaked)
				{
					camTweaked = true;
					cam.cameraType = (CameraType)2;
					cam.fieldOfView = 90f;
				}
				if (hmd != null && leftMap != null && rightMap != null)
				{
					return (Object)(object)cam != (Object)null;
				}
				XRApi xr = MarrowGame.xr;
				if (xr == null)
				{
					return false;
				}
				hmd = ((Il2CppObjectBase)xr.HMD).TryCast<HmdActionMap>();
				leftMap = ((Il2CppObjectBase)xr.LeftController).TryCast<LeftControllerActionMap>();
				rightMap = ((Il2CppObjectBase)xr.RightController).TryCast<RightControllerActionMap>();
				if (hmd != null && leftMap != null && rightMap != null)
				{
					((MelonBase)this).LoggerInstance.Msg("Connected to HMD + both controllers");
				}
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("connect: " + ex.Message);
				hmd = null;
			}
			return hmd != null && leftMap != null && rightMap != null && (Object)(object)cam != (Object)null;
		}

		public override void OnInitializeMelon()
		{
			Instance = this;
			((MelonBase)this).LoggerInstance.Msg("TrueDesktopMod loaded");
			InitConfig();
			SwapInMockHeadset();
			ApplyBypassPatches();
			SetupDisplay();
		}

		private void SetupDisplay()
		{
			try
			{
				int systemWidth = Display.main.systemWidth;
				int systemHeight = Display.main.systemHeight;
				Screen.SetResolution(systemWidth, systemHeight, (FullScreenMode)1);
				bool flag = true;
				QualitySettings.vSyncCount = 0;
				Application.targetFrameRate = -1;
				((MelonBase)this).LoggerInstance.Msg("Display: " + systemWidth + "x" + systemHeight + " fullscreen");
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("display setup: " + ex.Message);
			}
		}

		private void SwapInMockHeadset()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			try
			{
				List<XRLoader> loaders = XRGeneralSettings.Instance.Manager.loaders;
				MockHMDLoader val = ScriptableObject.CreateInstance<MockHMDLoader>();
				loaders.Clear();
				loaders.Add((XRLoader)val);
				((MelonBase)this).LoggerInstance.Msg("Bypass: MockHMD loader installed");
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Error("Bypass: could not install MockHMD loader: " + ex);
			}
		}

		private static bool ReturnTruePrefix(ref bool __result)
		{
			__result = true;
			return false;
		}

		private static bool FeatureTruePrefix(out bool value, ref bool __result)
		{
			value = true;
			return false;
		}

		private static void OnMarrowReadyPostfix(OpenControllerRig __instance)
		{
			try
			{
				Camera main = Camera.main;
				if (!((Object)(object)main == (Object)null) && !((Object)(object)((Component)__instance).transform.root != (Object)(object)((Component)main).transform.root))
				{
					Instance.BootControllers(main);
				}
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("Bypass: controller boot failed: " + ex.Message);
			}
		}

		private void Patch(Harmony h, MethodBase target, string label, string prefix, string postfix = null)
		{
			//IL_0042: 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)
			if (target == null)
			{
				((MelonBase)this).LoggerInstance.Warning("Bypass: could not find " + label);
				return;
			}
			try
			{
				HarmonyMethod val = ((prefix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(Core).GetMethod(prefix, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)));
				HarmonyMethod val2 = ((postfix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(Core).GetMethod(postfix, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)));
				h.Patch(target, val, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				((MelonBase)this).LoggerInstance.Msg("Bypass: patched " + label);
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("Bypass: patch failed for " + label + ": " + ex.Message);
			}
		}

		private Type FindType(Func<Type, bool> match)
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				Type[] types;
				try
				{
					types = assembly.GetTypes();
				}
				catch
				{
					continue;
				}
				Type[] array = types;
				foreach (Type type in array)
				{
					try
					{
						if (match(type))
						{
							return type;
						}
					}
					catch
					{
					}
				}
			}
			return null;
		}

		private void ApplyBypassPatches()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony h = new Harmony("TrueDesktopMod.bypass");
			Type typeFromHandle = typeof(XRDevice);
			MethodBase target = typeFromHandle.GetProperty("IsTracking", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetGetMethod(nonPublic: true) ?? typeFromHandle.GetMethod("get_IsTracking", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			Patch(h, target, "XRDevice.IsTracking", "ReturnTruePrefix");
			MethodBase target2 = FindType((Type t) => t.FullName == "UnityEngine.XR.InputDevice")?.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault(delegate(MethodInfo m)
			{
				if (m.Name != "TryGetFeatureValue")
				{
					return false;
				}
				ParameterInfo[] parameters = m.GetParameters();
				return parameters.Length == 2 && parameters[0].ParameterType.IsGenericType && parameters[0].ParameterType.GetGenericArguments()[0] == typeof(bool) && parameters[1].ParameterType.IsByRef && parameters[1].ParameterType.GetElementType() == typeof(bool);
			});
			Patch(h, target2, "InputDevice.TryGetFeatureValue(bool)", "FeatureTruePrefix");
			MethodBase target3 = FindType((Type t) => t.Name.StartsWith("__c__DisplayClass") && t.GetMethod("_InitializeXRLoader_b__0", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) != null)?.GetMethod("_InitializeXRLoader_b__0", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			Patch(h, target3, "XRApi.InitializeXRLoader check", "ReturnTruePrefix");
			MethodBase method = typeof(OpenControllerRig).GetMethod("OnMarrowReady", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			Patch(h, method, "OpenControllerRig.OnMarrowReady", null, "OnMarrowReadyPostfix");
		}

		private void BootControllers(Camera main)
		{
			//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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_00ba: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			XRApi xr = MarrowGame.xr;
			hmd = ((Il2CppObjectBase)xr.HMD).TryCast<HmdActionMap>();
			leftMap = ((Il2CppObjectBase)xr.LeftController).TryCast<LeftControllerActionMap>();
			rightMap = ((Il2CppObjectBase)xr.RightController).TryCast<RightControllerActionMap>();
			cam = main;
			if (hmd == null || leftMap == null || rightMap == null)
			{
				((MelonBase)this).LoggerInstance.Warning("Bypass: XR maps not available yet");
				return;
			}
			XRDevice val = (XRDevice)(object)leftMap;
			XRDevice val2 = (XRDevice)(object)rightMap;
			InputDevice xrDevice = val._xrDevice;
			xrDevice.m_Initialized = true;
			val._xrDevice = xrDevice;
			InputDevice xrDevice2 = val2._xrDevice;
			xrDevice2.m_Initialized = true;
			val2._xrDevice = xrDevice2;
			InputDeviceCharacteristics val3 = (InputDeviceCharacteristics)96;
			val._Characteristics_k__BackingField = (InputDeviceCharacteristics)(val3 | 0x100);
			val2._Characteristics_k__BackingField = (InputDeviceCharacteristics)(val3 | 0x200);
			((XRController)leftMap).Type = (XRControllerType)0;
			((XRController)rightMap).Type = (XRControllerType)0;
			val._IsConnected_k__BackingField = true;
			val2._IsConnected_k__BackingField = true;
			((ControllerActionMap)leftMap)._position = Vector3.zero;
			((ControllerActionMap)rightMap)._position = Vector3.zero;
			((ControllerActionMap)leftMap)._rotation = Quaternion.identity;
			((ControllerActionMap)rightMap)._rotation = Quaternion.identity;
			val.Refresh();
			val2.Refresh();
			((MelonBase)this).LoggerInstance.Msg("Bypass: fake controllers ready");
		}

		public override void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
			((MelonBase)this).LoggerInstance.Msg("Scene initialized: " + sceneName);
			cam = null;
			hmd = null;
			leftMap = null;
			rightMap = null;
			camTweaked = false;
			menuOpen = (spawnOpen = false);
			bool[] array = grip;
			bool[] array2 = grip;
			bool flag;
			gripPrev[0] = (flag = (gripPrev[1] = false));
			array2[1] = (flag = flag);
			array[0] = flag;
			sourceSlotForHand[0] = (sourceSlotForHand[1] = -1);
			armsAtSide = true;
			yaw = (pitch = 0f);
			extend = 1f / 3f;
			leftBFrames = 0;
			propYaw = (propPitch = 0f);
			leftXFrames = 0;
			gunLockActive = false;
			gunDropUntil = 0f;
			curFov = fov;
			meleeLockActive = false;
			meleeHandCache = -1;
			swingStart = -10f;
			regripFrames[0] = (regripFrames[1] = 0);
			nextRegrip[0] = (nextRegrip[1] = 0f);
			noclip = false;
			noclipColliders.Clear();
			noclipBodies.Clear();
			noclipGravity.Clear();
			aiDisabledByUs.Clear();
			nextNpcAiCheck = 0f;
			spawnHistory.Clear();
			dumpedScene = false;
			sceneName_ = sceneName;
			sceneStart = Time.realtimeSinceStartup;
			LockCursor(locked: true);
		}

		public override void OnUpdate()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if (!menuOpen && !spawnOpen)
			{
				float num = Input.mouseScrollDelta.y;
				if (Mathf.Abs(num) < 0.01f)
				{
					try
					{
						num = Input.GetAxis("Mouse ScrollWheel") * 10f;
					}
					catch
					{
					}
				}
				if (Mathf.Abs(num) > 0.01f)
				{
					extend = Mathf.Clamp(extend + Mathf.Sign(num) * (1f / 3f), 1f / 3f, 1f);
					armsAtSide = false;
				}
			}
			if (Connect())
			{
				if (!dumpedScene)
				{
					dumpedScene = true;
					Dump("Hand", Player.LeftHand);
					Dump("Inventory", R.Get(Player.RigManager, "inventory"));
				}
				RefreshHeld();
				SyncFlashlight();
				if (godMode)
				{
					GodModeStep();
				}
				if (npcAiOff && Time.time >= nextNpcAiCheck)
				{
					nextNpcAiCheck = Time.time + 1.5f;
					ApplyNpcAi();
				}
				HandleKeys();
			}
		}

		public override void OnLateUpdate()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Invalid comparison between Unknown and I4
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Invalid comparison between Unknown and I4
			if (hmd != null && leftMap != null && rightMap != null)
			{
				ForceFlatCamera();
				bool flag = menuOpen || spawnOpen;
				if (flag && (int)Cursor.lockState > 0)
				{
					LockCursor(locked: false);
				}
				if (!flag && (int)Cursor.lockState != 1)
				{
					LockCursor(locked: true);
				}
				Drive();
			}
		}

		private void ForceFlatCamera()
		{
			try
			{
				if (!((Object)(object)cam == (Object)null))
				{
					cam.stereoTargetEye = (StereoTargetEyeMask)0;
					cam.cameraType = (CameraType)2;
					float num = ((gunLockActive && !menuOpen && !spawnOpen && Input.GetMouseButton(1)) ? Mathf.Min(ZoomFov, fov) : fov);
					curFov = Mathf.Lerp(curFov, num, 1f - Mathf.Exp(-14f * Time.unscaledDeltaTime));
					cam.fieldOfView = curFov;
					cam.ResetAspect();
					cam.ResetProjectionMatrix();
				}
			}
			catch (Exception ex)
			{
				if (!warnedCam)
				{
					warnedCam = true;
					((MelonBase)this).LoggerInstance.Warning("flat camera: " + ex.Message);
				}
			}
		}

		private bool HudReady()
		{
			if (hmd == null)
			{
				return false;
			}
			if (Time.realtimeSinceStartup - sceneStart < 4f)
			{
				return false;
			}
			string text = (sceneName_ ?? "").ToLowerInvariant();
			if (text.Contains("menu") || text.Contains("load") || text.Contains("boot") || text.Contains("splash"))
			{
				return false;
			}
			try
			{
				return (Object)(object)Player.RigManager != (Object)null && (Object)(object)Player.RigManager.health != (Object)null;
			}
			catch
			{
				return false;
			}
		}

		private void HandleKeys()
		{
			if (Input.GetKeyDown((KeyCode)27))
			{
				ToggleMenu();
			}
			if (Input.GetKeyDown((KeyCode)9))
			{
				ToggleSpawnMenu();
			}
			if (Input.GetKeyDown((KeyCode)99) && (!menuOpen || menuPage != 4))
			{
				ToggleCommandMenu();
			}
			if (menuOpen)
			{
				if (menuPage != 4 && Input.GetKeyDown((KeyCode)54))
				{
					ReturnAllToInventory();
				}
			}
			else
			{
				if (spawnOpen)
				{
					return;
				}
				bool flag = gunFireMode && (Object)(object)heldGun != (Object)null;
				bool flag2 = gunFireMode && !flag && meleeHandCache >= 0 && (Object)(object)heldCache[meleeHandCache] != (Object)null;
				gunLockActive = flag;
				meleeLockActive = flag2;
				adsBlend = Mathf.MoveTowards(adsBlend, (flag && Input.GetMouseButton(1)) ? 1f : 0f, Time.deltaTime / 0.12f);
				if (flag || flag2)
				{
					int num = (flag ? gunHandCache : meleeHandCache);
					if (Input.GetKeyDown((KeyCode)103))
					{
						gunDropUntil = Time.time + 0.5f;
					}
					grip[num] = Time.time >= gunDropUntil;
					grip[1 - num] = Input.GetMouseButton(2);
					if (flag2 && Input.GetMouseButtonDown(0) && Time.time >= gunDropUntil && Time.time - swingStart > 0.18f)
					{
						swingStart = Time.time;
					}
				}
				else
				{
					grip[0] = Input.GetMouseButton(0);
					grip[1] = Input.GetMouseButton(1);
				}
				for (int i = 0; i < 2; i++)
				{
					CallbackStep(i);
				}
				for (int j = 0; j < 2; j++)
				{
					if (regripFrames[j] > 0)
					{
						grip[j] = false;
						regripFrames[j]--;
					}
				}
				for (int k = 0; k < 4; k++)
				{
					if (Input.GetKeyDown((KeyCode)(49 + k)))
					{
						Hotbar(k);
					}
				}
				if (Input.GetKeyDown((KeyCode)54))
				{
					ReturnAllToInventory();
				}
				if (Input.GetKeyDown((KeyCode)122))
				{
					UndoLastSpawn();
				}
				if (Input.GetKeyDown((KeyCode)102))
				{
					leftXFrames = 3;
				}
				if (Input.GetKeyDown((KeyCode)118))
				{
					ToggleNoclip();
				}
				if (Input.GetKeyDown((KeyCode)108))
				{
					ToggleFlashlight();
				}
				bool flag3 = (Object)(object)heldCache[0] != (Object)null || (Object)(object)heldCache[1] != (Object)null;
				if (!flag3 || Input.GetKeyDown((KeyCode)8))
				{
					propYaw = (propPitch = 0f);
				}
				float num2 = Input.GetAxisRaw("Mouse X") * lookSpeed;
				float num3 = Input.GetAxisRaw("Mouse Y") * lookSpeed;
				if (Input.GetKeyDown((KeyCode)114))
				{
					ReloadNow();
				}
				if (flag3 && Input.GetKey((KeyCode)116))
				{
					propYaw += num2;
					propPitch -= num3;
				}
				else
				{
					float num4 = ((fov > 0.01f) ? Mathf.Clamp(curFov / fov, 0.2f, 1f) : 1f);
					yaw += num2 * num4;
					pitch = Mathf.Clamp(pitch + num3 * num4, -87f, 87f);
				}
				if (flag3)
				{
					float num5 = 120f * Time.deltaTime;
					if (Input.GetKey((KeyCode)275))
					{
						propYaw += num5;
					}
					if (Input.GetKey((KeyCode)276))
					{
						propYaw -= num5;
					}
					if (Input.GetKey((KeyCode)274))
					{
						propPitch += num5;
					}
					if (Input.GetKey((KeyCode)273))
					{
						propPitch -= num5;
					}
				}
				AutoReload();
			}
		}

		private void SetStickClick(XRController pad, bool pressed)
		{
			if (pad == null)
			{
				return;
			}
			string[] array = new string[5] { "Joystick2DClick", "JoystickClick", "ThumbstickClick", "ThumbstickButton", "JoystickButton" };
			Type type = ((object)pad).GetType();
			string[] array2 = array;
			foreach (string name in array2)
			{
				try
				{
					PropertyInfo property = type.GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (property != null && property.CanWrite && property.PropertyType == typeof(bool))
					{
						property.SetValue(pad, pressed, null);
						break;
					}
					FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field != null && field.FieldType == typeof(bool))
					{
						field.SetValue(pad, pressed);
						break;
					}
				}
				catch
				{
				}
			}
		}

		private void Drive()
		{
			//IL_0429: Unknown result type (might be due to invalid IL or missing references)
			//IL_0431: Unknown result type (might be due to invalid IL or missing references)
			//IL_0436: Unknown result type (might be due to invalid IL or missing references)
			//IL_0449: Unknown result type (might be due to invalid IL or missing references)
			//IL_0451: Unknown result type (might be due to invalid IL or missing references)
			//IL_0456: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_0040: 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_004c: 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_00fd: 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_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: 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)
			try
			{
				bool flag = menuOpen || spawnOpen;
				Quaternion val = Quaternion.AngleAxis(yaw, Vector3.up) * Quaternion.AngleAxis(pitch, Vector3.left);
				hmd._rotation = val;
				Vector2 zero = Vector2.zero;
				if (!flag)
				{
					if (Input.GetKey((KeyCode)119))
					{
						zero.y += 1f;
					}
					if (Input.GetKey((KeyCode)115))
					{
						zero.y -= 1f;
					}
					if (Input.GetKey((KeyCode)100))
					{
						zero.x += 1f;
					}
					if (Input.GetKey((KeyCode)97))
					{
						zero.x -= 1f;
					}
					if (((Vector2)(ref zero)).sqrMagnitude > 1f)
					{
						((Vector2)(ref zero)).Normalize();
					}
				}
				if (noclip)
				{
					zero = Vector2.zero;
				}
				bool flag2 = !flag && (Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303));
				curMoveSpeed = Mathf.MoveTowards(curMoveSpeed, flag2 ? sprintSpeed : walkSpeed, 80f * Time.deltaTime);
				PadOf(0).Joystick2DAxis = zero * (curMoveSpeed / 16f);
				bool flag3 = !flag && (Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305));
				PadOf(1).Joystick2DAxis = new Vector2(0f, (flag3 && !noclip) ? (-1f) : 0f);
				SetStickClick(PadOf(0), flag2);
				bool aButton = !flag && !noclip && Input.GetKey((KeyCode)32);
				PadOf(1).AButton = aButton;
				PadOf(1).AButtonDown = !flag && !noclip && Input.GetKeyDown((KeyCode)32);
				PadOf(1).AButtonUp = !flag && !noclip && Input.GetKeyUp((KeyCode)32);
				bool flag4 = leftBFrames > 0;
				PadOf(0).BButton = flag4;
				PadOf(0).BButtonDown = flag4 && !bPrev;
				PadOf(0).BButtonUp = !flag4 && bPrev;
				bPrev = flag4;
				if (leftBFrames > 0)
				{
					leftBFrames--;
				}
				bool flag5 = leftXFrames > 0;
				PadOf(0).AButton = flag5;
				PadOf(0).AButtonDown = flag5 && !xPrev;
				PadOf(0).AButtonUp = !flag5 && xPrev;
				xPrev = flag5;
				if (leftXFrames > 0)
				{
					leftXFrames--;
				}
				for (int i = 0; i < 2; i++)
				{
					float gripForce = (grip[i] ? 1f : 0f);
					XRController val2 = PadOf(i);
					val2.Grip = gripForce;
					val2.GripForce = gripForce;
					val2.GripButton = grip[i];
					val2.GripButtonDown = grip[i] && !gripPrev[i];
					val2.GripButtonUp = !grip[i] && gripPrev[i];
					gripPrev[i] = grip[i];
					try
					{
						PlaceHand(i, val);
					}
					catch (Exception ex)
					{
						if (!handErrorLogged)
						{
							handErrorLogged = true;
							((MelonBase)this).LoggerInstance.Warning("place hand " + i + " failed (first occurrence): " + ex);
						}
						try
						{
							MapOf(i)._position = val * RestPos[i];
							MapOf(i)._rotation = val * RestRot[i];
						}
						catch
						{
						}
					}
				}
				PadOf(0).Trigger = 0f;
				PadOf(1).Trigger = 0f;
				if (!flag && Input.GetKey((KeyCode)113))
				{
					PadOf(0).Trigger = 1f;
				}
				if (!flag && Input.GetKey((KeyCode)101))
				{
					PadOf(1).Trigger = 1f;
				}
				if (!flag && gunLockActive && Input.GetMouseButton(0))
				{
					PadOf(gunHandCache).Trigger = 1f;
				}
				if (noclip)
				{
					NoclipStep(flag);
				}
				if (meleeLockActive && !flag)
				{
					MeleeBoost();
				}
			}
			catch (Exception ex2)
			{
				if (!driveErrorLogged)
				{
					driveErrorLogged = true;
					((MelonBase)this).LoggerInstance.Warning("drive failed (first occurrence): " + ex2);
				}
			}
		}

		private void PlaceHand(int i, Quaternion hmdRot)
		{
			//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_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_0059: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: 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_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: 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_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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)
			Vector3 local;
			Quaternion rot;
			if (armsAtSide && (Object)(object)heldCache[i] == (Object)null)
			{
				local = RestPos[i];
				rot = RestRot[i];
			}
			else if ((Object)(object)heldCache[i] != (Object)null)
			{
				local = CarryPos[i] + new Vector3(0f, 0f, extend * 1.5f);
				rot = Quaternion.Euler(propPitch, propYaw, 0f) * ReachRot[i];
				if (meleeLockActive && i == meleeHandCache)
				{
					ApplySwing(ref local, ref rot);
				}
				if (gunLockActive && i == gunHandCache && adsBlend > 0.001f)
				{
					local = Vector3.Lerp(local, AdsLocal, adsBlend);
					rot = Quaternion.Slerp(rot, AdsRot, adsBlend);
				}
			}
			else if (extend > 0.01f)
			{
				local = ReachTarget(i);
				rot = ReachRot[i];
			}
			else
			{
				local = RestPos[i];
				rot = RestRot[i];
			}
			MapOf(i)._position = hmdRot * local;
			MapOf(i)._rotation = hmdRot * rot;
		}

		private Vector3 ReachTarget(int handIndex)
		{
			//IL_004a: 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_0056: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_0076: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: 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_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)cam).transform;
			float num = ((handIndex == 0) ? (-1f) : 1f);
			float num2 = Mathf.Lerp(0.24f, 0.42f, extend);
			float num3 = Mathf.Lerp(0.75f, 3f, extend);
			Vector3 val = transform.position + transform.right * num * num2;
			Vector3 val2 = val + transform.forward * num3;
			int num4 = Physics.RaycastNonAlloc(val, transform.forward, Il2CppStructArray<RaycastHit>.op_Implicit(rayBuf), num3, -1, (QueryTriggerInteraction)1);
			Transform val3 = null;
			try
			{
				PhysicsRig physicsRig = Player.PhysicsRig;
				if ((Object)(object)physicsRig != (Object)null)
				{
					val3 = ((Component)physicsRig).transform.root;
				}
			}
			catch
			{
			}
			Transform val4 = (((Object)(object)heldCache[0] != (Object)null) ? heldCache[0].transform.root : null);
			Transform val5 = (((Object)(object)heldCache[1] != (Object)null) ? heldCache[1].transform.root : null);
			float num5 = float.MaxValue;
			for (int i = 0; i < num4; i++)
			{
				RaycastHit val6 = rayBuf[i];
				Collider collider = ((RaycastHit)(ref val6)).collider;
				if (!((Object)(object)collider == (Object)null))
				{
					Transform root = ((Component)collider).transform.root;
					if (!((Object)(object)root == (Object)(object)transform.root) && (!((Object)(object)val3 != (Object)null) || !((Object)(object)root == (Object)(object)val3)) && (!((Object)(object)val4 != (Object)null) || !((Object)(object)root == (Object)(object)val4)) && (!((Object)(object)val5 != (Object)null) || !((Object)(object)root == (Object)(object)val5)) && ((RaycastHit)(ref val6)).distance < num5)
					{
						num5 = ((RaycastHit)(ref val6)).distance;
					}
				}
			}
			if (num5 < float.MaxValue)
			{
				val2 = val + transform.forward * Mathf.Max(0.3f, num5 - 0.12f);
			}
			Vector3 val7 = Quaternion.Inverse(transform.rotation) * (val2 - transform.position);
			val7 = Vector3.ClampMagnitude(val7, num3 + num2);
			if (float.IsNaN(val7.x) || float.IsNaN(val7.y) || float.IsNaN(val7.z))
			{
				return RestPos[handIndex];
			}
			return val7;
		}

		private object BodySlot(int slotIndex)
		{
			object o = R.Get(Player.RigManager, "inventory");
			if (!(R.Get(o, "bodySlots") is IEnumerable enumerable))
			{
				return null;
			}
			int num = 0;
			foreach (object item in enumerable)
			{
				if (num++ == slotIndex)
				{
					return item;
				}
			}
			return null;
		}

		private bool TryReturnToSlot(int slotIndex, Hand hand)
		{
			if (slotIndex < 0)
			{
				return false;
			}
			object o = BodySlot(slotIndex);
			object obj = R.Get(o, "inventorySlotReceiver");
			if (obj == null)
			{
				return false;
			}
			string[] array = new string[6] { "OnHandRelease", "ReturnItem", "StoreItem", "PlaceItem", "OnHandDrop", "Holster" };
			string[] array2 = array;
			foreach (string name in array2)
			{
				if (R.TryCall(obj, name, out var result, hand))
				{
					return true;
				}
				if (R.TryCall(obj, name, out result))
				{
					return true;
				}
			}
			return false;
		}

		private void ReturnHandToSource(int handIndex)
		{
			if ((Object)(object)heldCache[handIndex] == (Object)null)
			{
				sourceSlotForHand[handIndex] = -1;
				return;
			}
			if (!TryReturnToSlot(sourceSlotForHand[handIndex], HandOf(handIndex)))
			{
				((MelonBase)this).LoggerInstance.Warning("Could not return held item to its original body slot automatically; this BONELAB build may not expose a compatible slot-return method.");
			}
			sourceSlotForHand[handIndex] = -1;
			grip[handIndex] = false;
		}

		private void ReturnAllToInventory()
		{
			ReturnHandToSource(0);
			ReturnHandToSource(1);
			armsAtSide = true;
			extend = 1f / 3f;
			grip[0] = (grip[1] = false);
		}

		private void Hotbar(int i)
		{
			try
			{
				ReturnHandToSource(1);
				armsAtSide = false;
				object obj = BodySlot(i);
				if (obj == null)
				{
					((MelonBase)this).LoggerInstance.Warning("inventory body slot " + (i + 1) + " not found");
					return;
				}
				Dump("BodySlot", obj);
				object o = R.Get(obj, "inventorySlotReceiver");
				Dump("SlotReceiver", o);
				if (R.TryCall(o, "OnHandGrab", out var _, Player.RightHand))
				{
					sourceSlotForHand[1] = i;
					grip[1] = true;
				}
				else
				{
					((MelonBase)this).LoggerInstance.Warning("OnHandGrab not found, see [dump] SlotReceiver");
				}
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("hotbar: " + ex.Message);
			}
		}

		private void RecordSpawn(GameObject go)
		{
			if ((Object)(object)go != (Object)null)
			{
				spawnHistory.Push(go);
			}
		}

		private bool TryMakeSpawnCallback(Type actionType, out object callback)
		{
			callback = null;
			try
			{
				Type type = actionType.GetGenericArguments()[0];
				Delegate obj;
				if (type == typeof(GameObject))
				{
					obj = (Action<GameObject>)delegate(GameObject go)
					{
						RecordSpawn(go);
					};
				}
				else
				{
					if (!(type == typeof(Poolee)))
					{
						return false;
					}
					obj = (Action<Poolee>)delegate(Poolee p)
					{
						RecordSpawn(((Object)(object)p != (Object)null) ? ((Component)p).gameObject : null);
					};
				}
				MethodInfo method = typeof(DelegateSupport).GetMethod("ConvertDelegate", BindingFlags.Static | BindingFlags.Public);
				if (method == null)
				{
					return false;
				}
				callback = method.MakeGenericMethod(actionType).Invoke(null, new object[1] { obj });
				return callback != null;
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("spawn callback: " + ex.GetBaseException().Message);
				return false;
			}
		}

		private void UndoLastSpawn()
		{
			while (spawnHistory.Count > 0)
			{
				GameObject val = spawnHistory.Pop();
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				try
				{
					Poolee componentInParent = val.GetComponentInParent<Poolee>();
					if ((Object)(object)componentInParent != (Object)null)
					{
						componentInParent.Despawn();
					}
					else
					{
						Object.Destroy((Object)(object)val);
					}
					((MelonBase)this).LoggerInstance.Msg("Undo spawn: " + ((Object)val).name + " (" + spawnHistory.Count + " left)");
					return;
				}
				catch (Exception ex)
				{
					((MelonBase)this).LoggerInstance.Warning("undo spawn: " + ex.GetBaseException().Message);
					return;
				}
			}
			((MelonBase)this).LoggerInstance.Msg("Undo spawn: nothing to undo");
		}

		private void ToggleNoclip()
		{
			try
			{
				if (noclip)
				{
					RestoreNoclip();
					return;
				}
				PhysicsRig physicsRig = Player.PhysicsRig;
				if ((Object)(object)physicsRig == (Object)null)
				{
					((MelonBase)this).LoggerInstance.Warning("noclip: physics rig not ready");
					return;
				}
				noclipColliders.Clear();
				noclipBodies.Clear();
				noclipGravity.Clear();
				foreach (Collider componentsInChild in ((Component)physicsRig).GetComponentsInChildren<Collider>(true))
				{
					if (!((Object)(object)componentsInChild == (Object)null) && componentsInChild.enabled && !componentsInChild.isTrigger)
					{
						componentsInChild.enabled = false;
						noclipColliders.Add(componentsInChild);
					}
				}
				foreach (Rigidbody componentsInChild2 in ((Component)physicsRig).GetComponentsInChildren<Rigidbody>(true))
				{
					if (!((Object)(object)componentsInChild2 == (Object)null))
					{
						noclipBodies.Add(componentsInChild2);
						noclipGravity.Add(componentsInChild2.useGravity);
						componentsInChild2.useGravity = false;
					}
				}
				noclip = true;
				((MelonBase)this).LoggerInstance.Msg("Noclip ON (" + noclipColliders.Count + " colliders, " + noclipBodies.Count + " bodies)");
			}
			catch (Exception ex)
			{
				noclip = false;
				((MelonBase)this).LoggerInstance.Warning("noclip toggle: " + ex.GetBaseException().Message);
			}
		}

		private void RestoreNoclip()
		{
			noclip = false;
			try
			{
				foreach (Collider noclipCollider in noclipColliders)
				{
					if ((Object)(object)noclipCollider != (Object)null)
					{
						noclipCollider.enabled = true;
					}
				}
				for (int i = 0; i < noclipBodies.Count; i++)
				{
					if ((Object)(object)noclipBodies[i] != (Object)null)
					{
						noclipBodies[i].useGravity = noclipGravity[i];
					}
				}
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("noclip restore: " + ex.GetBaseException().Message);
			}
			noclipColliders.Clear();
			noclipBodies.Clear();
			noclipGravity.Clear();
			((MelonBase)this).LoggerInstance.Msg("Noclip OFF");
		}

		private void NoclipStep(bool ui)
		{
			//IL_0024: 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_0045: 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_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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: 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_00ae: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: 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)
			if ((Object)(object)cam == (Object)null)
			{
				return;
			}
			Transform transform = ((Component)cam).transform;
			Vector3 val = Vector3.zero;
			if (!ui)
			{
				if (Input.GetKey((KeyCode)119))
				{
					val += transform.forward;
				}
				if (Input.GetKey((KeyCode)115))
				{
					val -= transform.forward;
				}
				if (Input.GetKey((KeyCode)100))
				{
					val += transform.right;
				}
				if (Input.GetKey((KeyCode)97))
				{
					val -= transform.right;
				}
				if (Input.GetKey((KeyCode)32))
				{
					val += Vector3.up;
				}
				if (Input.GetKey((KeyCode)306) || Input.GetKey((KeyCode)305))
				{
					val -= Vector3.up;
				}
			}
			bool flag = Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303);
			Vector3 velocity = ((((Vector3)(ref val)).sqrMagnitude > 0.001f) ? (((Vector3)(ref val)).normalized * (flag ? NoclipFastSpeed : NoclipSpeed)) : Vector3.zero);
			foreach (Rigidbody noclipBody in noclipBodies)
			{
				if ((Object)(object)noclipBody != (Object)null)
				{
					noclipBody.velocity = velocity;
				}
			}
		}

		private void EnsureFlashlight()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			//IL_009c: 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_010e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)cam == (Object)null) && (!((Object)(object)flashlight != (Object)null) || !((Object)(object)((Component)flashlight).transform.parent == (Object)(object)((Component)cam).transform)))
			{
				if ((Object)(object)flashlight != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)flashlight).gameObject);
				}
				GameObject val = new GameObject("TrueDesktop_Flashlight");
				val.transform.SetParent(((Component)cam).transform, false);
				val.transform.localPosition = Vector3.zero;
				val.transform.localRotation = Quaternion.identity;
				Light val2 = val.AddComponent<Light>();
				val2.type = (LightType)0;
				val2.range = FlashlightRange;
				val2.spotAngle = 65f;
				val2.innerSpotAngle = 35f;
				val2.intensity = FlashlightIntensity;
				val2.color = new Color(1f, 0.96f, 0.88f, 1f);
				val2.shadows = (LightShadows)0;
				val2.renderMode = (LightRenderMode)1;
				((Behaviour)val2).enabled = false;
				flashlight = val2;
			}
		}

		private void ToggleFlashlight()
		{
			try
			{
				EnsureFlashlight();
				if ((Object)(object)flashlight == (Object)null)
				{
					((MelonBase)this).LoggerInstance.Warning("flashlight: camera not ready");
					return;
				}
				flashlightOn = !flashlightOn;
				((Behaviour)flashlight).enabled = flashlightOn;
				((MelonBase)this).LoggerInstance.Msg("Flashlight " + (flashlightOn ? "ON" : "OFF"));
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("flashlight toggle: " + ex.GetBaseException().Message);
			}
		}

		private void SyncFlashlight()
		{
			if (!flashlightOn || (Object)(object)cam == (Object)null)
			{
				return;
			}
			try
			{
				if ((Object)(object)flashlight == (Object)null || (Object)(object)((Component)flashlight).transform.parent != (Object)(object)((Component)cam).transform)
				{
					EnsureFlashlight();
					if ((Object)(object)flashlight != (Object)null)
					{
						((Behaviour)flashlight).enabled = true;
					}
				}
				if ((Object)(object)flashlight != (Object)null)
				{
					flashlight.range = FlashlightRange;
					flashlight.intensity = FlashlightIntensity;
				}
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("flashlight sync: " + ex.GetBaseException().Message);
			}
		}

		private void ToggleCommandMenu()
		{
			if (menuOpen && menuPage == 8)
			{
				menuOpen = false;
				spawnOpen = false;
				LockCursor(locked: true);
			}
			else
			{
				menuOpen = true;
				spawnOpen = false;
				menuPage = 8;
				menuMessage = "";
				LockCursor(locked: false);
			}
		}

		private void GodModeStep()
		{
			try
			{
				Health health = Player.RigManager.health;
				if (!((Object)(object)health == (Object)null))
				{
					float num = ((R.Get(health, "max_Health") is float num2 && num2 > 1f) ? num2 : 100f);
					if (health.curr_Health < num)
					{
						health.curr_Health = num;
					}
				}
			}
			catch (Exception ex)
			{
				if (!godErrorLogged)
				{
					godErrorLogged = true;
					((MelonBase)this).LoggerInstance.Warning("god mode (first occurrence): " + ex.GetBaseException().Message);
				}
			}
		}

		private void ToggleGodMode()
		{
			godMode = !godMode;
			if (godMode)
			{
				GodModeStep();
			}
			menuMessage = "God mode " + (godMode ? "ON" : "OFF");
			((MelonBase)this).LoggerInstance.Msg(menuMessage);
		}

		private List<Component> FindBrains()
		{
			if (!aiBrainLooked)
			{
				aiBrainLooked = true;
				aiBrainType = FindType((Type t) => t.Name == "AIBrain" && (t.FullName ?? "").StartsWith("Il2Cpp"));
				if (aiBrainType == null)
				{
					((MelonBase)this).LoggerInstance.Warning("AIBrain type not found; NPC commands unavailable");
				}
			}
			if (aiBrainType == null)
			{
				return null;
			}
			List<Component> list = new List<Component>();
			Il2CppReferenceArray<Object> val = Object.FindObjectsOfType(Il2CppType.From(aiBrainType));
			if (val == null)
			{
				return list;
			}
			foreach (Object item in (Il2CppArrayBase<Object>)(object)val)
			{
				if (!(item == (Object)null))
				{
					Component val2 = ((Il2CppObjectBase)item).TryCast<Component>();
					if ((Object)(object)val2 != (Object)null)
					{
						list.Add(val2);
					}
				}
			}
			return list;
		}

		private void ClearAllNpcs()
		{
			try
			{
				List<Component> list = FindBrains();
				if (list == null)
				{
					menuMessage = "Clear NPCs failed: AIBrain type not found on this build.";
					return;
				}
				HashSet<int> hashSet = new HashSet<int>();
				int num = 0;
				int num2 = 0;
				foreach (Component item in list)
				{
					Poolee componentInParent = item.GetComponentInParent<Poolee>();
					if ((Object)(object)componentInParent == (Object)null)
					{
						num2++;
					}
					else if (hashSet.Add(((Object)componentInParent).GetInstanceID()))
					{
						try
						{
							componentInParent.Despawn();
							num++;
						}
						catch (Exception ex)
						{
							((MelonBase)this).LoggerInstance.Warning("clear npc: " + ex.GetBaseException().Message);
						}
					}
				}
				menuMessage = "Cleared " + num + " NPC(s)" + ((num2 > 0) ? (" (" + num2 + " not pooled, skipped)") : "");
				((MelonBase)this).LoggerInstance.Msg(menuMessage);
			}
			catch (Exception ex2)
			{
				menuMessage = "Clear NPCs failed: " + ex2.GetBaseException().Message;
				((MelonBase)this).LoggerInstance.Warning(menuMessage);
			}
		}

		private int ApplyNpcAi()
		{
			try
			{
				List<Component> list = FindBrains();
				if (list == null)
				{
					return -1;
				}
				int num = 0;
				foreach (Component item in list)
				{
					Behaviour val = ((Il2CppObjectBase)item).TryCast<Behaviour>();
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					int instanceID = ((Object)val).GetInstanceID();
					if (npcAiOff)
					{
						if (val.enabled)
						{
							val.enabled = false;
							aiDisabledByUs.Add(instanceID);
							num++;
						}
					}
					else if (aiDisabledByUs.Remove(instanceID))
					{
						val.enabled = true;
						num++;
					}
				}
				if (!npcAiOff)
				{
					aiDisabledByUs.Clear();
				}
				return num;
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("npc ai: " + ex.GetBaseException().Message);
				return 0;
			}
		}

		private void ToggleNpcAi()
		{
			npcAiOff = !npcAiOff;
			int num = ApplyNpcAi();
			if (num < 0)
			{
				npcAiOff = !npcAiOff;
				menuMessage = "NPC AI toggle failed: AIBrain type not found on this build.";
				return;
			}
			menuMessage = "NPC AI " + (npcAiOff ? "OFF" : "ON") + " (" + num + " NPC(s) changed)";
			((MelonBase)this).LoggerInstance.Msg(menuMessage);
		}

		private void DrawQuickCommands(float x, float y, float w, float bh, float gap, float scale, GUIStyle button, GUIStyle normal, GUIStyle sub)
		{
			//IL_000c: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			GUI.Label(new Rect(x, y, w, 30f * scale), "QUICK COMMANDS  -  sandbox testing", normal);
			y += 40f * scale;
			if (GUI.Button(new Rect(x, y, w, bh), "CLEAR ALL NPCS", button))
			{
				ClearAllNpcs();
			}
			y += bh + gap;
			if (GUI.Button(new Rect(x, y, w, bh), "NPC AI:  " + (npcAiOff ? "OFF (blind)  -  click to turn back on" : "ON  -  click to turn off / blind NPCs"), button))
			{
				ToggleNpcAi();
			}
			y += bh + gap;
			if (GUI.Button(new Rect(x, y, w, bh), "GOD MODE:  " + (godMode ? "ON" : "OFF"), button))
			{
				ToggleGodMode();
			}
			y += bh + gap;
			GUI.Label(new Rect(x, y, w, 60f * scale), "C opens / closes this page.  L toggles the flashlight in-game.", sub);
		}

		private void Bind<T>(string id, T def, Func<T> get, Action<T> set)
		{
			MelonPreferences_Entry<T> entry = cfg.CreateEntry<T>(id, def, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			cfgLoad.Add(delegate
			{
				set(entry.Value);
			});
			cfgSave.Add(delegate
			{
				entry.Value = get();
			});
		}

		private void InitConfig()
		{
			try
			{
				cfg = MelonPreferences.CreateCategory("TrueDesktopMod");
				Bind("LookSpeed", 6f, () => lookSpeed, delegate(float v)
				{
					lookSpeed = v;
				});
				Bind("Fov", 90f, () => fov, delegate(float v)
				{
					fov = v;
				});
				Bind("WalkSpeed", 16f, () => walkSpeed, delegate(float v)
				{
					walkSpeed = v;
				});
				Bind("SprintSpeed", 25f, () => sprintSpeed, delegate(float v)
				{
					sprintSpeed = v;
				});
				Bind("WeaponMode", def: true, () => gunFireMode, delegate(bool v)
				{
					gunFireMode = v;
				});
				Bind("NoclipSpeed", 6f, () => NoclipSpeed, delegate(float v)
				{
					NoclipSpeed = v;
				});
				Bind("NoclipFastSpeed", 18f, () => NoclipFastSpeed, delegate(float v)
				{
					NoclipFastSpeed = v;
				});
				Bind("FlashlightBrightness", 3.5f, () => FlashlightIntensity, delegate(float v)
				{
					FlashlightIntensity = v;
				});
				Bind("FlashlightRange", 45f, () => FlashlightRange, delegate(float v)
				{
					FlashlightRange = v;
				});
				Bind("ZoomFov", 50f, () => ZoomFov, delegate(float v)
				{
					ZoomFov = v;
				});
				Bind("PullRange", 8f, () => CallbackRange, delegate(float v)
				{
					CallbackRange = v;
				});
				Bind("MeleeSwingPower", 20f, () => SwingBoostSpeed, delegate(float v)
				{
					SwingBoostSpeed = v;
				});
				Bind("ThemeR", 1f, () => themeR, delegate(float v)
				{
					themeR = v;
				});
				Bind("ThemeG", 0.16f, () => themeG, delegate(float v)
				{
					themeG = v;
				});
				Bind("ThemeB", 0.16f, () => themeB, delegate(float v)
				{
					themeB = v;
				});
				Bind("ThemeTextColor", 0, () => themeTextMode, delegate(int v)
				{
					themeTextMode = v;
				});
				Bind("ThemeFont", "Default", () => themeFont, delegate(string v)
				{
					themeFont = v;
				});
				Bind("ThemeTextSize", 1f, () => themeFontScale, delegate(float v)
				{
					themeFontScale = v;
				});
				Bind("ThemeBold", def: true, () => themeBold, delegate(bool v)
				{
					themeBold = v;
				});
				Bind("ThemeScanlines", def: true, () => themeScanlines, delegate(bool v)
				{
					themeScanlines = v;
				});
				Bind("ThemeAnimation", def: true, () => themeAnimated, delegate(bool v)
				{
					themeAnimated = v;
				});
				Bind("ThemeBrackets", def: true, () => themeBrackets, delegate(bool v)
				{
					themeBrackets = v;
				});
				Bind("ThemeButtonStyle", 0, () => themeBtnStyle, delegate(int v)
				{
					themeBtnStyle = v;
				});
				Bind("ThemeOpacity", 0.96f, () => themeOpacity, delegate(float v)
				{
					themeOpacity = v;
				});
				foreach (Action item in cfgLoad)
				{
					item();
				}
				ClampConfig();
				((MelonBase)this).LoggerInstance.Msg("Config loaded");
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("config: " + ex.GetBaseException().Message);
			}
		}

		private void SaveConfig()
		{
			try
			{
				if (cfg == null)
				{
					menuMessage = "Save failed: config was not created.";
					return;
				}
				foreach (Action item in cfgSave)
				{
					item();
				}
				cfg.SaveToFile(false);
				menuMessage = "Saved to UserData/MelonPreferences.cfg";
				((MelonBase)this).LoggerInstance.Msg(menuMessage);
			}
			catch (Exception ex)
			{
				menuMessage = "Save failed: " + ex.GetBaseException().Message;
				((MelonBase)this).LoggerInstance.Warning(menuMessage);
			}
		}

		private void ClampConfig()
		{
			lookSpeed = Mathf.Clamp(lookSpeed, 1f, 15f);
			fov = Mathf.Clamp(fov, 60f, 120f);
			walkSpeed = Mathf.Clamp(walkSpeed, 4f, 40f);
			sprintSpeed = Mathf.Clamp(sprintSpeed, 4f, 60f);
			NoclipSpeed = Mathf.Clamp(NoclipSpeed, 1f, 30f);
			NoclipFastSpeed = Mathf.Clamp(NoclipFastSpeed, 3f, 60f);
			FlashlightIntensity = Mathf.Clamp(FlashlightIntensity, 0.5f, 12f);
			FlashlightRange = Mathf.Clamp(FlashlightRange, 10f, 150f);
			ZoomFov = Mathf.Clamp(ZoomFov, 20f, 75f);
			CallbackRange = Mathf.Clamp(CallbackRange, 2f, 25f);
			SwingBoostSpeed = Mathf.Clamp(SwingBoostSpeed, 0f, 60f);
			themeR = Mathf.Clamp01(themeR);
			themeG = Mathf.Clamp01(themeG);
			themeB = Mathf.Clamp01(themeB);
			themeTextMode = Mathf.Clamp(themeTextMode, 0, TextPresetNames.Length - 1);
			themeFontScale = Mathf.Clamp(themeFontScale, 0.8f, 1.4f);
			themeBtnStyle = Mathf.Clamp(themeBtnStyle, 0, BtnStyleNames.Length - 1);
			themeOpacity = Mathf.Clamp(themeOpacity, 0.5f, 1f);
			if (Array.IndexOf(FontChoices, themeFont) < 0)
			{
				themeFont = "Default";
			}
			curFov = fov;
			curMoveSpeed = walkSpeed;
		}

		private void ResetControls()
		{
			lookSpeed = 6f;
			fov = 90f;
			walkSpeed = 16f;
			sprintSpeed = 25f;
			gunFireMode = true;
			NoclipSpeed = 6f;
			NoclipFastSpeed = 18f;
			FlashlightIntensity = 3.5f;
			FlashlightRange = 45f;
			ZoomFov = 50f;
			CallbackRange = 8f;
			SwingBoostSpeed = 20f;
			menuMessage = "Defaults restored. Press SAVE SETTINGS to keep them.";
		}

		private void ResetTheme()
		{
			themeR = 1f;
			themeG = 0.16f;
			themeB = 0.16f;
			themeTextMode = 0;
			themeFont = "Default";
			themeFontScale = 1f;
			themeBold = true;
			themeScanlines = true;
			themeAnimated = true;
			themeBrackets = true;
			themeBtnStyle = 0;
			themeOpacity = 0.96f;
			menuMessage = "Theme reset to red sci-fi. Press SAVE SETTINGS to keep it.";
		}

		private void DrawSaveRow(float x, float y, float w, float scale, GUIStyle button, bool theme)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			float num = (w - 10f * scale) * 0.5f;
			if (GUI.Button(new Rect(x, y, num, 40f * scale), "SAVE SETTINGS", button))
			{
				SaveConfig();
			}
			if (GUI.Button(new Rect(x + num + 10f * scale, y, num, 40f * scale), theme ? "RESET THEME" : "RESET DEFAULTS", button))
			{
				if (theme)
				{
					ResetTheme();
				}
				else
				{
					ResetControls();
				}
			}
		}

		private float TuneRow(float x, float y, float w, float scale, GUIStyle normal, string label, float v, float min, float max, string fmt)
		{
			//IL_0012: 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)
			GUI.Label(new Rect(x, y, w * 0.46f, 28f * scale), label + v.ToString(fmt), normal);
			return MenuSlider(new Rect(x + w * 0.48f, y + 2f * scale, w * 0.52f, 24f * scale), v, min, max);
		}

		private float ChannelRow(float x, float y, float w, float scale, GUIStyle normal, string name, float v)
		{
			//IL_0012: 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)
			GUI.Label(new Rect(x, y, w * 0.3f, 28f * scale), name + ":  " + Mathf.RoundToInt(v * 255f), normal);
			return MenuSlider(new Rect(x + w * 0.32f, y + 2f * scale, w * 0.68f, 24f * scale), v, 0f, 1f);
		}

		private bool OnOff(Rect r, bool v, string label)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return GUI.Toggle(r, v, (v ? "[ ON ]  " : "[ OFF ]  ") + label, menuToggle);
		}

		private void DrawThemePage(float x, float y, float w, float scale, float bottom, GUIStyle button, GUIStyle normal, GUIStyle sub)
		{
			//IL_0027: 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_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: 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_0463: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b7: 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_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: 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_0197: Invalid comparison between Unknown and I4
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0573: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0607: Unknown result type (might be due to invalid IL or missing references)
			//IL_063a: 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)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: 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_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: 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_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: 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)
			float num = y - 46f * scale;
			if (GUI.Toggle(new Rect(x + 124f * scale, num, 150f * scale, 36f * scale), themeTab == 0, "COLOR", button) && themeTab != 0)
			{
				themeTab = 0;
			}
			if (GUI.Toggle(new Rect(x + 284f * scale, num, 190f * scale, 36f * scale), themeTab == 1, "FONT & STYLE", button) && themeTab != 1)
			{
				themeTab = 1;
			}
			float num2 = 10f * scale;
			if (themeTab == 0)
			{
				GUI.Label(new Rect(x, y, w, 24f * scale), "ACCENT COLOR  -  pick a preset or mix your own", normal);
				y += 30f * scale;
				float num3 = 8f * scale;
				float num4 = (w - num3 * (float)(AccentPresets.Length - 1)) / (float)AccentPresets.Length;
				Rect val = default(Rect);
				for (int i = 0; i < AccentPresets.Length; i++)
				{
					((Rect)(ref val))..ctor(x + (float)i * (num4 + num3), y, num4, 34f * scale);
					Color val2 = AccentPresets[i];
					bool flag = Mathf.Abs(val2.r - themeR) + Mathf.Abs(val2.g - themeG) + Mathf.Abs(val2.b - themeB) < 0.03f;
					if ((int)Event.current.type == 7)
					{
						Fill(val, Mul(val2, 0.9f));
						Frame(val, flag ? 3f : 1f, flag ? Color.white : Mul(val2, 0.45f));
					}
					if (GUI.Button(val, GUIContent.none, GUIStyle.none))
					{
						themeR = val2.r;
						themeG = val2.g;
						themeB = val2.b;
					}
				}
				y += 46f * scale;
				themeR = ChannelRow(x, y, w, scale, normal, "Red", themeR);
				y += 38f * scale;
				themeG = ChannelRow(x, y, w, scale, normal, "Green", themeG);
				y += 38f * scale;
				themeB = ChannelRow(x, y, w, scale, normal, "Blue", themeB);
				y += 46f * scale;
				GUI.Label(new Rect(x, y, w, 24f * scale), "TEXT COLOR", normal);
				y += 30f * scale;
				float num5 = (w - num2 * (float)(TextPresetNames.Length - 1)) / (float)TextPresetNames.Length;
				Rect val3 = default(Rect);
				for (int j = 0; j < TextPresetNames.Length; j++)
				{
					((Rect)(ref val3))..ctor(x + (float)j * (num5 + num2), y, num5, 38f * scale);
					if (GUI.Toggle(val3, themeTextMode == j, TextPresetNames[j], button) && themeTextMode != j)
					{
						themeTextMode = j;
					}
				}
				y += 48f * scale;
				GUI.Label(new Rect(x, y, w, 28f * scale), "Sample text  //  0123456789  //  ALERT", normal);
			}
			else
			{
				int num6 = Mathf.Max(0, Array.IndexOf(FontChoices, themeFont));
				GUI.Label(new Rect(x, y, w, 24f * scale), "FONT  -  any font installed on your PC works", normal);
				y += 30f * scale;
				if (GUI.Button(new Rect(x, y, 70f * scale, 38f * scale), "<", button))
				{
					themeFont = FontChoices[(num6 + FontChoices.Length - 1) % FontChoices.Length];
				}
				if (GUI.Button(new Rect(x + 80f * scale, y, w - 160f * scale, 38f * scale), FontChoices[num6].ToUpperInvariant(), button))
				{
					themeFont = FontChoices[(num6 + 1) % FontChoices.Length];
				}
				if (GUI.Button(new Rect(x + w - 70f * scale, y, 70f * scale, 38f * scale), ">", button))
				{
					themeFont = FontChoices[(num6 + 1) % FontChoices.Length];
				}
				y += 48f * scale;
				GUI.Label(new Rect(x, y, w, 30f * scale), "The quick brown fox jumps over 0123456789  //  ALERT", normal);
				y += 38f * scale;
				themeFontScale = TuneRow(x, y, w, scale, normal, "Text size: ", themeFontScale, 0.8f, 1.4f, "0.00");
				y += 42f * scale;
				float num7 = (w - 2f * num2) / 3f;
				themeBold = OnOff(new Rect(x, y, num7, 40f * scale), themeBold, "BOLD");
				themeScanlines = OnOff(new Rect(x + num7 + num2, y, num7, 40f * scale), themeScanlines, "SCANLINES");
				themeAnimated = OnOff(new Rect(x + 2f * (num7 + num2), y, num7, 40f * scale), themeAnimated, "ANIMATION");
				y += 50f * scale;
				themeBrackets = OnOff(new Rect(x, y, num7, 40f * scale), themeBrackets, "BRACKETS");
				if (GUI.Button(new Rect(x + num7 + num2, y, 2f * num7 + num2, 40f * scale), "BUTTON STYLE:  " + BtnStyleNames[Mathf.Clamp(themeBtnStyle, 0, BtnStyleNames.Length - 1)] + "   (click to change)", button))
				{
					themeBtnStyle = (themeBtnStyle + 1) % BtnStyleNames.Length;
				}
				y += 50f * scale;
				themeOpacity = TuneRow(x, y, w, scale, normal, "Panel opacity: ", themeOpacity, 0.5f, 1f, "0.00");
			}
			DrawSaveRow(x, bottom - 76f * scale, w, scale, button, theme: true);
		}

		private bool TrySwapAvatar(string barcode, string title)
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			try
			{
				if (string.IsNullOrWhiteSpace(barcode))
				{
					menuMessage = "This avatar entry has no barcode.";
					return false;
				}
				RigManager rigManager = Player.RigManager;
				if ((Object)(object)rigManager == (Object)null)
				{
					menuMessage = "Avatar swap failed: rig manager not ready.";
					return false;
				}
				MethodInfo[] methods = typeof(RigManager).GetMethods(BindingFlags.Instance | BindingFlags.Public);
				foreach (MethodInfo methodInfo in methods)
				{
					if (!(methodInfo.Name != "SwapAvatarCrate"))
					{
						ParameterInfo[] parameters = methodInfo.GetParameters();
						if (parameters.Length >= 2)
						{
							object[] array = new object[parameters.Length];
							array[0] = (object)new Barcode(barcode);
							array[1] = true;
							methodInfo.Invoke(rigManager, array);
							menuMessage = "Swapping avatar: " + title;
							((MelonBase)this).LoggerInstance.Msg(menuMessage + " [" + barcode + "]");
							menuOpen = false;
							spawnOpen = false;
							LockCursor(locked: true);
							return true;
						}
					}
				}
				menuMessage = "Avatar swap failed: RigManager.SwapAvatarCrate not found.";
				((MelonBase)this).LoggerInstance.Error(menuMessage);
				return false;
			}
			catch (Exception ex)
			{
				menuMessage = "Avatar swap failed for " + title + ": " + ex.GetBaseException().Message;
				((MelonBase)this).LoggerInstance.Error(menuMessage);
				return false;
			}
		}

		private void SelectWheel(int index)
		{
			if (index >= 0 && index < 4)
			{
				Hotbar(index);
			}
			menuOpen = false;
			LockCursor(locked: true);
		}

		private void ApplySwing(ref Vector3 local, ref Quaternion rot)
		{
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: 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)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			float num = (Time.time - swingStart) / 0.18f;
			if (!(num < 0f) && !(num >= 1f))
			{
				float num3;
				float num4;
				float num5;
				float num6;
				if (num < 0.2f)
				{
					float num2 = num / 0.2f;
					num3 = Mathf.Lerp(0f, -80f, num2);
					num4 = Mathf.Lerp(0f, 35f, num2);
					num5 = 0.18f * num2;
					num6 = -0.08f * num2;
				}
				else
				{
					float num7 = (num - 0.2f) / 0.8f;
					float num8 = num7 * num7 * (3f - 2f * num7);
					num3 = Mathf.Lerp(-80f, 95f, num8);
					num4 = Mathf.Lerp(35f, -45f, num8);
					num5 = Mathf.Lerp(0.18f, -0.15f, num8);
					num6 = Mathf.Sin(num7 * (float)Math.PI) * 0.55f;
				}
				local += new Vector3(0f, num5, num6);
				rot = Quaternion.Euler(num3, num4, 0f) * rot;
			}
		}

		private void MeleeBoost()
		{
			//IL_0087: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00ac: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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_010d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)cam == (Object)null || meleeHandCache < 0)
			{
				return;
			}
			float num = (Time.time - swingStart) / 0.18f;
			if (num < 0.2f || num >= 1f)
			{
				return;
			}
			GameObject val = heldCache[meleeHandCache];
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Transform transform = ((Component)cam).transform;
			Vector3 val2 = transform.forward - transform.right * 0.5f - transform.up * 0.3f;
			Vector3 velocity = ((Vector3)(ref val2)).normalized * SwingBoostSpeed;
			foreach (Rigidbody componentsInChild in ((Component)val.transform.root).GetComponentsInChildren<Rigidbody>())
			{
				if ((Object)(object)componentsInChild != (Object)null && !componentsInChild.isKinematic)
				{
					componentsInChild.velocity = velocity;
				}
			}
		}

		private bool IsInteractable(Rigidbody rb)
		{
			if (!interactableHostLooked)
			{
				interactableHostLooked = true;
				interactableHostType = FindType((Type t) => t.Name == "InteractableHost" && (t.FullName ?? "").StartsWith("Il2Cpp"));
			}
			if (interactableHostType == null)
			{
				return rb.mass <= 30f;
			}
			try
			{
				return (Object)(object)((Component)rb).GetComponentInParent(Il2CppType.From(interactableHostType)) != (Object)null;
			}
			catch
			{
				return rb.mass <= 30f;
			}
		}

		private void CallbackStep(int i)
		{
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)cam == (Object)null || !grip[i] || (Object)(object)heldCache[i] != (Object)null || Time.time < nextRegrip[i])
			{
				return;
			}
			Transform transform = ((Component)cam).transform;
			Transform val = null;
			try
			{
				PhysicsRig physicsRig = Player.PhysicsRig;
				if ((Object)(object)physicsRig != (Object)null)
				{
					val = ((Component)physicsRig).transform.root;
				}
			}
			catch
			{
			}
			Transform val2 = (((Object)(object)heldCache[0] != (Object)null) ? heldCache[0].transform.root : null);
			Transform val3 = (((Object)(object)heldCache[1] != (Object)null) ? heldCache[1].transform.root : null);
			int num = Physics.SphereCastNonAlloc(transform.position, 0.3f, transform.forward, Il2CppStructArray<RaycastHit>.op_Implicit(rayBuf), CallbackRange, -1, (QueryTriggerInteraction)1);
			Rigidbody val4 = null;
			float num2 = float.MaxValue;
			for (int j = 0; j < num; j++)
			{
				Collider collider = ((RaycastHit)(ref rayBuf[j])).collider;
				if ((Object)(object)collider == (Object)null)
				{
					continue;
				}
				Rigidbody attachedRigidbody = collider.attachedRigidbody;
				if (!((Object)(object)attachedRigidbody == (Object)null) && !attachedRigidbody.isKinematic && !(attachedRigidbody.mass > 30f))
				{
					Transform root = ((Component)attachedRigidbody).transform.root;
					if (!((Object)(object)root == (Object)(object)transform.root) && (!((Object)(object)val != (Object)null) || !((Object)(object)root == (Object)(object)val)) && (!((Object)(object)val2 != (Object)null) || !((Object)(object)root == (Object)(object)val2)) && (!((Object)(object)val3 != (Object)null) || !((Object)(object)root == (Object)(object)val3)) && !(((RaycastHit)(ref rayBuf[j])).distance >= num2) && IsInteractable(attachedRigidbody))
					{
						num2 = ((RaycastHit)(ref rayBuf[j])).distance;
						val4 = attachedRigidbody;
					}
				}
			}
			if ((Object)(object)val4 == (Object)null)
			{
				return;
			}
			Vector3 val5 = ((Component)HandOf(i)).transform.position - val4.worldCenterOfMass;
			float magnitude = ((Vector3)(ref val5)).magnitude;
			armsAtSide = false;
			if (magnitude < 0.5f)
			{
				regripFrames[i] = 3;
				nextRegrip[i] = Time.time + 0.6f;
				return;
			}
			Vector3 velocity = val5 / magnitude * Mathf.Clamp(magnitude * 8f, 4f, 16f);
			foreach (Rigidbody componentsInChild in ((Component)((Component)val4).transform.root).GetComponentsInChildren<Rigidbody>())
			{
				if ((Object)(object)componentsInChild != (Object)null && !componentsInChild.isKinematic)
				{
					componentsInChild.velocity = velocity;
				}
			}
		}

		private void ReloadNow()
		{
			Gun componentInHand = Player.GetComponentInHand<Gun>(Player.RightHand);
			if ((Object)(object)componentInHand == (Object)null)
			{
				componentInHand = Player.GetComponentInHand<Gun>(Player.LeftHand);
			}
			if ((Object)(object)componentInHand == (Object)null)
			{
				return;
			}
			try
			{
				nextReload = Time.time + 0.75f;
				R.TryCall(componentInHand, "InstantLoadAsync", out var _);
				componentInHand.CompleteSlidePull();
				componentInHand.CompleteSlideReturn();
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("reload: " + ex.Message);
			}
		}

		private void AutoReload()
		{
			if (Time.time < nextReload || Time.time < nextReloadCheck)
			{
				return;
			}
			nextReloadCheck = Time.time + 0.25f;
			Gun componentInHand = Player.GetComponentInHand<Gun>(Player.RightHand);
			if ((Object)(object)componentInHand == (Object)null)
			{
				componentInHand = Player.GetComponentInHand<Gun>(Player.LeftHand);
			}
			if ((Object)(object)componentInHand == (Object)null)
			{
				return;
			}
			try
			{
				if (!componentInHand.HasMagazine())
				{
					nextReload = Time.time + 0.75f;
					R.TryCall(componentInHand, "InstantLoadAsync", out var _);
					componentInHand.CompleteSlidePull();
					componentInHand.CompleteSlideReturn();
				}
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Warning("autoreload: " + ex.Message);
			}
		}

		private void ToggleMenu()
		{
			menuOpen = !menuOpen;
			spawnOpen = false;
			if (menuOpen)
			{
				menuPage = 0;
				menuMessage = "";
			}
			LockCursor(!menuOpen);
		}

		private GameObject HeldSpawnGun()
		{
			for (int i = 0; i < 2; i++)
			{
				GameObject val = HeldObject(HandOf(i));
				if (!((Object)(object)val == (Object)null))
				{
					string text = ((Object)val.transform.root).name.ToLowerInvariant();
					if (text.Contains("spawngun") || text.Contains("spawn gun") || text.Contains("spawner"))
					{
						return ((Component)val.transform.root).gameObject;
					}
				}
			}
			return null;
		}

		private void ToggleSpawnMenu()
		{
			if (menuOpen && menuPage == 4)
			{
				menuOpen = false;
				spawnOpen = false;
				LockCursor(locked: true);
				return;
			}
			menuOpen = true;
			spawnOpen = false;
			menuPage = 4;
			menuMessage = "Scanning installed crates...";
			catalogScanned = false;
			EnsureCatalog();
			focusSpawnSearch = true;
			LockCursor(locked: false);
		}

		private int Ammo(string group)
		{
			try
			{
				return AmmoInventory.Instance._groupCounts[group];
			}
			catch
			{
				return 0;
			}
		}

		private void Box(Rect r)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_0071: 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_00c7: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)whiteTex == (Object)null)
			{
				whiteTex = new Texture2D(1, 1);
				whiteTex.SetPixel(0, 0, Color.white);
				whiteTex.Apply();
			}
			Color color = GUI.color;
			GUI.color = HudBack;
			GUI.DrawTexture(r, (Texture)(object)whiteTex);
			GUI.color = new Color(1f, 0.82f, 0f, 0.25f);
			GUI.DrawTexture(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r)).width, 1f), (Texture)(object)whiteTex);
			GUI.DrawTexture(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).yMax - 1f, ((Rect)(ref r)).width, 1f), (Texture)(object)whiteTex);
			GUI.DrawTexture(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, 1f, ((Rect)(ref r)).height), (Texture)(object)whiteTex);
			GUI.DrawTexture(new Rect(((Rect)(ref r)).xMax - 1f, ((Rect)(ref r)).y, 1f, ((Rect)(ref r)).height), (Texture)(object)whiteTex);
			GUI.color = color;
		}

		private void Text(Rect r, string text, GUIStyle style, Color c, TextAnchor anchor)
		{
			//IL_0002: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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)
			style.alignment = anchor;
			style.normal.textColor = new Color(0f, 0f, 0f, 0.6f);
			GUI.Label(new Rect(((Rect)(ref r)).x + 1f, ((Rect)(ref r)).y + 1f, ((Rect)(ref r)).width, ((Rect)(ref r)).height), text, style);
			style.normal.textColor = c;
			GUI.Label(r, text, style);
		}

		private void BuildStyles()
		{
			//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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			labelStyle = new GUIStyle(GUI.skin.label)
			{
				fontStyle = (FontStyle)1,
				wordWrap = false
			};
			bigStyle = new GUIStyle(GUI.skin.label)
			{
				fontStyle = (FontStyle)1,
				wordWrap = false
			};
			smallStyle = new GUIStyle(GUI.skin.label)
			{
				fontStyle = (FontStyle)1,
				wordWrap = false
			};
			menuStyleScale = -1f;
		}

		private Texture2D MakeBoxTex(Color fill, Color border)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_0036: 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)
			Texture2D val = new Texture2D(8, 8);
			((Texture)val).filterMode = (FilterMode)0;
			((Object)val).hideFlags = (HideFlags)61;
			for (int i = 0; i < 8; i++)
			{
				for (int j = 0; j < 8; j++)
				{
					val.SetPixel(j, i, (j == 0 || i == 0 || j == 7 || i == 7) ? border : fill);
				}
			}
			val.Apply();
			return val;
		}

		private void SetStates(GUIStyle st, Texture2D normalTex, Texture2D hoverTex, Texture2D activeTex, Texture2D onTex, Color text)
		{
			//IL_0074: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			st.normal.background = normalTex;
			st.focused.background = normalTex;
			st.hover.background = hoverTex;
			st.active.background = activeTex;
			st.onNormal.background = onTex;
			st.onFocused.background = onTex;
			st.onHover.background = onTex;
			st.onActive.background = activeTex;
			st.normal.textColor = text;
			st.focused.textColor = text;
			st.hover.textColor = Color.white;
			st.active.textColor = Color.white;
			st.onNormal.textColor = Color.white;
			st.onFocused.textColor = Color.white;
			st.onHover.textColor = Color.white;
			st.onActive.textColor = Color.white;
		}

		private static Color Mul(Color c, float k, float alpha = 1f)
		{
			//IL_0001: 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_001b: 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)
			return new Color(Mathf.Clamp01(c.r * k), Mathf.Clamp01(c.g * k), Mathf.Clamp01(c.b * k), alpha);
		}

		private string ThemeSignature()
		{
			return themeR.ToString("F3") + "|" + themeG.ToString("F3") + "|" + themeB.ToString("F3") + "|" + themeTextMode + "|" + themeFont + "|" + themeFontScale.ToString("F2") + "|" + themeBold + "|" + themeBtnStyle + "|" + themeOpacity.ToString("F2");
		}

		private void ApplyTheme()
		{
			//IL_002e: 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_003a: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to in