Decompiled source of LocalBodyCam v1.1.5

Mods/BodyCamLocal.dll

Decompiled 17 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BodyCamLocal;
using BoneLib.BoneMenu;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Bonelab;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: MelonInfo(typeof(BodyCamMod), "Local BodyCam", "1.0.0", "Codex", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : System.Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class NullableAttribute : System.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(/*Could not decode attribute arguments.*/)]
	internal sealed class NullableContextAttribute : System.Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class RefSafetyRulesAttribute : System.Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BodyCamLocal
{
	public sealed class BodyCamMod : MelonMod
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static Action <0>__Save;
		}

		private MelonPreferences_Category _category = null;

		private MelonPreferences_Entry<bool> _enabled = null;

		private MelonPreferences_Entry<bool> _showHud = null;

		private MelonPreferences_Entry<bool> _showTimestamp = null;

		private MelonPreferences_Entry<float> _forwardOffset = null;

		private MelonPreferences_Entry<float> _horizontalOffset = null;

		private MelonPreferences_Entry<float> _verticalOffset = null;

		private MelonPreferences_Entry<float> _downTilt = null;

		private MelonPreferences_Entry<float> _roll = null;

		private MelonPreferences_Entry<float> _fieldOfView = null;

		private MelonPreferences_Entry<float> _nearClip = null;

		private MelonPreferences_Entry<float> _bodyMotion = null;

		private MelonPreferences_Entry<float> _motionSmoothing = null;

		private MelonPreferences_Entry<float> _lensStrength = null;

		private MelonPreferences_Entry<float> _grain = null;

		private MelonPreferences_Entry<float> _vignette = null;

		private MelonPreferences_Entry<float> _hudScale = null;

		private MelonPreferences_Entry<bool> _nightVision = null;

		private MelonPreferences_Entry<float> _nightVisionIntensity = null;

		private MelonPreferences_Entry<float> _nightVisionGain = null;

		private MelonPreferences_Entry<int> _battery = null;

		private GUIStyle _hudStyle = null;

		private GUIStyle _smallStyle = null;

		private Texture2D _white = null;

		private Texture2D _noise = null;

		private Texture2D _vignetteTexture = null;

		private Camera? _monitorBodyCam;

		private Transform? _spectatorTarget;

		private SmoothFollower? _spectatorSmoother;

		private GameObject? _bodyCamTarget;

		private bool _spectatorUnavailableLogged;

		private GameObject? _monitorOverlay;

		private Text? _recLabel;

		private Text? _batteryLabel;

		private Text? _timestampLabel;

		private Image? _vignetteImage;

		private Image? _noiseImage;

		private Image? _nightVisionImage;

		private Sprite? _vignetteSprite;

		private Sprite? _noiseSprite;

		private Canvas? _monitorCanvas;

		private Vector3 _smoothedPosition;

		private Vector3 _positionVelocity;

		private Quaternion _smoothedRotation;

		private bool _hasSmoothedPose;

		private float _startedAt;

		private float _nextNoiseUpdate;

		private readonly Random _random = new Random();

		public override void OnInitializeMelon()
		{
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: 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_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_042e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			//IL_049c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_050a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0541: Unknown result type (might be due to invalid IL or missing references)
			//IL_0578: Unknown result type (might be due to invalid IL or missing references)
			//IL_05af: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_061d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0654: Unknown result type (might be due to invalid IL or missing references)
			//IL_067c: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0716: Unknown result type (might be due to invalid IL or missing references)
			//IL_072b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0730: Unknown result type (might be due to invalid IL or missing references)
			//IL_0736: Expected O, but got Unknown
			_category = MelonPreferences.CreateCategory("LocalBodyCam", "Local BodyCam");
			_enabled = _category.CreateEntry<bool>("Enabled", true, "Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
			_showHud = _category.CreateEntry<bool>("ShowHud", true, "Show HUD", (string)null, false, false, (ValueValidator)null, (string)null);
			_showTimestamp = _category.CreateEntry<bool>("ShowTimestamp", true, "Show timestamp", (string)null, false, false, (ValueValidator)null, (string)null);
			_forwardOffset = _category.CreateEntry<float>("ForwardOffset", 0.16f, "Forward offset (m)", (string)null, false, false, (ValueValidator)null, (string)null);
			_horizontalOffset = _category.CreateEntry<float>("HorizontalOffset", 0f, "Left / right offset (m)", (string)null, false, false, (ValueValidator)null, (string)null);
			_verticalOffset = _category.CreateEntry<float>("VerticalOffset", -0.08f, "Up / down offset (m)", (string)null, false, false, (ValueValidator)null, (string)null);
			_downTilt = _category.CreateEntry<float>("DownTilt", 11f, "Down tilt (degrees)", (string)null, false, false, (ValueValidator)null, (string)null);
			_roll = _category.CreateEntry<float>("Roll", 0f, "Camera roll (degrees)", (string)null, false, false, (ValueValidator)null, (string)null);
			_fieldOfView = _category.CreateEntry<float>("FieldOfView", 104f, "Bodycam field of view", (string)null, false, false, (ValueValidator)null, (string)null);
			_nearClip = _category.CreateEntry<float>("NearClip", 0.08f, "Near clipping distance", (string)null, false, false, (ValueValidator)null, (string)null);
			_bodyMotion = _category.CreateEntry<float>("BodyMotion", 0.35f, "Body-mounted camera motion", (string)null, false, false, (ValueValidator)null, (string)null);
			_motionSmoothing = _category.CreateEntry<float>("MotionSmoothing", 0.32f, "Bodycam motion smoothing", (string)null, false, false, (ValueValidator)null, (string)null);
			_lensStrength = _category.CreateEntry<float>("LensStrength", 0.22f, "Lens distortion", (string)null, false, false, (ValueValidator)null, (string)null);
			_grain = _category.CreateEntry<float>("Grain", 0.12f, "Sensor grain", (string)null, false, false, (ValueValidator)null, (string)null);
			_vignette = _category.CreateEntry<float>("Vignette", 0.52f, "Vignette", (string)null, false, false, (ValueValidator)null, (string)null);
			_hudScale = _category.CreateEntry<float>("HudScale", 1f, "HUD scale", (string)null, false, false, (ValueValidator)null, (string)null);
			_nightVision = _category.CreateEntry<bool>("NightVision", false, "Night vision", (string)null, false, false, (ValueValidator)null, (string)null);
			_nightVisionIntensity = _category.CreateEntry<float>("NightVisionIntensity", 0.72f, "Night vision intensity", (string)null, false, false, (ValueValidator)null, (string)null);
			_nightVisionGain = _category.CreateEntry<float>("NightVisionGain", 0.55f, "Night vision brightness / gain", (string)null, false, false, (ValueValidator)null, (string)null);
			_battery = _category.CreateEntry<int>("Battery", 82, "Battery percent", (string)null, false, false, (ValueValidator)null, (string)null);
			_category.SaveToFile(true);
			Page val = Page.Root.CreatePage("Local BodyCam", Color.red, 0, true);
			val.CreateBool("Enabled", Color.white, _enabled.Value, (Action<bool>)([CompilerGenerated] (bool value) =>
			{
				_enabled.Value = value;
			}));
			val.CreateBool("Show HUD", Color.white, _showHud.Value, (Action<bool>)([CompilerGenerated] (bool value) =>
			{
				_showHud.Value = value;
			}));
			val.CreateBool("Show timestamp", Color.white, _showTimestamp.Value, (Action<bool>)([CompilerGenerated] (bool value) =>
			{
				_showTimestamp.Value = value;
			}));
			val.CreateFloat("Forward offset", Color.white, _forwardOffset.Value, 0.02f, -0.25f, 0.75f, (Action<float>)([CompilerGenerated] (float value) =>
			{
				_forwardOffset.Value = value;
			}));
			val.CreateFloat("Left / right offset", Color.white, _horizontalOffset.Value, 0.02f, -0.5f, 0.5f, (Action<float>)([CompilerGenerated] (float value) =>
			{
				_horizontalOffset.Value = value;
			}));
			val.CreateFloat("Up / down offset", Color.white, _verticalOffset.Value, 0.02f, -0.75f, 0.5f, (Action<float>)([CompilerGenerated] (float value) =>
			{
				_verticalOffset.Value = value;
			}));
			val.CreateFloat("Down tilt", Color.white, _downTilt.Value, 1f, 0f, 35f, (Action<float>)([CompilerGenerated] (float value) =>
			{
				_downTilt.Value = value;
			}));
			val.CreateFloat("Camera roll", Color.white, _roll.Value, 1f, -15f, 15f, (Action<float>)([CompilerGenerated] (float value) =>
			{
				_roll.Value = value;
			}));
			val.CreateFloat("Bodycam FOV", Color.white, _fieldOfView.Value, 1f, 70f, 135f, (Action<float>)([CompilerGenerated] (float value) =>
			{
				_fieldOfView.Value = value;
			}));
			val.CreateFloat("Near clip", Color.white, _nearClip.Value, 0.01f, 0.03f, 0.3f, (Action<float>)([CompilerGenerated] (float value) =>
			{
				_nearClip.Value = value;
			}));
			val.CreateFloat("Body camera motion", Color.white, _bodyMotion.Value, 0.05f, 0f, 1f, (Action<float>)([CompilerGenerated] (float value) =>
			{
				_bodyMotion.Value = value;
			}));
			val.CreateFloat("Bodycam smoothing", Color.cyan, _motionSmoothing.Value, 0.05f, 0f, 1f, (Action<float>)([CompilerGenerated] (float value) =>
			{
				_motionSmoothing.Value = value;
			}));
			val.CreateFloat("Lens strength", Color.white, _lensStrength.Value, 0.02f, 0f, 0.65f, (Action<float>)([CompilerGenerated] (float value) =>
			{
				_lensStrength.Value = value;
			}));
			val.CreateFloat("Sensor grain", Color.white, _grain.Value, 0.01f, 0f, 0.45f, (Action<float>)([CompilerGenerated] (float value) =>
			{
				_grain.Value = value;
			}));
			val.CreateFloat("Vignette", Color.white, _vignette.Value, 0.02f, 0f, 1f, (Action<float>)([CompilerGenerated] (float value) =>
			{
				_vignette.Value = value;
			}));
			val.CreateFloat("HUD scale", Color.white, _hudScale.Value, 0.05f, 0.55f, 1.8f, (Action<float>)([CompilerGenerated] (float value) =>
			{
				_hudScale.Value = value;
			}));
			val.CreateBool("Night vision", Color.green, _nightVision.Value, (Action<bool>)([CompilerGenerated] (bool value) =>
			{
				_nightVision.Value = value;
			}));
			val.CreateFloat("NV intensity", Color.green, _nightVisionIntensity.Value, 0.02f, 0f, 1f, (Action<float>)([CompilerGenerated] (float value) =>
			{
				_nightVisionIntensity.Value = value;
			}));
			val.CreateFloat("NV brightness / gain", Color.green, _nightVisionGain.Value, 0.02f, 0f, 1f, (Action<float>)([CompilerGenerated] (float value) =>
			{
				_nightVisionGain.Value = value;
			}));
			val.CreateInt("Battery %", Color.white, _battery.Value, 1, 1, 100, (Action<int>)([CompilerGenerated] (int value) =>
			{
				_battery.Value = value;
			}));
			Color cyan = Color.cyan;
			object obj = <>O.<0>__Save;
			if (obj == null)
			{
				Action val2 = MelonPreferences.Save;
				<>O.<0>__Save = val2;
				obj = (object)val2;
			}
			val.CreateFunction("Save settings", cyan, (Action)obj);
			_startedAt = Time.realtimeSinceStartup;
			MelonLogger.Msg("Local BodyCam loaded. This presentation is local-only.");
		}

		public override void OnGUI()
		{
		}

		public override void OnUpdate()
		{
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: 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_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: 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_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			if (!_enabled.Value)
			{
				if ((Object)(object)_monitorBodyCam != (Object)null)
				{
					((Behaviour)_monitorBodyCam).enabled = false;
				}
			}
			else
			{
				if (!TryGetNativeSpectatorCamera() || (Object)(object)_monitorBodyCam == (Object)null || (Object)(object)_spectatorTarget == (Object)null)
				{
					return;
				}
				EnsureAssets();
				EnsureMonitorOverlay();
				UpdateMonitorOverlay();
				Transform parent = _spectatorTarget.parent;
				if (!((Object)(object)parent == (Object)null))
				{
					float num = Mathf.Clamp01(_bodyMotion.Value);
					float realtimeSinceStartup = Time.realtimeSinceStartup;
					float num2 = (Mathf.PerlinNoise(realtimeSinceStartup * 1.7f, 3.1f) - 0.5f) * 0.04f * num;
					float num3 = (Mathf.PerlinNoise(7.4f, realtimeSinceStartup * 2.1f) - 0.5f) * 0.026f * num;
					float num4 = (Mathf.PerlinNoise(realtimeSinceStartup * 1.3f, 12.7f) - 0.5f) * 2.2f * num;
					float num5 = (Mathf.PerlinNoise(19.2f, realtimeSinceStartup * 1.6f) - 0.5f) * 1.5f * num;
					Vector3 val = Vector3.ProjectOnPlane(parent.forward, Vector3.up);
					if (((Vector3)(ref val)).sqrMagnitude < 0.0001f)
					{
						val = parent.forward;
					}
					((Vector3)(ref val)).Normalize();
					Vector3 val2 = parent.position + val * _forwardOffset.Value + parent.right * (_horizontalOffset.Value + num2) + Vector3.up * (_verticalOffset.Value + num3);
					Quaternion val3 = parent.rotation * Quaternion.Euler(_downTilt.Value + num4, 0f, _roll.Value + num5);
					float num6 = Mathf.Lerp(0.001f, 0.09f, Mathf.Clamp01(_motionSmoothing.Value));
					if (!_hasSmoothedPose)
					{
						_smoothedPosition = val2;
						_smoothedRotation = val3;
						_positionVelocity = Vector3.zero;
						_hasSmoothedPose = true;
					}
					else
					{
						_smoothedPosition = Vector3.SmoothDamp(_smoothedPosition, val2, ref _positionVelocity, num6, 1f / 0f, Time.unscaledDeltaTime);
						float num7 = 1f - Mathf.Exp((0f - Time.unscaledDeltaTime) / num6);
						_smoothedRotation = Quaternion.Slerp(_smoothedRotation, val3, num7);
					}
					_bodyCamTarget.transform.position = _smoothedPosition;
					_bodyCamTarget.transform.rotation = _smoothedRotation;
					_monitorBodyCam.fieldOfView = _fieldOfView.Value;
					_monitorBodyCam.nearClipPlane = _nearClip.Value;
				}
			}
		}

		private bool TryGetNativeSpectatorCamera()
		{
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Expected O, but got Unknown
			if ((Object)(object)_monitorBodyCam != (Object)null && (Object)(object)_spectatorTarget != (Object)null)
			{
				return true;
			}
			GameObject val = GameObject.Find("GameplaySystems [0]/DisabledContainer/Spectator Camera/Spectator Camera");
			GameObject val2 = GameObject.Find("RigManager(bonelab) [0]/VRControllerRig/TrackingSpace/Headset/Spectator Target");
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				if (!_spectatorUnavailableLogged)
				{
					_spectatorUnavailableLogged = true;
					MelonLogger.Warning("Local BodyCam needs BONELAB's spectator mode set to Fish Eye. Enable Fish Eye in the game/SteamVR spectator settings, then reload the level.");
				}
				return false;
			}
			_monitorBodyCam = val.GetComponent<Camera>();
			_spectatorTarget = val2.transform;
			_spectatorSmoother = val.GetComponent<SmoothFollower>();
			if ((Object)(object)_monitorBodyCam == (Object)null || (Object)(object)_spectatorSmoother == (Object)null)
			{
				_spectatorTarget = null;
				return false;
			}
			_bodyCamTarget = new GameObject("LocalBodyCam_Target");
			_spectatorSmoother.targetTransform = _bodyCamTarget.transform;
			_hasSmoothedPose = false;
			_spectatorUnavailableLogged = false;
			MelonLogger.Msg("Connected Local BodyCam to BONELAB's native desktop spectator camera.");
			return true;
		}

		private void EnsureMonitorOverlay()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: 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_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_monitorOverlay != (Object)null) && !((Object)(object)_monitorBodyCam == (Object)null))
			{
				_monitorOverlay = new GameObject("LocalBodyCam_MonitorOverlay");
				Canvas val = (_monitorCanvas = _monitorOverlay.AddComponent<Canvas>());
				val.renderMode = (RenderMode)0;
				val.overrideSorting = true;
				val.sortingOrder = 32000;
				CanvasScaler val2 = _monitorOverlay.AddComponent<CanvasScaler>();
				val2.uiScaleMode = (ScaleMode)1;
				val2.referenceResolution = new Vector2(1920f, 1080f);
				((Behaviour)_monitorOverlay.AddComponent<GraphicRaycaster>()).enabled = false;
				_vignetteSprite = Sprite.Create(_vignetteTexture, new Rect(0f, 0f, (float)((Texture)_vignetteTexture).width, (float)((Texture)_vignetteTexture).height), new Vector2(0.5f, 0.5f));
				_noiseSprite = Sprite.Create(_noise, new Rect(0f, 0f, (float)((Texture)_noise).width, (float)((Texture)_noise).height), new Vector2(0.5f, 0.5f));
				_vignetteImage = CreateFullImage("Rounded lens vignette", _vignetteSprite, 0);
				_nightVisionImage = CreateFullImage("Night vision", null, 1);
				_noiseImage = CreateFullImage("Sensor noise", _noiseSprite, 2);
				_recLabel = CreateLabel("REC", 28, (TextAnchor)0);
				SetRect(((Graphic)_recLabel).rectTransform, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(28f, -72f), new Vector2(230f, -22f));
				_batteryLabel = CreateLabel("BAT", 20, (TextAnchor)2);
				SetRect(((Graphic)_batteryLabel).rectTransform, new Vector2(1f, 1f), new Vector2(1f, 1f), new Vector2(-250f, -65f), new Vector2(-28f, -22f));
				_timestampLabel = CreateLabel("TIME", 18, (TextAnchor)6);
				SetRect(((Graphic)_timestampLabel).rectTransform, Vector2.zero, Vector2.zero, new Vector2(42f, 18f), new Vector2(700f, 60f));
			}
		}

		private Image CreateFullImage(string name, Sprite? sprite, int sibling)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(_monitorOverlay.transform, false);
			Image val2 = val.AddComponent<Image>();
			val2.sprite = sprite;
			((Graphic)val2).raycastTarget = false;
			val.transform.SetSiblingIndex(sibling);
			SetRect(((Graphic)val2).rectTransform, Vector2.zero, Vector2.one, Vector2.zero, Vector2.zero);
			return val2;
		}

		private Text CreateLabel(string name, int size, TextAnchor alignment)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(_monitorOverlay.transform, false);
			Text val2 = val.AddComponent<Text>();
			val2.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
			val2.fontSize = size;
			val2.fontStyle = (FontStyle)1;
			val2.alignment = alignment;
			((Graphic)val2).raycastTarget = false;
			return val2;
		}

		private static void SetRect(RectTransform rect, Vector2 min, Vector2 max, Vector2 low, Vector2 high)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			rect.anchorMin = min;
			rect.anchorMax = max;
			rect.offsetMin = low;
			rect.offsetMax = high;
		}

		private void UpdateMonitorOverlay()
		{
			//IL_00bc: 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_0153: 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_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_monitorOverlay == (Object)null) && !((Object)(object)_vignetteImage == (Object)null) && !((Object)(object)_noiseImage == (Object)null) && !((Object)(object)_nightVisionImage == (Object)null))
			{
				_monitorOverlay.SetActive(_enabled.Value);
				float realtimeSinceStartup = Time.realtimeSinceStartup;
				if (realtimeSinceStartup >= _nextNoiseUpdate)
				{
					RefreshNoiseTexture(realtimeSinceStartup);
				}
				((Graphic)_vignetteImage).color = new Color(0f, 0f, 0f, Mathf.Clamp01(_vignette.Value) * (0.82f + Mathf.Clamp01(_lensStrength.Value) * 0.18f));
				((Graphic)_noiseImage).color = new Color(1f, 1f, 1f, Mathf.Clamp01(_grain.Value) * 0.11f);
				((Graphic)_nightVisionImage).color = (Color)(_nightVision.Value ? new Color(0.04f, 0.92f, 0.12f, Mathf.Clamp01(_nightVisionIntensity.Value) * (0.25f + Mathf.Clamp01(_nightVisionGain.Value) * 0.42f)) : Color.clear);
				bool value = _showHud.Value;
				float num = Mathf.Clamp(_hudScale.Value, 0.55f, 1.8f);
				if ((Object)(object)_recLabel != (Object)null)
				{
					((Component)_recLabel).gameObject.SetActive(value);
					_recLabel.text = "●  REC";
					((Graphic)_recLabel).color = (((int)(realtimeSinceStartup * 2f) % 2 == 0) ? new Color(0.98f, 0.04f, 0.04f) : new Color(0.45f, 0.02f, 0.02f));
				}
				if ((Object)(object)_batteryLabel != (Object)null)
				{
					((Component)_batteryLabel).gameObject.SetActive(value);
					_batteryLabel.text = _battery.Value + "%  ▰";
					((Graphic)_batteryLabel).color = ((_battery.Value < 20) ? new Color(0.95f, 0.06f, 0.04f) : new Color(0.25f, 1f, 0.43f));
				}
				if ((Object)(object)_timestampLabel != (Object)null)
				{
					((Component)_timestampLabel).gameObject.SetActive(value && _showTimestamp.Value);
					TimeSpan val = TimeSpan.FromSeconds((double)(realtimeSinceStartup - _startedAt));
					_timestampLabel.text = $"BC-01  {System.DateTime.Now:yyyy-MM-dd}  {val:hh\\:mm\\:ss}";
					((Graphic)_timestampLabel).color = new Color(1f, 1f, 1f, 0.9f);
				}
				if ((Object)(object)_recLabel != (Object)null)
				{
					_recLabel.fontSize = Mathf.RoundToInt(28f * num);
				}
				if ((Object)(object)_batteryLabel != (Object)null)
				{
					_batteryLabel.fontSize = Mathf.RoundToInt(20f * num);
				}
				if ((Object)(object)_timestampLabel != (Object)null)
				{
					_timestampLabel.fontSize = Mathf.RoundToInt(18f * num);
				}
			}
		}

		private void RefreshNoiseTexture(float now)
		{
			//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)
			Color32[] array = (Color32[])(object)new Color32[5184];
			for (int i = 0; i < array.Length; i++)
			{
				byte b = (byte)_random.Next(80, 181);
				array[i] = new Color32(b, b, b, (byte)255);
			}
			_noise.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
			_noise.Apply(false);
			_nextNoiseUpdate = now + 0.066f;
		}

		public override void OnDeinitializeMelon()
		{
			if ((Object)(object)_monitorOverlay != (Object)null)
			{
				Object.Destroy((Object)(object)_monitorOverlay);
			}
			if ((Object)(object)_spectatorSmoother != (Object)null && (Object)(object)_spectatorTarget != (Object)null)
			{
				_spectatorSmoother.targetTransform = _spectatorTarget;
			}
			if ((Object)(object)_bodyCamTarget != (Object)null)
			{
				Object.Destroy((Object)(object)_bodyCamTarget);
			}
		}

		private void EnsureAssets()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_002b: 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_0053: Expected O, but got Unknown
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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_0092: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			if (!((Object)(object)_white != (Object)null))
			{
				_white = new Texture2D(1, 1);
				_white.SetPixel(0, 0, Color.white);
				_white.Apply();
				_noise = new Texture2D(96, 54, (TextureFormat)4, false);
				_vignetteTexture = BuildVignetteTexture(256);
				_hudStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 20,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)3
				};
				_smallStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 13,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)3
				};
			}
		}

		private void DrawHud(int width, int height)
		{
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_00cd: 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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: 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)
			float num = Mathf.Clamp((float)width / 1920f, 0.72f, 1.5f) * _hudScale.Value;
			_hudStyle.fontSize = Mathf.RoundToInt(20f * num);
			_smallStyle.fontSize = Mathf.RoundToInt(13f * num);
			int num2 = Mathf.RoundToInt(28f * num);
			Color color = (((int)(Time.realtimeSinceStartup * 2f) % 2 == 0) ? new Color(0.95f, 0.04f, 0.03f, 1f) : new Color(0.45f, 0.02f, 0.02f, 1f));
			GUI.color = color;
			GUI.DrawTexture(new Rect((float)num2, (float)num2 + 5f * num, 12f * num, 12f * num), (Texture)(object)_white);
			GUI.Label(new Rect((float)num2 + 19f * num, (float)num2, 100f * num, 28f * num), "REC", _hudStyle);
			GUI.color = new Color(1f, 1f, 1f, 0.9f);
			if (_showTimestamp.Value)
			{
				TimeSpan val = TimeSpan.FromSeconds((double)(Time.realtimeSinceStartup - _startedAt));
				GUI.Label(new Rect((float)num2, (float)(height - num2) - 20f * num, 260f * num, 22f * num), $"BC-01  {System.DateTime.Now:yyyy-MM-dd}  {val:hh\\:mm\\:ss}", _smallStyle);
			}
			DrawBattery((float)(width - num2) - 62f * num, (float)num2 + 3f * num, num);
			GUI.color = Color.white;
		}

		private void DrawBattery(float x, float y, float scale)
		{
			//IL_0025: 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_005f: 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_009f: 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_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			float num = 43f * scale;
			float num2 = 17f * scale;
			GUI.color = new Color(1f, 1f, 1f, 0.88f);
			GUI.DrawTexture(new Rect(x, y, num, 2f * scale), (Texture)(object)_white);
			GUI.DrawTexture(new Rect(x, y + num2 - 2f * scale, num, 2f * scale), (Texture)(object)_white);
			GUI.DrawTexture(new Rect(x, y, 2f * scale, num2), (Texture)(object)_white);
			GUI.DrawTexture(new Rect(x + num - 2f * scale, y, 2f * scale, num2), (Texture)(object)_white);
			GUI.DrawTexture(new Rect(x + num, y + 5f * scale, 4f * scale, 7f * scale), (Texture)(object)_white);
			float num3 = Mathf.Clamp01((float)_battery.Value / 100f) * (num - 6f * scale);
			GUI.color = ((_battery.Value < 20) ? new Color(0.95f, 0.06f, 0.04f, 0.95f) : new Color(0.25f, 1f, 0.43f, 0.95f));
			GUI.DrawTexture(new Rect(x + 3f * scale, y + 3f * scale, num3, num2 - 6f * scale), (Texture)(object)_white);
			GUI.color = Color.white;
			GUI.Label(new Rect(x - 38f * scale, y - 1f * scale, 34f * scale, num2), _battery.Value + "%", _smallStyle);
		}

		private void DrawVignette(int width, int height)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp01(_vignette.Value) * (0.58f + Mathf.Clamp01(_lensStrength.Value) * 0.42f);
			GUI.color = new Color(0f, 0f, 0f, num);
			GUI.DrawTexture(new Rect(0f, 0f, (float)width, (float)height), (Texture)(object)_vignetteTexture, (ScaleMode)0, true);
			GUI.color = Color.white;
		}

		private Texture2D BuildVignetteTexture(int size)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_00ad: 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)
			Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
			Color32[] array = (Color32[])(object)new Color32[size * size];
			for (int i = 0; i < size; i++)
			{
				for (int j = 0; j < size; j++)
				{
					float num = ((float)j / (float)(size - 1) - 0.5f) * 2f;
					float num2 = ((float)i / (float)(size - 1) - 0.5f) * 2f;
					float num3 = Mathf.Sqrt(num * num + num2 * num2);
					float num4 = Mathf.Clamp01((num3 - 0.38f) / 0.62f);
					num4 = num4 * num4 * (3f - 2f * num4);
					array[i * size + j] = new Color32((byte)255, (byte)255, (byte)255, (byte)Mathf.RoundToInt(num4 * 255f));
				}
			}
			val.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
			val.Apply(false);
			return val;
		}

		private void DrawNightVision(Rect screen)
		{
			//IL_0051: 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_0097: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp01(_nightVisionIntensity.Value);
			float num2 = Mathf.Clamp01(_nightVisionGain.Value);
			GUI.color = new Color(0.36f + num2 * 0.3f, 0.58f + num2 * 0.36f, 0.36f + num2 * 0.3f, num2 * 0.32f);
			GUI.DrawTexture(screen, (Texture)(object)_white);
			GUI.color = new Color(0.02f, 0.82f + num2 * 0.18f, 0.08f + num2 * 0.14f, num * (0.32f + num2 * 0.36f));
			GUI.DrawTexture(screen, (Texture)(object)_white);
			GUI.color = Color.white;
		}

		private void DrawHudSensorNoise(Rect screen)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if (!(_grain.Value <= 0f))
			{
				GUI.color = new Color(1f, 1f, 1f, Mathf.Clamp01(_grain.Value) * 0.035f);
				GUI.DrawTexture(screen, (Texture)(object)_noise, (ScaleMode)0, true);
				GUI.color = Color.white;
			}
		}

		private void DrawGrain(Rect screen)
		{
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (_grain.Value <= 0f)
			{
				return;
			}
			if (Time.realtimeSinceStartup >= _nextNoiseUpdate)
			{
				Color32[] array = (Color32[])(object)new Color32[5184];
				for (int i = 0; i < array.Length; i++)
				{
					byte b = (byte)_random.Next(80, 181);
					array[i] = new Color32(b, b, b, (byte)255);
				}
				_noise.SetPixels32(Il2CppStructArray<Color32>.op_Implicit(array));
				_noise.Apply(false);
				_nextNoiseUpdate = Time.realtimeSinceStartup + 0.066f;
			}
			GUI.color = new Color(1f, 1f, 1f, Mathf.Clamp01(_grain.Value) * 0.18f);
			GUI.DrawTexture(screen, (Texture)(object)_noise, (ScaleMode)0, true);
			GUI.color = Color.white;
		}
	}
}