Decompiled source of DR NewEngland CameraSets v1.0.0

DR_NewEngland_CameraSets.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FistVR;
using JerryCamSets;
using OtherLoader;
using Sodalite;
using Sodalite.Api;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace JerryCamSets
{
	[Serializable]
	public class CamSetShot
	{
		public string sourceName;

		public Transform point;

		public float startDistance;

		public float fieldOfView = 40f;

		public Vector3[] flightSamples;

		public float flightDuration = 13.333333f;

		public float flightLength;

		public float flightSpeedRatio = 0.7f;

		public bool flightSpeedRelative;
	}
	[DefaultExecutionOrder(12000)]
	public class CamSetsController : MonoBehaviour
	{
		public Transform camcorderMount;

		public GameObject camcorderPrefab;

		public string camcorderItemID = "Camcorder";

		public Transform targetOverride;

		public Vector3[] routePoints;

		public float[] routeDistances;

		public CamSetShot[] shots;

		public bool forceWorldOrigin = true;

		public float switchHysteresis = 3f;

		public float progressDistance;

		public int activeShot = -1;

		public bool distanceFraming = true;

		public float framingHeight = 8f;

		public float minimumTrackingFov = 2f;

		public float maximumTrackingFov = 75f;

		public float zoomResponse = 4f;

		public float routeOffsetMeters;

		public float cameraDistanceMeters;

		public float currentFieldOfView;

		private float nextFramingDiagnostic;

		private bool hasFraming;

		public int raceStartGate = 5;

		public string introItemID = "Intro";

		public float introAfterStartMeters = 50f;

		public float introLifetime = 9.2f;

		private GameObject introInstance;

		private float introExpiresAt;

		private float introPreviousProgress;

		private bool introHasProgress;

		private bool introArmed;

		private Camcorder camcorder;

		private FVRSceneSettings scene;

		private object controls;

		private object previousMode;

		private object spawnedMode;

		private FieldInfo modeField;

		private FieldInfo fovField;

		private FieldInfo linearField;

		private FieldInfo angularField;

		private Transform previousPoint;

		private float previousFov;

		private float previousLinear;

		private float previousAngular;

		private float nextAttempt;

		private int segment = -1;

		private bool activated;

		private bool warned;

		private float shotStarted;

		private float flightTravel;

		private float lastProgress;

		private Vector3 lastTarget;

		private bool hasLastTarget;

		private static object ReadField(object owner, string name)
		{
			return owner?.GetType().GetField(name)?.GetValue(owner);
		}

		private bool BindCameraSettings(object options)
		{
			object obj = ReadField(ReadField(options, "SpectatorCamera"), "CurrentSettings");
			bool flag = obj != null;
			controls = ((!flag) ? ReadField(options, "ControlOptions") : obj);
			if (controls == null)
			{
				return false;
			}
			Type type = controls.GetType();
			modeField = type.GetField((!flag) ? "CamMode" : "CameraMode");
			fovField = type.GetField((!flag) ? "CamFOV" : "CameraFov");
			linearField = type.GetField((!flag) ? "CamSmoothingLinear" : "CameraSmoothingLinear");
			angularField = type.GetField((!flag) ? "CamSmoothingRotational" : "CameraSmoothingAngular");
			if ((object)modeField == null || (object)fovField == null || (object)linearField == null || (object)angularField == null)
			{
				return false;
			}
			spawnedMode = Enum.Parse(modeField.FieldType, "SpawnedObject");
			return true;
		}

		private bool IsSpawnedMode()
		{
			return object.Equals(modeField.GetValue(controls), spawnedMode);
		}

		private void Awake()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (forceWorldOrigin)
			{
				((Component)this).transform.position = Vector3.zero;
				((Component)this).transform.rotation = Quaternion.identity;
				((Component)this).transform.localScale = Vector3.one;
			}
		}

		private void OnEnable()
		{
			nextAttempt = 0f;
			warned = false;
			segment = -1;
			hasLastTarget = false;
			introHasProgress = false;
			introArmed = false;
			hasFraming = false;
			nextFramingDiagnostic = 0f;
		}

		private void LateUpdate()
		{
			//IL_00bf: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: 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_033e: 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_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04be: Unknown result type (might be due to invalid IL or missing references)
			//IL_052d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0549: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)introInstance != (Object)null && Time.unscaledTime >= introExpiresAt)
			{
				RemoveIntro();
			}
			Transform head = targetOverride;
			if ((Object)(object)head == (Object)null && (Object)(object)GM.CurrentMovementManager != (Object)null)
			{
				head = GM.CurrentMovementManager.Head;
			}
			if ((Object)(object)head == (Object)null || shots == null || shots.Length == 0 || routePoints == null || routePoints.Length < 2 || routeDistances == null || routeDistances.Length != routePoints.Length)
			{
				return;
			}
			Vector3 local = ((Component)this).transform.InverseTransformPoint(head.position);
			bool flag = UpdateRouteProgress(local);
			UpdateIntro(flag);
			if (!activated)
			{
				if (Time.unscaledTime < nextAttempt)
				{
					return;
				}
				nextAttempt = Time.unscaledTime + 1f;
				if (!Activate())
				{
					return;
				}
			}
			if ((Object)(object)scene == (Object)null || (Object)(object)camcorder == (Object)null || (Object)(object)scene.GetCamObjectPoint() != (Object)(object)camcorder.CamPoint || !IsSpawnedMode())
			{
				return;
			}
			int num = activeShot;
			SelectShot(flag);
			CamSetShot camSetShot = shots[activeShot];
			if ((Object)(object)camSetShot.point == (Object)null)
			{
				return;
			}
			if (flag || num != activeShot)
			{
				shotStarted = Time.time;
				flightTravel = 0f;
				lastProgress = progressDistance;
			}
			camcorderMount.position = camSetShot.point.position;
			if (camSetShot.flightSamples != null && camSetShot.flightSamples.Length > 1)
			{
				flightTravel = Mathf.Clamp(flightTravel + (progressDistance - lastProgress) * camSetShot.flightSpeedRatio, 0f, camSetShot.flightLength);
				float num2 = ((!camSetShot.flightSpeedRelative) ? ((Time.time - shotStarted) / Mathf.Max(0.01f, camSetShot.flightDuration)) : (flightTravel / Mathf.Max(0.01f, camSetShot.flightLength)));
				float num3 = Mathf.Clamp01(num2) * (float)(camSetShot.flightSamples.Length - 1);
				int num4 = Mathf.Min((int)num3, camSetShot.flightSamples.Length - 2);
				camcorderMount.position = ((Component)this).transform.TransformPoint(Vector3.Lerp(camSetShot.flightSamples[num4], camSetShot.flightSamples[num4 + 1], num3 - (float)num4));
			}
			lastProgress = progressDistance;
			Vector3 val = head.position - camcorderMount.position;
			if (((Vector3)(ref val)).sqrMagnitude > 0.001f)
			{
				camcorderMount.rotation = Quaternion.LookRotation(val, Vector3.up);
			}
			cameraDistanceMeters = ((Vector3)(ref val)).magnitude;
			float num5 = CalculateFramingFov(camSetShot.fieldOfView, cameraDistanceMeters);
			if (!hasFraming || flag || num != activeShot)
			{
				currentFieldOfView = num5;
			}
			else
			{
				currentFieldOfView = Mathf.Lerp(currentFieldOfView, num5, 1f - Mathf.Exp((0f - Mathf.Max(0.01f, zoomResponse)) * Time.unscaledDeltaTime));
			}
			hasFraming = true;
			float num6 = currentFieldOfView;
			fovField.SetValue(controls, num6);
			if (Time.unscaledTime >= nextFramingDiagnostic)
			{
				nextFramingDiagnostic = Time.unscaledTime + 10f;
				string text = string.Concat("[CamSets framing] source=usa2/route_3 mirrorX=true shot=", camSetShot.sourceName, " progress=", progressDistance.ToString("F1"), " routeOffset=", routeOffsetMeters.ToString("F1"), " cameraDistance=", cameraDistanceMeters.ToString("F1"), " fov=", num6.ToString("F1"), " player=", head.position, " camera=", camcorderMount.position);
				if (routeOffsetMeters > 40f)
				{
					Debug.LogWarning((object)(text + " (player is far from the route_3 reference line)"), (Object)(object)this);
				}
				else
				{
					Debug.Log((object)text, (Object)(object)this);
				}
			}
			Camera spectatorCamera = scene.SpectatorCamera;
			if ((Object)(object)spectatorCamera != (Object)null)
			{
				((Component)spectatorCamera).transform.position = camcorder.CamPoint.position;
				((Component)spectatorCamera).transform.rotation = camcorder.CamPoint.rotation;
				spectatorCamera.fieldOfView = num6;
			}
		}

		private float CalculateFramingFov(float sourceFov, float distance)
		{
			float result = Mathf.Clamp(sourceFov, 1f, 179f);
			if (!distanceFraming)
			{
				return result;
			}
			result = Mathf.Clamp(maximumTrackingFov, 1f, 179f);
			float num = Mathf.Clamp(minimumTrackingFov, 1f, result);
			float num2 = 2f * Mathf.Atan2(Mathf.Max(1f, framingHeight) * 0.5f, Mathf.Max(0.1f, distance)) * 57.29578f;
			return Mathf.Clamp(num2, num, result);
		}

		private bool UpdateRouteProgress(Vector3 local)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			int num = segment;
			int num2;
			if (segment >= 0 && hasLastTarget)
			{
				Vector3 val = local - lastTarget;
				num2 = ((((Vector3)(ref val)).sqrMagnitude > 2500f) ? 1 : 0);
			}
			else
			{
				num2 = 1;
			}
			bool flag = (byte)num2 != 0;
			int best;
			float distance;
			if (flag)
			{
				Project(local, 0, routePoints.Length - 2, out best, out distance);
			}
			else
			{
				int num3 = Mathf.Max(0, segment - 15);
				int num4 = Mathf.Min(routePoints.Length - 2, segment + 15);
				Project(local, num3, num4, out best, out distance);
				if (distance > 1600f || (best == num3 && num3 > 0) || (best == num4 && num4 < routePoints.Length - 2))
				{
					Project(local, 0, routePoints.Length - 2, out best, out distance);
				}
			}
			if (num >= 0 && Mathf.Abs(best - num) > 15)
			{
				flag = true;
			}
			routeOffsetMeters = Mathf.Sqrt(distance);
			segment = best;
			lastTarget = local;
			hasLastTarget = true;
			return flag;
		}

		private void SelectShot(bool repositioned)
		{
			int num = 0;
			for (int i = 1; i < shots.Length && progressDistance >= shots[i].startDistance; i++)
			{
				num = i;
			}
			if (repositioned || activeShot < 0 || activeShot >= shots.Length || Mathf.Abs(num - activeShot) > 1)
			{
				activeShot = num;
			}
			else if (num > activeShot)
			{
				activeShot = num;
			}
			else if (num < activeShot && progressDistance < shots[activeShot].startDistance - Mathf.Max(0f, switchHysteresis))
			{
				activeShot = num;
			}
		}

		private void Project(Vector3 position, int first, int last, out int best, out float distance)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			best = first;
			distance = float.MaxValue;
			for (int i = first; i <= last; i++)
			{
				Vector3 val = routePoints[i];
				Vector3 val2 = routePoints[i + 1] - val;
				float num = Mathf.Clamp01(Vector3.Dot(position - val, val2) / Mathf.Max(0.0001f, ((Vector3)(ref val2)).sqrMagnitude));
				Vector3 val3 = position - (val + val2 * num);
				float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
				if (sqrMagnitude < distance)
				{
					distance = sqrMagnitude;
					best = i;
					progressDistance = Mathf.Lerp(routeDistances[i], routeDistances[i + 1], num);
				}
			}
		}

		private bool Activate()
		{
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: 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_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: 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_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: 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)
			if ((Object)(object)GM.CurrentSceneSettings == (Object)null || GM.Options == null || (Object)(object)camcorderMount == (Object)null)
			{
				return false;
			}
			if ((Object)(object)camcorder == (Object)null)
			{
				GameObject gameObject = camcorderPrefab;
				if ((Object)(object)gameObject == (Object)null && IM.OD != null)
				{
					if (IM.OD.TryGetValue(camcorderItemID, out var value))
					{
						gameObject = ((AnvilAsset)value).GetGameObject();
					}
					else
					{
						foreach (KeyValuePair<string, FVRObject> item in IM.OD)
						{
							if (string.Equals(item.Key, "Camcorder", StringComparison.OrdinalIgnoreCase) || string.Equals(item.Value.DisplayName, "Camcorder", StringComparison.OrdinalIgnoreCase))
							{
								gameObject = ((AnvilAsset)item.Value).GetGameObject();
								break;
							}
						}
					}
				}
				if ((Object)(object)gameObject == (Object)null || (Object)(object)gameObject.GetComponentInChildren<Camcorder>(true) == (Object)null)
				{
					if (!warned)
					{
						Debug.LogWarning((object)"[CamSets] Waiting for native H3VR Camcorder. Check camcorderItemID or assign camcorderPrefab.", (Object)(object)this);
						warned = true;
					}
					return false;
				}
				GameObject val = Object.Instantiate<GameObject>(gameObject);
				((Object)val).name = "H3VR_Camcorder";
				val.transform.SetParent(camcorderMount, false);
				camcorder = val.GetComponentInChildren<Camcorder>(true);
				if ((Object)(object)camcorder.CamPoint == (Object)null)
				{
					Object.Destroy((Object)(object)val);
					camcorder = null;
					return false;
				}
				Rigidbody[] componentsInChildren = val.GetComponentsInChildren<Rigidbody>(true);
				foreach (Rigidbody val2 in componentsInChildren)
				{
					val2.isKinematic = true;
					val2.useGravity = false;
				}
				Collider[] componentsInChildren2 = val.GetComponentsInChildren<Collider>(true);
				foreach (Collider val3 in componentsInChildren2)
				{
					val3.enabled = false;
				}
				((Behaviour)camcorder).enabled = false;
				Transform transform = val.transform;
				Vector3 val4 = transform.InverseTransformPoint(camcorder.CamPoint.position);
				Quaternion val5 = Quaternion.Inverse(transform.rotation) * camcorder.CamPoint.rotation;
				transform.localRotation = Quaternion.Inverse(val5);
				transform.localPosition = -(transform.localRotation * Vector3.Scale(val4, transform.localScale));
				val.SetActive(true);
			}
			scene = GM.CurrentSceneSettings;
			if (!BindCameraSettings(GM.Options))
			{
				if (!warned)
				{
					Debug.LogWarning((object)"[CamSets] Camera settings are not ready or unsupported.", (Object)(object)this);
					warned = true;
				}
				return false;
			}
			previousPoint = scene.GetCamObjectPoint();
			previousMode = modeField.GetValue(controls);
			previousFov = (float)fovField.GetValue(controls);
			previousLinear = (float)linearField.GetValue(controls);
			previousAngular = (float)angularField.GetValue(controls);
			modeField.SetValue(controls, spawnedMode);
			linearField.SetValue(controls, 0f);
			angularField.SetValue(controls, 0f);
			scene.SetCamObjectPoint(camcorder.CamPoint);
			activated = true;
			activeShot = -1;
			return true;
		}

		private bool CrossedIntroMarker(bool repositioned)
		{
			float num = routeDistances[Mathf.Clamp(raceStartGate, 0, routeDistances.Length - 1)];
			float num2 = num + Mathf.Max(0f, introAfterStartMeters);
			if (!introHasProgress)
			{
				introHasProgress = true;
				introPreviousProgress = progressDistance;
				introArmed = progressDistance < num2;
				return false;
			}
			if (progressDistance <= num)
			{
				introArmed = true;
			}
			bool result = introArmed && !repositioned && introPreviousProgress < num2 && progressDistance >= num2;
			if (progressDistance >= num2)
			{
				introArmed = false;
			}
			introPreviousProgress = progressDistance;
			return result;
		}

		private void UpdateIntro(bool repositioned)
		{
			//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_00ec: Unknown result type (might be due to invalid IL or missing references)
			if (!CrossedIntroMarker(repositioned))
			{
				return;
			}
			Transform val = ((!((Object)(object)GM.CurrentMovementManager == (Object)null)) ? GM.CurrentMovementManager.Head : null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			try
			{
				if (IM.OD == null || !IM.OD.TryGetValue(introItemID, out var value) || (Object)(object)value == (Object)null)
				{
					Debug.LogWarning((object)("[CamSets] Missing FVRObject ItemID: " + introItemID), (Object)(object)this);
					return;
				}
				GameObject gameObject = ((AnvilAsset)value).GetGameObject();
				if ((Object)(object)gameObject == (Object)null)
				{
					Debug.LogWarning((object)"[CamSets] Intro FVRObject has no loaded prefab.", (Object)(object)this);
					return;
				}
				RemoveIntro();
				introInstance = Object.Instantiate<GameObject>(gameObject, val.position, val.rotation);
				((Object)introInstance).name = "Intro";
				SceneManager.MoveGameObjectToScene(introInstance, ((Component)this).gameObject.scene);
				introInstance.SetActive(true);
				introExpiresAt = Time.unscaledTime + Mathf.Max(0f, introLifetime);
			}
			catch (Exception ex)
			{
				RemoveIntro();
				Debug.LogError((object)("[CamSets] Could not spawn Intro: " + ex), (Object)(object)this);
			}
		}

		private void RemoveIntro()
		{
			if (!((Object)(object)introInstance == (Object)null))
			{
				introInstance.SetActive(false);
				Object.Destroy((Object)(object)introInstance);
				introInstance = null;
			}
		}

		private void OnDisable()
		{
			RemoveIntro();
			introHasProgress = false;
			introArmed = false;
			if (activated && (Object)(object)scene != (Object)null && (Object)(object)camcorder != (Object)null && (Object)(object)scene.GetCamObjectPoint() == (Object)(object)camcorder.CamPoint)
			{
				scene.SetCamObjectPoint(previousPoint);
				if (controls != null && IsSpawnedMode())
				{
					modeField.SetValue(controls, previousMode);
					fovField.SetValue(controls, previousFov);
					linearField.SetValue(controls, previousLinear);
					angularField.SetValue(controls, previousAngular);
				}
			}
			activated = false;
		}

		private void OnDrawGizmosSelected()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_009c: 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)
			if (shots == null)
			{
				return;
			}
			Gizmos.color = Color.cyan;
			CamSetShot[] array = shots;
			foreach (CamSetShot camSetShot in array)
			{
				if ((Object)(object)camSetShot.point != (Object)null)
				{
					Gizmos.DrawWireSphere(camSetShot.point.position, 1f);
				}
				if (camSetShot.flightSamples != null)
				{
					for (int j = 1; j < camSetShot.flightSamples.Length; j++)
					{
						Gizmos.DrawLine(((Component)this).transform.TransformPoint(camSetShot.flightSamples[j - 1]), ((Component)this).transform.TransformPoint(camSetShot.flightSamples[j]));
					}
				}
			}
		}
	}
}
namespace JerryAr.DR_NewEngland_CameraSets
{
	[BepInPlugin("JerryAr.DR_NewEngland_CameraSets", "DR_NewEngland_CameraSets", "1.0.0")]
	[BepInDependency("nrgill28.Sodalite", "1.4.1")]
	[BepInProcess("h3vr.exe")]
	[Description("Built with MeatKit")]
	[BepInDependency("h3vr.otherloader", "1.3.0")]
	public sealed class DR_NewEngland_CameraSetsPlugin : BaseUnityPlugin
	{
		private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		internal static ManualLogSource Logger;

		private float nextWarning;

		private bool requested = false;

		private bool buttonDirty = true;

		private WristMenuButton button;

		private CamSetsController instance;

		private float nextCheck;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			LoadAssets();
		}

		private void LoadAssets()
		{
			OtherLoader.RegisterDirectLoad(BasePath, "JerryAr.DR_NewEngland_CameraSets", "", "", "dr_newengland_camerasets", "");
		}

		private void OnEnable()
		{
			requested = false;
			buttonDirty = true;
			nextCheck = 0f;
		}

		private void Toggle(object sender, ButtonClickEventArgs args)
		{
			requested = !requested;
			buttonDirty = true;
			nextCheck = 0f;
		}

		private void Update()
		{
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_0224: 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_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			if (buttonDirty)
			{
				if (button != null)
				{
					WristMenuAPI.Buttons.Remove(button);
				}
				button = new WristMenuButton((!requested) ? "Track cameras: OFF" : "Track cameras: ON", new ButtonClickEvent(Toggle));
				WristMenuAPI.Buttons.Add(button);
				buttonDirty = false;
			}
			if (!requested)
			{
				RemoveSet();
			}
			else
			{
				if (Time.unscaledTime < nextCheck)
				{
					return;
				}
				nextCheck = Time.unscaledTime + 0.5f;
				Scene val = default(Scene);
				bool flag = false;
				for (int i = 0; i < SceneManager.sceneCount; i++)
				{
					Scene sceneAt = SceneManager.GetSceneAt(i);
					if (((Scene)(ref sceneAt)).isLoaded && string.Equals(((Scene)(ref sceneAt)).name, "NewEngland", StringComparison.OrdinalIgnoreCase))
					{
						val = sceneAt;
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					RemoveSet();
				}
				else
				{
					if ((Object)(object)instance != (Object)null)
					{
						return;
					}
					GameObject val2 = null;
					try
					{
						if (IM.OD == null || !IM.OD.TryGetValue("CamSets", out var value) || (Object)(object)value == (Object)null)
						{
							if (Time.unscaledTime >= nextWarning)
							{
								Logger.LogWarning((object)"Waiting for FVRObject ItemID CamSets to be registered.");
								nextWarning = Time.unscaledTime + 10f;
							}
							return;
						}
						GameObject gameObject = ((AnvilAsset)value).GetGameObject();
						if ((Object)(object)gameObject == (Object)null)
						{
							if (Time.unscaledTime >= nextWarning)
							{
								Logger.LogWarning((object)"Waiting for CamSets FVRObject prefab.");
								nextWarning = Time.unscaledTime + 10f;
							}
							return;
						}
						if ((Object)(object)gameObject.GetComponent<CamSetsController>() == (Object)null)
						{
							throw new InvalidOperationException("CamSets FVRObject must reference the CamSets prefab with CamSetsController.");
						}
						val2 = Object.Instantiate<GameObject>(gameObject);
						((Object)val2).name = "CamSets";
						val2.SetActive(false);
						SceneManager.MoveGameObjectToScene(val2, val);
						val2.transform.position = Vector3.zero;
						val2.transform.rotation = Quaternion.identity;
						val2.transform.localScale = Vector3.one;
						instance = val2.GetComponent<CamSetsController>();
						val2.SetActive(true);
						Logger.LogInfo((object)"CamSets enabled in NewEngland: usa2/route_3, 46 shots, X mirrored.");
					}
					catch (Exception ex)
					{
						if ((Object)(object)val2 != (Object)null)
						{
							Object.Destroy((Object)(object)val2);
						}
						instance = null;
						requested = false;
						buttonDirty = true;
						Logger.LogError((object)("Could not create CamSets: " + ex));
					}
				}
			}
		}

		private void RemoveSet()
		{
			if (!((Object)(object)instance == (Object)null))
			{
				((Behaviour)instance).enabled = false;
				((Component)instance).gameObject.SetActive(false);
				Object.Destroy((Object)(object)((Component)instance).gameObject);
				instance = null;
			}
		}

		private void OnDisable()
		{
			requested = false;
			RemoveSet();
			if (button != null)
			{
				WristMenuAPI.Buttons.Remove(button);
				button = null;
			}
			buttonDirty = true;
		}
	}
}
namespace JerryCamSets
{
	public sealed class IntroGifPlayer : MonoBehaviour
	{
		public RawImage target;

		public Texture2D[] atlases;

		public float[] frameDurations;

		public float playbackDuration = 9.2f;

		public int columns = 4;

		public int rows = 4;

		public int frameWidth = 480;

		public int frameHeight = 270;

		public int padding = 2;

		private float[] frameEnds;

		private float sourceDuration;

		private float startedAt;

		private int frame;

		private int shownFrame = -1;

		private void Awake()
		{
			if ((Object)(object)target == (Object)null)
			{
				target = ((Component)this).GetComponent<RawImage>();
			}
			if (frameDurations != null && frameDurations.Length != 0)
			{
				frameEnds = new float[frameDurations.Length];
				for (int i = 0; i < frameEnds.Length; i++)
				{
					sourceDuration += Mathf.Max(0.01f, frameDurations[i]);
					frameEnds[i] = sourceDuration;
				}
			}
		}

		private void OnEnable()
		{
			startedAt = Time.unscaledTime;
			frame = 0;
			shownFrame = -1;
			ShowFrame(0);
		}

		private void Update()
		{
			if (frameEnds != null && !(sourceDuration <= 0f))
			{
				float num = (Time.unscaledTime - startedAt) * sourceDuration / Mathf.Max(0.01f, playbackDuration);
				while (frame < frameEnds.Length - 1 && num >= frameEnds[frame])
				{
					frame++;
				}
				ShowFrame(frame);
			}
		}

		private void ShowFrame(int index)
		{
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)target == (Object)null) && atlases != null && columns > 0 && rows > 0 && index != shownFrame)
			{
				int num = columns * rows;
				int num2 = index / num;
				int num3 = index % num;
				if (num2 < atlases.Length && !((Object)(object)atlases[num2] == (Object)null))
				{
					Texture2D val = atlases[num2];
					float num4 = num3 % columns * (frameWidth + 2 * padding) + padding;
					float num5 = num3 / columns * (frameHeight + 2 * padding) + padding;
					target.texture = (Texture)(object)val;
					target.uvRect = new Rect(num4 / (float)((Texture)val).width, 1f - (num5 + (float)frameHeight) / (float)((Texture)val).height, (float)frameWidth / (float)((Texture)val).width, (float)frameHeight / (float)((Texture)val).height);
					shownFrame = index;
				}
			}
		}
	}
}
public class DemoScript : MonoBehaviour
{
	private enum RotationAxes
	{
		MouseXAndY,
		MouseX,
		MouseY
	}

	public List<GameObject> Mirrors;

	public GameObject LightBulb;

	public Toggle RecursionToggle;

	private float rotationModifier = -1f;

	private float moveModifier = 1f;

	private Material lightBulbMaterial;

	private RotationAxes axes = RotationAxes.MouseXAndY;

	private float sensitivityX = 15f;

	private float sensitivityY = 15f;

	private float minimumX = -360f;

	private float maximumX = 360f;

	private float minimumY = -60f;

	private float maximumY = 60f;

	private float rotationX = 0f;

	private float rotationY = 0f;

	private Quaternion originalRotation;

	private void Start()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		originalRotation = ((Component)this).transform.localRotation;
		Renderer component = LightBulb.GetComponent<Renderer>();
		if (Application.isPlaying)
		{
			component.sharedMaterial = component.material;
		}
		lightBulbMaterial = component.sharedMaterial;
	}

	private void Update()
	{
		RotateMirror();
		MoveLightBulb();
		UpdateMouseLook();
		UpdateMovement();
	}

	public void MirrorRecursionToggled()
	{
		ChangeMirrorRecursion();
	}

	public void ChangeMirrorRecursion()
	{
		foreach (GameObject mirror in Mirrors)
		{
			MirrorScript component = mirror.GetComponent<MirrorScript>();
			component.MirrorRecursion = RecursionToggle.isOn;
		}
	}

	private void UpdateMovement()
	{
		float num = 4f * Time.deltaTime;
		if (Input.GetKey((KeyCode)119))
		{
			((Component)this).transform.Translate(0f, 0f, num);
		}
		else if (Input.GetKey((KeyCode)115))
		{
			((Component)this).transform.Translate(0f, 0f, 0f - num);
		}
		if (Input.GetKey((KeyCode)97))
		{
			((Component)this).transform.Translate(0f - num, 0f, 0f);
		}
		else if (Input.GetKey((KeyCode)100))
		{
			((Component)this).transform.Translate(num, 0f, 0f);
		}
		if (Input.GetKeyDown((KeyCode)109))
		{
			RecursionToggle.isOn = !RecursionToggle.isOn;
		}
	}

	private void RotateMirror()
	{
		//IL_0014: 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_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = Mirrors[0];
		Quaternion rotation = val.transform.rotation;
		float y = ((Quaternion)(ref rotation)).eulerAngles.y;
		if (y > 65f && y < 100f)
		{
			rotationModifier = 0f - rotationModifier;
			y -= 65f;
			val.transform.Rotate(0f, 0f - y, 0f);
		}
		else if (y > 100f && y < 295f)
		{
			rotationModifier = 0f - rotationModifier;
			y = 295f - y;
			val.transform.Rotate(0f, y, 0f);
		}
		else
		{
			val.transform.Rotate(0f, rotationModifier * Time.deltaTime * 20f, 0f);
		}
	}

	private void MoveLightBulb()
	{
		//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_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		float x = LightBulb.transform.position.x;
		if (x > 5f)
		{
			moveModifier = 0f - moveModifier;
			x = 5f;
		}
		else if (x < -5f)
		{
			moveModifier = 0f - moveModifier;
			x = -5f;
		}
		else
		{
			x += Time.deltaTime * moveModifier;
		}
		Light component = LightBulb.GetComponent<Light>();
		LightBulb.transform.position = new Vector3(x, LightBulb.transform.position.y, LightBulb.transform.position.z);
		float num = Mathf.Min(1f, component.intensity);
		lightBulbMaterial.SetColor("_EmissionColor", new Color(num, num, num));
	}

	private void UpdateMouseLook()
	{
		//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_0093: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: 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_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		if (axes == RotationAxes.MouseXAndY)
		{
			rotationX += Input.GetAxis("Mouse X") * sensitivityX;
			rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
			rotationX = ClampAngle(rotationX, minimumX, maximumX);
			rotationY = ClampAngle(rotationY, minimumY, maximumY);
			Quaternion val = Quaternion.AngleAxis(rotationX, Vector3.up);
			Quaternion val2 = Quaternion.AngleAxis(rotationY, -Vector3.right);
			((Component)this).transform.localRotation = originalRotation * val * val2;
		}
		else if (axes == RotationAxes.MouseX)
		{
			rotationX += Input.GetAxis("Mouse X") * sensitivityX;
			rotationX = ClampAngle(rotationX, minimumX, maximumX);
			Quaternion val3 = Quaternion.AngleAxis(rotationX, Vector3.up);
			((Component)this).transform.localRotation = originalRotation * val3;
		}
		else
		{
			rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
			rotationY = ClampAngle(rotationY, minimumY, maximumY);
			Quaternion val4 = Quaternion.AngleAxis(0f - rotationY, Vector3.right);
			((Component)this).transform.localRotation = originalRotation * val4;
		}
	}

	public static float ClampAngle(float angle, float min, float max)
	{
		if (angle < -360f)
		{
			angle += 360f;
		}
		if (angle > 360f)
		{
			angle -= 360f;
		}
		return Mathf.Clamp(angle, min, max);
	}
}
public class MirrorCameraScript : MonoBehaviour
{
	public GameObject MirrorObject;

	public bool VRMode;

	public bool FlipLookDirection = true;

	public bool UseMirrorUp = true;

	[Range(0.5f, 2f)]
	public float FOVScale = 1f;

	public Vector2 UVScale = Vector2.one;

	public Vector2 UVOffset = Vector2.zero;

	public float FOVMul = 2f;

	public bool UseStandardProjection = false;

	[Range(0.0001f, 0.5f)]
	public float NearPlaneOffset = 0.01f;

	public bool debug_ForceCullingMaskAll = false;

	private Renderer mirrorRenderer;

	private Material mirrorMaterial;

	private MirrorScript mirrorScript;

	private Camera cameraObject;

	private RenderTexture reflectionTexture;

	private int oldReflectionTextureSize;

	private static bool renderingMirror;

	private MaterialPropertyBlock propertyBlock;

	private void Start()
	{
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Expected O, but got Unknown
		mirrorScript = ((Component)this).GetComponentInParent<MirrorScript>();
		cameraObject = ((Component)this).GetComponent<Camera>();
		cameraObject.stereoTargetEye = (StereoTargetEyeMask)0;
		if (mirrorScript.AddFlareLayer)
		{
			((Component)cameraObject).gameObject.AddComponent<FlareLayer>();
		}
		mirrorRenderer = MirrorObject.GetComponent<Renderer>();
		if (Application.isPlaying)
		{
			Material[] sharedMaterials = mirrorRenderer.sharedMaterials;
			foreach (Material val in sharedMaterials)
			{
				if (((Object)val).name == "MirrorMaterial")
				{
					mirrorRenderer.sharedMaterial = val;
					break;
				}
			}
		}
		mirrorMaterial = mirrorRenderer.sharedMaterial;
		propertyBlock = new MaterialPropertyBlock();
		CreateRenderTexture();
	}

	private void CreateRenderTexture()
	{
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Expected O, but got Unknown
		if ((Object)(object)reflectionTexture == (Object)null || oldReflectionTextureSize != mirrorScript.TextureSize)
		{
			if (Object.op_Implicit((Object)(object)reflectionTexture))
			{
				Object.DestroyImmediate((Object)(object)reflectionTexture);
			}
			reflectionTexture = new RenderTexture(mirrorScript.TextureSize, mirrorScript.TextureSize, 16);
			((Texture)reflectionTexture).filterMode = (FilterMode)1;
			reflectionTexture.antiAliasing = 1;
			((Object)reflectionTexture).name = "MirrorRenderTexture_" + ((Object)this).GetInstanceID();
			((Object)reflectionTexture).hideFlags = (HideFlags)61;
			((Texture)reflectionTexture).wrapMode = (TextureWrapMode)1;
			mirrorMaterial.SetTexture("_MainTex", (Texture)(object)reflectionTexture);
			oldReflectionTextureSize = mirrorScript.TextureSize;
		}
		if ((Object)(object)cameraObject.targetTexture != (Object)(object)reflectionTexture)
		{
			cameraObject.targetTexture = reflectionTexture;
		}
	}

	private void Update()
	{
		//IL_005b: 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_00dc: Unknown result type (might be due to invalid IL or missing references)
		if (FOVScale > 1f)
		{
			FOVScale = 1f;
		}
		if (FOVScale < 0.01f)
		{
			FOVScale = 0.01f;
		}
		FOVScale = 1f / (FOVMul * Vector3.Distance(((Component)GM.CurrentMovementManager.Head).gameObject.transform.position, MirrorObject.transform.position));
		CreateRenderTexture();
		if ((Object)(object)mirrorRenderer != (Object)null)
		{
			mirrorRenderer.GetPropertyBlock(propertyBlock);
			propertyBlock.SetVector("_UVScaleOffset", new Vector4(UVScale.x, UVScale.y, UVOffset.x, UVOffset.y));
			mirrorRenderer.SetPropertyBlock(propertyBlock);
		}
	}

	private void OnDrawGizmos()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: 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_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)MirrorObject == (Object)null))
		{
			Gizmos.color = Color.blue;
			Vector3 position = MirrorObject.transform.position;
			Vector3 val = ((!((Object)(object)mirrorScript != (Object)null) || !mirrorScript.NormalIsForward) ? MirrorObject.transform.up : MirrorObject.transform.forward);
			Gizmos.DrawRay(position, val * 0.5f);
		}
	}

	private void UpdateCameraProperties(Camera src, Camera dest)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Invalid comparison between Unknown and I4
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		dest.clearFlags = src.clearFlags;
		dest.backgroundColor = src.backgroundColor;
		if ((int)src.clearFlags == 1)
		{
			Skybox component = ((Component)src).GetComponent<Skybox>();
			Skybox component2 = ((Component)dest).GetComponent<Skybox>();
			if ((Object)(object)component != (Object)null && (Object)(object)component.material != (Object)null)
			{
				((Behaviour)component2).enabled = true;
				component2.material = component.material;
			}
			else
			{
				((Behaviour)component2).enabled = false;
			}
		}
		dest.orthographic = src.orthographic;
		dest.orthographicSize = src.orthographicSize;
		dest.aspect = src.aspect;
		dest.renderingPath = src.renderingPath;
	}

	internal void RenderMirror()
	{
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Invalid comparison between Unknown and I4
		//IL_0105: 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_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: 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_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: 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_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: 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_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0207: 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_0219: 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_021d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0238: 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_01e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_029b: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: 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_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ab: 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_02b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02be: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c5: 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_02da: 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_02de: Unknown result type (might be due to invalid IL or missing references)
		Camera current = Camera.current;
		if (renderingMirror || !((Behaviour)this).enabled || (Object)(object)current == (Object)null || (Object)(object)mirrorRenderer == (Object)null || (Object)(object)mirrorMaterial == (Object)null || !mirrorRenderer.enabled)
		{
			return;
		}
		if (VRMode)
		{
			if ((int)current.stereoActiveEye == 1)
			{
				return;
			}
			mirrorMaterial.EnableKeyword("MIRROR_RECURSION");
		}
		else
		{
			mirrorMaterial.DisableKeyword("MIRROR_RECURSION");
		}
		renderingMirror = true;
		int pixelLightCount = QualitySettings.pixelLightCount;
		if (QualitySettings.pixelLightCount != mirrorScript.MaximumPerPixelLights)
		{
			QualitySettings.pixelLightCount = mirrorScript.MaximumPerPixelLights;
		}
		try
		{
			Camera val = ((!VRMode) ? current : Camera.main);
			UpdateCameraProperties(val, cameraObject);
			Vector3 position = MirrorObject.transform.position;
			Vector3 val2 = ((!mirrorScript.NormalIsForward) ? MirrorObject.transform.up : MirrorObject.transform.forward);
			Vector3 normalized = ((Vector3)(ref val2)).normalized;
			float num = 0f - Vector3.Dot(normalized, position);
			Vector3 position2 = ((Component)val).transform.position;
			float num2 = Vector3.Dot(normalized, position2) + num;
			Vector3 val3 = position2 - 2f * num2 * normalized;
			((Component)cameraObject).transform.position = val3;
			Vector3 val4 = position - val3;
			Vector3 val5 = ((Vector3)(ref val4)).normalized;
			if (FlipLookDirection)
			{
				val5 = -val5;
			}
			Vector3 val6 = ((!UseMirrorUp) ? Vector3.up : ((!mirrorScript.NormalIsForward) ? MirrorObject.transform.forward : MirrorObject.transform.up));
			((Component)cameraObject).transform.rotation = Quaternion.LookRotation(val5, val6);
			cameraObject.worldToCameraMatrix = ((Component)cameraObject).transform.worldToLocalMatrix;
			if (UseStandardProjection)
			{
				cameraObject.ResetProjectionMatrix();
				cameraObject.fieldOfView = val.fieldOfView * FOVScale;
			}
			else
			{
				float num3 = val.fieldOfView * FOVScale;
				Matrix4x4 projection = Matrix4x4.Perspective(num3, val.aspect, val.nearClipPlane, val.farClipPlane);
				Vector3 pos = position + normalized * NearPlaneOffset;
				Vector4 clipPlane = CameraSpacePlane(cameraObject.worldToCameraMatrix, pos, normalized, 1f);
				cameraObject.projectionMatrix = CalculateObliqueMatrix(projection, clipPlane);
			}
			if (debug_ForceCullingMaskAll)
			{
				cameraObject.cullingMask = -1;
			}
			else
			{
				cameraObject.cullingMask = -17 & ((LayerMask)(ref mirrorScript.ReflectLayers)).value;
			}
			cameraObject.farClipPlane = mirrorScript.FarClipPlane;
			GL.invertCulling = true;
			cameraObject.Render();
			GL.invertCulling = false;
		}
		finally
		{
			renderingMirror = false;
			if (QualitySettings.pixelLightCount != pixelLightCount)
			{
				QualitySettings.pixelLightCount = pixelLightCount;
			}
		}
	}

	private void OnDisable()
	{
		if (Object.op_Implicit((Object)(object)reflectionTexture))
		{
			Object.DestroyImmediate((Object)(object)reflectionTexture);
			reflectionTexture = null;
		}
	}

	private Vector4 CameraSpacePlane(Matrix4x4 worldToCameraMatrix, Vector3 pos, Vector3 normal, float sideSign)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: 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_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: 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_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: 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)
		Vector3 val = ((Matrix4x4)(ref worldToCameraMatrix)).MultiplyPoint(pos);
		Vector3 val2 = ((Matrix4x4)(ref worldToCameraMatrix)).MultiplyVector(normal);
		Vector3 val3 = ((Vector3)(ref val2)).normalized * sideSign;
		return new Vector4(val3.x, val3.y, val3.z, 0f - Vector3.Dot(val, val3));
	}

	private Matrix4x4 CalculateObliqueMatrix(Matrix4x4 projection, Vector4 clipPlane)
	{
		//IL_0003: 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_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00b4: Unknown result type (might be due to invalid IL or missing references)
		Vector4 val = ((Matrix4x4)(ref projection)).inverse * new Vector4(Mathf.Sign(clipPlane.x), Mathf.Sign(clipPlane.y), 1f, 1f);
		Vector4 val2 = clipPlane * (2f / Vector4.Dot(clipPlane, val));
		((Matrix4x4)(ref projection))[2] = val2.x - ((Matrix4x4)(ref projection))[3];
		((Matrix4x4)(ref projection))[6] = val2.y - ((Matrix4x4)(ref projection))[7];
		((Matrix4x4)(ref projection))[10] = val2.z - ((Matrix4x4)(ref projection))[11];
		((Matrix4x4)(ref projection))[14] = val2.w - ((Matrix4x4)(ref projection))[15];
		return projection;
	}
}
public class MirrorReflectionScript : MonoBehaviour
{
	private MirrorCameraScript childScript;

	private void Start()
	{
		childScript = ((Component)((Component)this).gameObject.transform.parent).gameObject.GetComponentInChildren<MirrorCameraScript>();
		if ((Object)(object)childScript == (Object)null)
		{
			Debug.LogError((object)"Child script (MirrorCameraScript) should be in sibling object");
		}
	}

	private void OnWillRenderObject()
	{
		childScript.RenderMirror();
	}
}
public class MirrorScript : MonoBehaviour
{
	[Tooltip("Maximum number of per pixel lights that will show in the mirrored image")]
	public int MaximumPerPixelLights = 2;

	[Tooltip("Texture size for the mirror, depending on how close the player can get to the mirror, this will need to be larger")]
	public int TextureSize = 768;

	[Tooltip("Subtracted from the near plane of the mirror")]
	public float ClipPlaneOffset = 0.07f;

	[Tooltip("Far clip plane for mirro camera")]
	public float FarClipPlane = 1000f;

	[Tooltip("What layers will be reflected?")]
	public LayerMask ReflectLayers = LayerMask.op_Implicit(-1);

	[Tooltip("Add a flare layer to the reflection camera?")]
	public bool AddFlareLayer = false;

	[Tooltip("For quads, the normal points forward (true). For planes, the normal points up (false)")]
	public bool NormalIsForward = true;

	[Tooltip("Aspect ratio (width / height). Set to 0 to use default.")]
	public float AspectRatio = 0f;

	[Tooltip("Set to true if you have multiple mirrors facing each other to get an infinite effect, otherwise leave as false for a more realistic mirror effect.")]
	public bool MirrorRecursion;
}
[BepInPlugin("MeatKit", "MeatKit Plugin", "1.0.0")]
[BepInProcess("h3vr.exe")]
public class MeatKitPlugin : BaseUnityPlugin
{
	private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

	internal static ManualLogSource Logger;

	private void Awake()
	{
		Logger = ((BaseUnityPlugin)this).Logger;
		LoadAssets();
	}

	private void LoadAssets()
	{
	}
}
public class ReticleOverLayOnNV : PIPScopeGUIDrawer
{
	public Material uiMaterial;

	public Texture2D hostileTexture;

	public Color hostileColor = new Color(0.9f, 0.3f, 0.25f, 0.8f);

	public float iconSize = 32f;

	public float iconEdgeOffset = 8f;

	public bool scaleWithDistance = true;

	public Vector2 iconSizeMinMax = new Vector2(16f, 64f);

	public bool forceCircularBorder;

	public LaserLight laser;

	public override void DrawGUI(PIPScope scope, Canvas canvas, Vector2 canvasSize)
	{
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)GM.TNH_Manager == (Object)null)
		{
			return;
		}
		bool flag = (Object)(object)GM.TNH_Manager.CurHoldPoint != (Object)null;
		bool flag2 = (Object)(object)GM.TNH_Manager.TAHReticle != (Object)null;
		List<int> list = GM.TNH_Manager.ActiveSupplyPointIndicies();
		if (flag || list.Count != 0 || flag2)
		{
			float num = Mathf.Max(canvasSize.x, canvasSize.y);
			float num2 = Mathf.Min(canvasSize.x, canvasSize.y);
			Transform scopeTransform = ((scope.enableThermal && (Object)(object)scope.thermalScopeCam != (Object)null) ? ((Component)scope.thermalScopeCam).transform : ((Component)scope.scopeCam).transform);
			float num3 = ((!scope.enableThermal || !(scope.thermalOverlayFOV > 0f)) ? GetCameraFov((scope.enableThermal && (Object)(object)scope.thermalScopeCam != (Object)null) ? scope.thermalScopeCam.cam : scope.pipScopeCam.cam) : scope.thermalOverlayFOV);
			float degreesToPixels = num / num3;
			if (laser.IsActive)
			{
				uiMaterial.mainTexture = (Texture)(object)hostileTexture;
				uiMaterial.color = hostileColor;
				uiMaterial.SetPass(0);
				DrawTransformIcon(scope, scopeTransform, canvasSize, degreesToPixels, ((Component)laser.laserDot).gameObject.transform);
			}
		}
	}

	public float GetCameraFov(Camera cam)
	{
		if (cam.aspect > 1f)
		{
			return VerticalToHorizontalFOV(cam.fieldOfView, cam.aspect);
		}
		return cam.fieldOfView;
	}

	public void DrawIcon(Vector2 position, Vector2 size)
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		Matrix4x4 val = Matrix4x4.TRS(new Vector3(position.x - size.x * 0.5f, position.y - size.y * 0.5f, 0f), Quaternion.identity, new Vector3(size.x, size.y, 1f));
		Graphics.DrawMeshNow(PIPScopeGUIUtility.GetQuad(), val);
	}

	public void DrawTransformIcon(PIPScope scope, Transform scopeTransform, Vector2 canvasSize, float degreesToPixels, Transform t)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: 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_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//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_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_022d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: 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)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: 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)
		Matrix4x4 worldToLocalMatrix = scopeTransform.worldToLocalMatrix;
		Vector3 val = ((Matrix4x4)(ref worldToLocalMatrix)).MultiplyPoint3x4(t.position);
		Vector3 val2 = Vector3.Normalize(val);
		Quaternion val3 = Quaternion.LookRotation(val2);
		Vector3 eulerAngles = ((Quaternion)(ref val3)).eulerAngles;
		Vector2 val4 = EulerAngleToDirection(eulerAngles, degreesToPixels);
		float num = iconSize;
		if (scaleWithDistance)
		{
			num *= 25f;
			float magnitude = ((Vector3)(ref val)).magnitude;
			num /= Mathf.Max(0.001f, magnitude);
			num = Mathf.Clamp(num, iconSizeMinMax.x, iconSizeMinMax.y);
		}
		num = Mathf.Round(num * 0.5f) * 2f;
		if (scope.thermalOverlayCircular || forceCircularBorder)
		{
			float num2 = (Mathf.Min(canvasSize.x, canvasSize.y) - num) * 0.5f - iconEdgeOffset;
			float num3 = val4.x * val4.x + val4.y * val4.y;
			if (num3 > num2 * num2)
			{
				val4 *= num2 / Mathf.Sqrt(num3);
			}
		}
		else
		{
			Vector2 val5 = default(Vector2);
			((Vector2)(ref val5))..ctor((canvasSize.x - num) * 0.5f - iconEdgeOffset, (canvasSize.y - num) * 0.5f - iconEdgeOffset);
			if (Mathf.Abs(val4.x) > val5.x || Mathf.Abs(val4.y) > val5.y)
			{
				Vector2 normalized = ((Vector2)(ref val4)).normalized;
				float num4 = Vector2.Angle(Vector2.right, normalized);
				float num5 = Mathf.Abs(val5.y / Mathf.Cos((90f - num4) * ((float)Math.PI / 180f)));
				float num6 = Mathf.Abs(val5.x / Mathf.Sin((90f - num4) * ((float)Math.PI / 180f)));
				val4 = normalized * Mathf.Min(num5, num6);
			}
		}
		val4.x = Mathf.Round(val4.x);
		val4.y = Mathf.Round(val4.y);
		DrawIcon(val4, new Vector2(num, num));
	}

	public Vector2 EulerAngleToDirection(Vector3 eulerAngle, float degreesToPixels)
	{
		//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		Vector2 result = default(Vector2);
		((Vector2)(ref result))..ctor(eulerAngle.y, 0f - eulerAngle.x);
		result.x = Mathf.Repeat(result.x, 360f);
		result.y = Mathf.Repeat(result.y, 360f);
		if (result.x > 180f)
		{
			result.x -= 360f;
		}
		if (result.y > 180f)
		{
			result.y -= 360f;
		}
		result.x *= degreesToPixels;
		result.y *= degreesToPixels;
		return result;
	}

	public float VerticalToHorizontalFOV(float verticalFOV, float aspect)
	{
		return Mathf.Atan(Mathf.Tan(verticalFOV * 0.5f * ((float)Math.PI / 180f)) * aspect) * 2f * ((float)Math.PI / 180f);
	}
}