Decompiled source of Freecam v1.0.1

Mods/Freecam.dll

Decompiled 7 months ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Freecam;
using Freecam.Configuration;
using Freecam.HarmonyPatches;
using Freecam.IMGUI;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using SLZ.Bonelab;
using SLZ.Marrow.Input;
using SLZ.Rig;
using SLZ.SaveData;
using Unity.XR.MockHMD;
using UnityEngine;
using UnityEngine.XR.Management;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Freecam")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany(null)]
[assembly: AssemblyProduct("Freecam")]
[assembly: AssemblyCopyright("Copyright (c) 2023 Frederick (Millzy) Mills")]
[assembly: AssemblyTrademark(null)]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: NeutralResourcesLanguage("en")]
[assembly: MelonInfo(typeof(Mod), "Freecam", "1.0.1", "Millzy", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonID("dev.millzy.Freecam")]
[assembly: VerifyLoaderVersion("0.5.7")]
[assembly: HarmonyDontPatchAll]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.1.40822")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 Freecam
{
	[RegisterTypeInIl2Cpp]
	internal sealed class FreecamController : MonoBehaviour
	{
		private Vector3 _lastMousePosition = Vector3.zero;

		[NonSerialized]
		public float Speed;

		[NonSerialized]
		public float FastMultiplier;

		[NonSerialized]
		public float CameraSensitivity;

		public FreecamController(IntPtr ptr)
			: base(ptr)
		{
		}//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)


		private void Awake()
		{
			Config instance = Config.Instance;
			Speed = instance.Speed;
			FastMultiplier = instance.FastMultiplier;
			CameraSensitivity = instance.CameraSensitivity;
		}

		private void Update()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: 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_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: 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_017d: Unknown result type (might be due to invalid IL or missing references)
			float num = Speed * Time.deltaTime;
			float fastMultiplier = FastMultiplier;
			float cameraSensitivity = CameraSensitivity;
			if (Input.GetKey((KeyCode)304))
			{
				num *= fastMultiplier;
			}
			Transform transform = ((Component)this).transform;
			if (Input.GetKey((KeyCode)119))
			{
				transform.position += transform.forward * num;
			}
			if (Input.GetKey((KeyCode)97))
			{
				transform.position += transform.right * (-1f * num);
			}
			if (Input.GetKey((KeyCode)115))
			{
				transform.position += transform.forward * (-1f * num);
			}
			if (Input.GetKey((KeyCode)100))
			{
				transform.position += transform.right * num;
			}
			if (Input.GetKey((KeyCode)32))
			{
				transform.position += transform.up * num;
			}
			if (Input.GetKey((KeyCode)306))
			{
				transform.position += transform.up * (-1f * num);
			}
			if (Input.GetMouseButton(1))
			{
				Vector3 val = Input.mousePosition - _lastMousePosition;
				Vector3 localEulerAngles = ((Component)this).transform.localEulerAngles;
				float num2 = localEulerAngles.y + val.x * cameraSensitivity;
				float num3 = localEulerAngles.x - val.y * cameraSensitivity;
				transform.localEulerAngles = new Vector3(num3, num2, 0f);
			}
			_lastMousePosition = Input.mousePosition;
		}
	}
	[RegisterTypeInIl2Cpp]
	internal sealed class FreecamHostManager : MonoBehaviour
	{
		private Config _config;

		private GameObject _freecamObject;

		private RigManager _rigManager;

		private FreecamMenu _menu;

		public FreecamHostManager(IntPtr ptr)
			: base(ptr)
		{
		}

		public static void CreateFreecam(RigManager rigManager)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("FreecamHost");
			val.AddComponent<FreecamHostManager>()._rigManager = rigManager;
			Transform transform = val.transform;
			transform.position = ((Rig)rigManager.ControllerRig).m_head.position;
			GameObject val2 = new GameObject("Freecam");
			val2.transform.SetParent(transform, false);
			val2.transform.localPosition = new Vector3(0f, 0f, 0f);
			val2.AddComponent<Camera>().cameraType = (CameraType)2;
			val2.AddComponent<FreecamController>();
			Config instance = Config.Instance;
			((Behaviour)val.AddComponent<FreecamMenu>()).enabled = instance.ShowConfigMenu;
		}

		private void Awake()
		{
			_config = Config.Instance;
		}

		private void Start()
		{
			_freecamObject = ((Component)((Component)this).GetComponentInChildren<FreecamController>()).gameObject;
			_menu = ((Component)this).GetComponent<FreecamMenu>();
		}

		private void Update()
		{
			if (Input.GetKeyDown((KeyCode)102))
			{
				ToggleFreecam();
			}
			if (Input.GetKeyDown((KeyCode)282))
			{
				ToggleMenu();
			}
		}

		public void ToggleFreecam()
		{
			bool flag = !_config.FreecamEnabled;
			_freecamObject.SetActive(flag);
			_config.FreecamEnabled = flag;
			Control_Player controlPlayer = _rigManager.uiRig.controlPlayer;
			DataManager.Settings._spectatorSettings._spectatorCameraMode = (SpectatorCameraMode)0;
			controlPlayer.UpdateSpectator();
		}

		private void ToggleMenu()
		{
			bool flag = !_config.ShowConfigMenu;
			((Behaviour)_menu).enabled = flag;
			_config.ShowConfigMenu = flag;
		}
	}
	public sealed class Mod : MelonMod
	{
		private static void SwapXRLoader()
		{
			List<XRLoader> loaders = XRGeneralSettings.Instance.Manager.loaders;
			MockHMDLoader val = ScriptableObject.CreateInstance<MockHMDLoader>();
			((Object)val).name = "Freecam Override";
			loaders.Clear();
			loaders.Add((XRLoader)(object)val);
		}

		public override void OnInitializeMelon()
		{
			PatchManager.Instance.InstallFreecamPatches();
			if (Config.Instance.NoHmd)
			{
				SwapXRLoader();
			}
		}

		public override void OnApplicationQuit()
		{
			PatchManager.Instance.UninstallFreecamPatches();
			Config.Instance.Save();
		}
	}
	internal sealed class PatchManager
	{
		private static readonly Lazy<PatchManager> s_lazy = new Lazy<PatchManager>(() => new PatchManager());

		private readonly Harmony _harmony;

		public static PatchManager Instance => s_lazy.Value;

		private PatchManager()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			_harmony = new Harmony("dev.millzy.Freecam");
		}

		public void InstallFreecamPatches()
		{
			_harmony.PatchAll();
			PatchXRApi();
		}

		public void UninstallFreecamPatches()
		{
			_harmony.UnpatchSelf();
		}

		private void PatchXRApi()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			Type typeFromHandle = typeof(XRApi);
			Type nestedType = typeFromHandle.GetNestedType("__c__DisplayClass50_0");
			MethodInfo method;
			if (nestedType == null)
			{
				nestedType = typeFromHandle.GetNestedType("__c");
				method = nestedType.GetMethod("_Initialize_b__45_0");
			}
			else
			{
				method = nestedType.GetMethod("_InitializeXRLoader_b__0");
			}
			MethodInfo method2 = typeof(XRApi_InitializeXRLoader).GetMethod("Prefix", BindingFlags.Static | BindingFlags.Public);
			_harmony.Patch((MethodBase)method, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
	}
	internal static class BuildInfo
	{
		public const string Name = "Freecam";

		public const string Author = "Millzy";

		public const string Version = "1.0.1";

		public const string Description = "A desktop freecam for BONELAB.";

		public const string Id = "dev.millzy.Freecam";
	}
}
namespace Freecam.IMGUI
{
	[RegisterTypeInIl2Cpp]
	internal sealed class CameraSettingsMenu : MonoBehaviour, INotifyPropertyChanged
	{
		private string _fieldOfViewString = string.Empty;

		private float _fieldOfViewValue;

		private string _nearClipString = string.Empty;

		private float _nearClipValue;

		public float FieldOfView
		{
			get
			{
				return _fieldOfViewValue;
			}
			set
			{
				SetField(ref _fieldOfViewValue, value, dontFire: false, "FieldOfView");
				_fieldOfViewString = value.ToString("F");
			}
		}

		public float NearClip
		{
			get
			{
				return _nearClipValue;
			}
			set
			{
				SetField(ref _nearClipValue, value, dontFire: false, "NearClip");
				_nearClipString = value.ToString("F");
			}
		}

		private string FieldOfViewString
		{
			set
			{
				if (SetField(ref _fieldOfViewString, value, dontFire: true, "FieldOfViewString") && float.TryParse(value, out var result))
				{
					FieldOfView = result;
				}
			}
		}

		private string NearClipString
		{
			set
			{
				if (SetField(ref _nearClipString, value, dontFire: true, "NearClipString") && float.TryParse(value, out var result))
				{
					NearClip = result;
				}
			}
		}

		public event PropertyChangedEventHandler? PropertyChanged;

		public CameraSettingsMenu(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Awake()
		{
			Config instance = Config.Instance;
			_fieldOfViewValue = instance.FieldOfView;
			_nearClipValue = instance.NearClip;
		}

		private void OnGUI()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			GUI.Box(new Rect(215f, 40f, 200f, 300f), "Camera");
			GUI.Label(new Rect(220f, 60f, 190f, 20f), "Field of View:");
			FieldOfViewString = GUI.TextField(new Rect(350f, 60f, 50f, 20f), _fieldOfViewString);
			FieldOfView = GUI.HorizontalSlider(new Rect(220f, 85f, 190f, 20f), _fieldOfViewValue, 60f, 120f);
			GUI.Label(new Rect(220f, 125f, 190f, 20f), "Near Clip Distance:");
			NearClipString = GUI.TextField(new Rect(350f, 125f, 50f, 20f), _nearClipString);
			NearClip = GUI.HorizontalSlider(new Rect(220f, 150f, 190f, 20f), _nearClipValue, 0.01f, 0.5f);
		}

		private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
		{
			this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
		}

		private bool SetField<T>(ref T field, T value, bool dontFire = false, [CallerMemberName] string? propertyName = null)
		{
			if (EqualityComparer<T>.Default.Equals(field, value))
			{
				return false;
			}
			field = value;
			if (!dontFire)
			{
				OnPropertyChanged(propertyName);
			}
			return true;
		}
	}
	[RegisterTypeInIl2Cpp]
	public class FreecamMenu : MonoBehaviour
	{
		private Config _config;

		private Camera _camera;

		private FreecamController _freecamController;

		private GeneralSettingsMenu _generalSettingsMenu;

		private CameraSettingsMenu _cameraSettingsMenu;

		private LayerSettingsMenu _layerSettingsMenu;

		public FreecamMenu(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Awake()
		{
			_config = Config.Instance;
			_freecamController = ((Component)this).GetComponentInChildren<FreecamController>();
			_generalSettingsMenu = ((Component)this).gameObject.AddComponent<GeneralSettingsMenu>();
			_cameraSettingsMenu = ((Component)this).gameObject.AddComponent<CameraSettingsMenu>();
			_layerSettingsMenu = ((Component)this).gameObject.AddComponent<LayerSettingsMenu>();
			_generalSettingsMenu.PropertyChanged += PropertyChanged;
			_cameraSettingsMenu.PropertyChanged += PropertyChanged;
			_layerSettingsMenu.PropertyChanged += PropertyChanged;
		}

		private void Start()
		{
			_camera = ((Component)this).GetComponentInChildren<Camera>();
		}

		private void OnGUI()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			GUI.Box(new Rect(10f, 10f, 610f, 25f), "Freecam Menu (F1 to Show/Hide)");
		}

		private void OnEnable()
		{
			((Behaviour)_generalSettingsMenu).enabled = true;
			((Behaviour)_cameraSettingsMenu).enabled = true;
			((Behaviour)_layerSettingsMenu).enabled = true;
		}

		private void OnDisable()
		{
			SaveValues();
			((Behaviour)_generalSettingsMenu).enabled = false;
			((Behaviour)_cameraSettingsMenu).enabled = false;
			((Behaviour)_layerSettingsMenu).enabled = false;
		}

		private void PropertyChanged(object sender, PropertyChangedEventArgs args)
		{
			ApplyValues();
		}

		private void ApplyValues()
		{
			_freecamController.Speed = _generalSettingsMenu.Speed;
			_freecamController.FastMultiplier = _generalSettingsMenu.FastMultiplier;
			_freecamController.CameraSensitivity = _generalSettingsMenu.CameraSensitivity;
			_camera.fieldOfView = _cameraSettingsMenu.FieldOfView;
			_camera.nearClipPlane = _cameraSettingsMenu.NearClip;
			_camera.cullingMask = _layerSettingsMenu.CullingMask;
		}

		private void SaveValues()
		{
			_config.NoHmd = _generalSettingsMenu.NoHmd;
			_config.Speed = _generalSettingsMenu.Speed;
			_config.FastMultiplier = _generalSettingsMenu.FastMultiplier;
			_config.CameraSensitivity = _generalSettingsMenu.CameraSensitivity;
			_config.FieldOfView = _cameraSettingsMenu.FieldOfView;
			_config.NearClip = _cameraSettingsMenu.NearClip;
			_config.CullingMask = _layerSettingsMenu.CullingMask;
		}
	}
	[RegisterTypeInIl2Cpp]
	internal sealed class GeneralSettingsMenu : MonoBehaviour, INotifyPropertyChanged
	{
		private Config _config;

		private string _fastMultiplierString = string.Empty;

		private float _fastMultiplierValue;

		private string _cameraSensitivityString = string.Empty;

		private float _cameraSensitivityValue;

		private FreecamHostManager _freecamHostManager;

		private LayerSettingsMenu _layerSettingsMenu;

		private bool _noHmdToggle;

		private string _speedString = string.Empty;

		private float _speedValue;

		public bool NoHmd
		{
			get
			{
				return _noHmdToggle;
			}
			set
			{
				SetField(ref _noHmdToggle, value, dontFire: false, "NoHmd");
			}
		}

		public float Speed
		{
			get
			{
				return _speedValue;
			}
			set
			{
				SetField(ref _speedValue, value, dontFire: false, "Speed");
				_speedString = value.ToString("F");
			}
		}

		public float FastMultiplier
		{
			get
			{
				return _fastMultiplierValue;
			}
			set
			{
				SetField(ref _fastMultiplierValue, value, dontFire: false, "FastMultiplier");
				_fastMultiplierString = value.ToString("F");
			}
		}

		public float CameraSensitivity
		{
			get
			{
				return _cameraSensitivityValue;
			}
			set
			{
				SetField(ref _cameraSensitivityValue, value, dontFire: false, "CameraSensitivity");
				_cameraSensitivityString = value.ToString("F");
			}
		}

		private string SpeedString
		{
			set
			{
				if (SetField(ref _speedString, value, dontFire: true, "SpeedString") && float.TryParse(value, out var result))
				{
					Speed = result;
				}
			}
		}

		private string FastMultiplierString
		{
			set
			{
				if (SetField(ref _fastMultiplierString, value, dontFire: true, "FastMultiplierString") && float.TryParse(value, out var result))
				{
					FastMultiplier = result;
				}
			}
		}

		private string CameraSensitivityString
		{
			set
			{
				if (SetField(ref _cameraSensitivityString, value, dontFire: true, "CameraSensitivityString") && float.TryParse(value, out var result))
				{
					CameraSensitivity = result;
				}
			}
		}

		public event PropertyChangedEventHandler? PropertyChanged;

		public GeneralSettingsMenu(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Awake()
		{
			_config = Config.Instance;
			_noHmdToggle = _config.NoHmd;
			_speedValue = _config.Speed;
			_fastMultiplierValue = _config.FastMultiplier;
			_cameraSensitivityValue = _config.CameraSensitivity;
		}

		private void Start()
		{
			_freecamHostManager = ((Component)this).GetComponent<FreecamHostManager>();
			_layerSettingsMenu = ((Component)this).GetComponent<LayerSettingsMenu>();
		}

		private void OnGUI()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: 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_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			GUI.Box(new Rect(10f, 40f, 200f, 300f), "General");
			bool freecamEnabled = _config.FreecamEnabled;
			if (GUI.Button(new Rect(15f, 60f, 190f, 20f), freecamEnabled ? "Disable Freecam (F)" : "Enable Freecam (F)"))
			{
				_freecamHostManager.ToggleFreecam();
			}
			NoHmd = GUI.Toggle(new Rect(15f, 85f, 190f, 20f), _noHmdToggle, "No HMD Mode");
			GUI.Label(new Rect(15f, 110f, 190f, 20f), "Speed:");
			SpeedString = GUI.TextField(new Rect(150f, 110f, 60f, 20f), _speedString);
			Speed = GUI.HorizontalSlider(new Rect(15f, 130f, 190f, 20f), _speedValue, 0.1f, 40f);
			GUI.Label(new Rect(15f, 155f, 190f, 20f), "Fast Multiplier:");
			FastMultiplierString = GUI.TextField(new Rect(150f, 155f, 60f, 20f), _fastMultiplierString);
			FastMultiplier = GUI.HorizontalSlider(new Rect(15f, 180f, 190f, 20f), _fastMultiplierValue, 1.5f, 20f);
			GUI.Label(new Rect(15f, 200f, 190f, 20f), "Camera Sensitivity");
			CameraSensitivityString = GUI.TextField(new Rect(150f, 200f, 60f, 20f), _cameraSensitivityString);
			CameraSensitivity = GUI.HorizontalSlider(new Rect(15f, 225f, 190f, 20f), _cameraSensitivityValue, 0.01f, 1f);
			if (GUI.Button(new Rect(15f, 250f, 190f, 20f), "Show All Layers"))
			{
				_layerSettingsMenu.CullingMask = -1;
			}
			if (GUI.Button(new Rect(15f, 275f, 190f, 20f), "Hide All Layers"))
			{
				_layerSettingsMenu.CullingMask = 0;
			}
		}

		private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
		{
			this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
		}

		private bool SetField<T>(ref T field, T value, bool dontFire = false, [CallerMemberName] string? propertyName = null)
		{
			if (EqualityComparer<T>.Default.Equals(field, value))
			{
				return false;
			}
			field = value;
			if (!dontFire)
			{
				OnPropertyChanged(propertyName);
			}
			return true;
		}
	}
	[RegisterTypeInIl2Cpp]
	internal sealed class LayerSettingsMenu : MonoBehaviour, INotifyPropertyChanged
	{
		private int _cullingMask;

		private string[] _layerNames;

		public int CullingMask
		{
			get
			{
				return _cullingMask;
			}
			set
			{
				SetField(ref _cullingMask, value, "CullingMask");
			}
		}

		public event PropertyChangedEventHandler? PropertyChanged;

		public LayerSettingsMenu(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Awake()
		{
			Config instance = Config.Instance;
			_cullingMask = instance.CullingMask;
			List<string> list = new List<string>();
			for (int i = 0; i < 32; i++)
			{
				string text = LayerMask.LayerToName(i);
				if (text == string.Empty)
				{
					text = "Layer " + i;
				}
				list.Add(text);
			}
			_layerNames = list.ToArray();
		}

		private void OnGUI()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			GUI.Box(new Rect(420f, 40f, 200f, 825f), "Layers");
			for (int i = 0; i < 32; i++)
			{
				int num = 1 << i;
				if (GUI.Toggle(new Rect(425f, 65f + 25f * (float)i, 180f, 20f), (_cullingMask & num) == num, _layerNames[i]))
				{
					CullingMask |= num;
				}
				else
				{
					CullingMask &= ~num;
				}
			}
		}

		private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
		{
			this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
		}

		private bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
		{
			if (EqualityComparer<T>.Default.Equals(field, value))
			{
				return false;
			}
			field = value;
			OnPropertyChanged(propertyName);
			return true;
		}
	}
}
namespace Freecam.HarmonyPatches
{
	[HarmonyPatch(typeof(OpenControllerRig))]
	[HarmonyPatch("OnStart")]
	internal static class OpenControllerRig_OnStart
	{
		[HarmonyPostfix]
		private static bool Prefix(OpenControllerRig __instance)
		{
			if (!Config.Instance.NoHmd)
			{
				return true;
			}
			__instance._isControllerRigPaused = true;
			return true;
		}
	}
	[HarmonyPatch(typeof(RigManager))]
	[HarmonyPatch("Start")]
	internal static class RigManager_Start
	{
		private static readonly Config s_config = Config.Instance;

		[HarmonyPostfix]
		private static void Postfix(RigManager __instance)
		{
			if (s_config.FreecamEnabled)
			{
				Control_Player controlPlayer = __instance.uiRig.controlPlayer;
				DataManager.Settings._spectatorSettings._spectatorCameraMode = (SpectatorCameraMode)0;
				controlPlayer.UpdateSpectator();
			}
			FreecamHostManager.CreateFreecam(__instance);
		}
	}
	internal static class XRApi_InitializeXRLoader
	{
		private static readonly Config s_config = Config.Instance;

		public static bool Prefix(ref bool __result)
		{
			if (!s_config.NoHmd)
			{
				return true;
			}
			__result = true;
			return false;
		}
	}
	[HarmonyPatch(typeof(XRHMD))]
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal static class XRHMD_get_IsUserPresent
	{
		private static readonly Config s_config = Config.Instance;

		[HarmonyPrefix]
		private static bool Prefix(ref bool __result)
		{
			__result = true;
			return false;
		}
	}
}
namespace Freecam.Configuration
{
	internal sealed class Config
	{
		private static readonly Lazy<Config> s_lazy = new Lazy<Config>(() => new Config());

		private readonly MelonPreferences_Category _config;

		private readonly MelonPreferences_Entry<bool> _freecamEnabled;

		private readonly MelonPreferences_Entry<bool> _noHmd;

		private readonly MelonPreferences_Entry<bool> _showConfigMenu;

		private readonly MelonPreferences_Entry<float> _speed;

		private readonly MelonPreferences_Entry<float> _fastMultiplier;

		private readonly MelonPreferences_Entry<float> _cameraSensitivity;

		private readonly MelonPreferences_Entry<float> _fieldOfView;

		private readonly MelonPreferences_Entry<float> _nearClip;

		private readonly MelonPreferences_Entry<int> _cullingMask;

		public static Config Instance => s_lazy.Value;

		public bool FreecamEnabled
		{
			get
			{
				return _freecamEnabled.Value;
			}
			set
			{
				_freecamEnabled.Value = value;
			}
		}

		public bool NoHmd
		{
			get
			{
				return _noHmd.Value;
			}
			set
			{
				_noHmd.Value = value;
			}
		}

		public bool ShowConfigMenu
		{
			get
			{
				return _showConfigMenu.Value;
			}
			set
			{
				_showConfigMenu.Value = value;
			}
		}

		public float Speed
		{
			get
			{
				return _speed.Value;
			}
			set
			{
				_speed.Value = value;
			}
		}

		public float FastMultiplier
		{
			get
			{
				return _fastMultiplier.Value;
			}
			set
			{
				_fastMultiplier.Value = value;
			}
		}

		public float CameraSensitivity
		{
			get
			{
				return _cameraSensitivity.Value;
			}
			set
			{
				_cameraSensitivity.Value = value;
			}
		}

		public float FieldOfView
		{
			get
			{
				return _fieldOfView.Value;
			}
			set
			{
				_fieldOfView.Value = value;
			}
		}

		public float NearClip
		{
			get
			{
				return _nearClip.Value;
			}
			set
			{
				_nearClip.Value = value;
			}
		}

		public int CullingMask
		{
			get
			{
				return _cullingMask.Value;
			}
			set
			{
				_cullingMask.Value = value;
			}
		}

		private Config()
		{
			_config = MelonPreferences.CreateCategory("Freecam");
			_freecamEnabled = _config.CreateEntry<bool>("bFreecamEnabled", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_noHmd = _config.CreateEntry<bool>("bNoHmd", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_showConfigMenu = _config.CreateEntry<bool>("bShowConfigMenu", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_speed = _config.CreateEntry<float>("fNormalSpeed", 10f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_fastMultiplier = _config.CreateEntry<float>("fFastMultiplier", 10f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_cameraSensitivity = _config.CreateEntry<float>("fLookSensitivity", 0.3f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_fieldOfView = _config.CreateEntry<float>("fFieldOfView", 90f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_nearClip = _config.CreateEntry<float>("fNearClip", 0.3f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_cullingMask = _config.CreateEntry<int>("iCullingMask", -1, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		}

		public void Save()
		{
			_config.SaveToFile(true);
		}
	}
}