Decompiled source of Portals v1.6.0

Mods/Portals.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BoneLib;
using BoneLib.BoneMenu;
using HarmonyLib;
using Il2Cpp;
using Il2CppCysharp.Threading.Tasks;
using Il2CppInterop.Runtime.Attributes;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppInterop.Runtime.InteropTypes.Fields;
using Il2CppSLZ.Bonelab;
using Il2CppSLZ.Bonelab.SaveData;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.AI;
using Il2CppSLZ.Marrow.Audio;
using Il2CppSLZ.Marrow.Data;
using Il2CppSLZ.Marrow.Interaction;
using Il2CppSLZ.Marrow.Pool;
using Il2CppSLZ.Marrow.PuppetMasta;
using Il2CppSLZ.Marrow.Utilities;
using Il2CppSLZ.Marrow.Warehouse;
using Il2CppSLZ.VRMK;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using Portals;
using Portals.AssetWarehouse;
using Portals.MonoBehaviours;
using Portals.Pool;
using Portals.Rendering;
using Unity.XR.MockHMD;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.XR;
using UnityEngine.XR.Management;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(PortalsMod), "Portals", "1.6.0", "Lakatrazz", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyDescription("Adds portals that can connect two areas of space.")]
[assembly: AssemblyTitle("Portals")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.6.0.0")]
[module: UnverifiableCode]
namespace Portals
{
	public static class EmbeddedResource
	{
		public static byte[] LoadBytesFromAssembly(Assembly assembly, string name)
		{
			if (!assembly.GetManifestResourceNames().Contains(name))
			{
				MelonLogger.Warning("Failed to locate an embedded resource with path " + name + "!");
				return null;
			}
			MelonLogger.Msg("Loading embedded resource data " + name + "...", new object[1] { ConsoleColor.DarkCyan });
			using Stream stream = assembly.GetManifestResourceStream(name);
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			MelonLogger.Msg("Done!", new object[1] { ConsoleColor.DarkCyan });
			return memoryStream.ToArray();
		}

		public static Assembly LoadAssemblyFromAssembly(Assembly assembly, string name)
		{
			byte[] array = LoadBytesFromAssembly(assembly, name);
			if (array == null)
			{
				return null;
			}
			return Assembly.Load(array);
		}
	}
	public class PortalsMod : MelonMod
	{
		public const string Version = "1.6.0";

		public static Instance Logger { get; private set; }

		public static bool IsMockHMD { get; private set; }

		public static Assembly PortalsAssembly { get; private set; }

		public static bool HasFusion { get; private set; }

		public override void OnInitializeMelon()
		{
			Logger = ((MelonBase)this).LoggerInstance;
			PortalsAssembly = ((MelonBase)this).MelonAssembly.Assembly;
			Hooking.OnLevelLoaded += OnLevelLoaded;
			CheckFusion();
			PortalPreferences.SetupPreferences();
		}

		private static void CheckFusion()
		{
			if (MelonBase.FindMelon("LabFusion", "Lakatrazz") != null)
			{
				HasFusion = true;
				EmbeddedResource.LoadAssemblyFromAssembly(PortalsAssembly, "Portals.resources.PortalsModule.dll").GetType("PortalsModule.ModuleLoader").GetMethod("LoadModule")
					.Invoke(null, null);
			}
		}

		public override void OnLateInitializeMelon()
		{
			IsMockHMD = Object.op_Implicit((Object)(object)XRGeneralSettings.Instance.Manager.loaders.Find(Predicate<XRLoader>.op_Implicit((Func<XRLoader, bool>)((XRLoader loader) => (Object)(object)((Il2CppObjectBase)loader).TryCast<MockHMDLoader>() != (Object)null))));
		}

		public override void OnPreferencesLoaded()
		{
			PortalPreferences.LoadPreferences();
		}

		private void OnLevelLoaded(LevelInfo info)
		{
			CloneCreator.OnLevelLoaded();
		}
	}
	public static class PortalConstants
	{
		public static readonly Vector2 DefaultSize = new Vector2(1.22f, 2.44f);

		private static LayerMask _hitMask = default(LayerMask);

		private static bool _hasHitMask = false;

		public const int PortalLayer = 18;

		public const int TrackerLayer = 19;

		public static LayerMask HitMask
		{
			get
			{
				//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: 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_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: 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_0049: Unknown result type (might be due to invalid IL or missing references)
				//IL_0059: Unknown result type (might be due to invalid IL or missing references)
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_0097: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
				if (!_hasHitMask)
				{
					_hitMask = LayerMask.op_Implicit(-1);
					_hitMask = LayerMask.op_Implicit(LayerMask.op_Implicit(_hitMask) & -16777217);
					_hitMask = LayerMask.op_Implicit(LayerMask.op_Implicit(_hitMask) & -257);
					_hitMask = LayerMask.op_Implicit(LayerMask.op_Implicit(_hitMask) & -67108865);
					_hitMask = LayerMask.op_Implicit(LayerMask.op_Implicit(_hitMask) & -536870913);
					_hitMask = LayerMask.op_Implicit(LayerMask.op_Implicit(_hitMask) & -134217729);
					_hitMask = LayerMask.op_Implicit(LayerMask.op_Implicit(_hitMask) & -1073741825);
					_hitMask = LayerMask.op_Implicit(LayerMask.op_Implicit(_hitMask) & -268435457);
					_hitMask = LayerMask.op_Implicit(LayerMask.op_Implicit(_hitMask) & -9);
					_hasHitMask = true;
				}
				return _hitMask;
			}
		}
	}
	public static class PortalPreferences
	{
		private static float _renderScale;

		private static bool _renderVolumetrics;

		private static int _renderDistance;

		private static MelonPreferences_Category _preferencesCategory;

		private static MelonPreferences_Entry<bool> _renderViewPreference;

		private static MelonPreferences_Entry<float> _renderScalePreference;

		private static MelonPreferences_Entry<bool> _renderVolumetricsPreference;

		private static MelonPreferences_Entry<bool> _limitDistancePreference;

		private static MelonPreferences_Entry<int> _renderDistancePreference;

		private static MelonPreferences_Entry<int> _maxRecursionPreference;

		private static MelonPreferences_Entry<bool> _disableInFusionPreference;

		private static Page _portalsPage;

		private static BoolElement _renderViewElement;

		private static FloatElement _renderScaleElement;

		private static BoolElement _renderVolumetricsElement;

		private static BoolElement _limitDistanceElement;

		private static IntElement _renderDistanceElement;

		private static IntElement _maxRecursionElement;

		private static BoolElement _disableInFusionElement;

		private static bool _preferencesSetup;

		public static bool RenderView { get; private set; }

		public static float RenderScale
		{
			get
			{
				return _renderScale;
			}
			set
			{
				_renderScale = value;
				PortalPreferences.OnRenderScaleChanged?.Invoke(value);
			}
		}

		public static bool RenderVolumetrics
		{
			get
			{
				return _renderVolumetrics;
			}
			set
			{
				_renderVolumetrics = value;
				PortalPreferences.OnRenderVolumetricsChanged?.Invoke(value);
			}
		}

		public static bool LimitDistance { get; private set; }

		public static int RenderDistance
		{
			get
			{
				return _renderDistance;
			}
			set
			{
				_renderDistance = value;
			}
		}

		public static int MaxRecursion { get; private set; }

		public static bool DisableInFusion { get; private set; }

		public static event Action<float> OnRenderScaleChanged;

		public static event Action<bool> OnRenderVolumetricsChanged;

		public static void SetupPreferences()
		{
			bool flag = true;
			float num = 1f;
			bool flag2 = true;
			bool flag3 = true;
			int num2 = 25;
			int num3 = 1;
			bool flag4 = false;
			if (HelperMethods.IsAndroid())
			{
				num2 = 10;
			}
			_preferencesCategory = MelonPreferences.CreateCategory("Portals");
			_renderViewPreference = _preferencesCategory.CreateEntry<bool>("Render View", flag, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_renderScalePreference = _preferencesCategory.CreateEntry<float>("Render Scale", num, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_renderVolumetricsPreference = _preferencesCategory.CreateEntry<bool>("Render Volumetrics", flag2, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_limitDistancePreference = _preferencesCategory.CreateEntry<bool>("Limit Distance", flag3, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_renderDistancePreference = _preferencesCategory.CreateEntry<int>("Render Distance", num2, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			_maxRecursionPreference = _preferencesCategory.CreateEntry<int>("Max Recursion", num3, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			if (PortalsMod.HasFusion)
			{
				_disableInFusionPreference = _preferencesCategory.CreateEntry<bool>("Disable In Fusion", flag4, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			}
			_preferencesSetup = true;
			SetupBoneMenu();
			LoadPreferences();
		}

		public static void LoadPreferences()
		{
			if (_preferencesSetup)
			{
				RenderView = _renderViewPreference.Value;
				RenderScale = _renderScalePreference.Value;
				RenderVolumetrics = _renderVolumetricsPreference.Value;
				LimitDistance = _limitDistancePreference.Value;
				RenderDistance = _renderDistancePreference.Value;
				MaxRecursion = _maxRecursionPreference.Value;
				_renderViewElement.Value = RenderView;
				_renderScaleElement.Value = RenderScale;
				_limitDistanceElement.Value = LimitDistance;
				_renderDistanceElement.Value = RenderDistance;
				_maxRecursionElement.Value = MaxRecursion;
				if (PortalsMod.HasFusion)
				{
					DisableInFusion = _disableInFusionPreference.Value;
					_disableInFusionElement.Value = DisableInFusion;
				}
			}
		}

		private static void SetupBoneMenu()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: 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)
			_portalsPage = Page.Root.CreatePage("Portals", Color.cyan, 0, true);
			_renderViewElement = _portalsPage.CreateBool("Render View", Color.yellow, _renderViewPreference.Value, (Action<bool>)OnSetRenderView);
			_renderScaleElement = _portalsPage.CreateFloat("Render Scale", Color.yellow, _renderScalePreference.Value, 0.1f, 0.1f, 1f, (Action<float>)OnSetRenderScale);
			_renderVolumetricsElement = _portalsPage.CreateBool("Render Volumetrics", Color.cyan, _renderVolumetricsPreference.Value, (Action<bool>)OnSetRenderVolumetrics);
			_limitDistanceElement = _portalsPage.CreateBool("Limit Distance", Color.yellow, _limitDistancePreference.Value, (Action<bool>)OnSetLimitDistance);
			_renderDistanceElement = _portalsPage.CreateInt("Render Distance", Color.yellow, _renderDistancePreference.Value, 1, 1, 100, (Action<int>)OnSetRenderDistance);
			_maxRecursionElement = _portalsPage.CreateInt("Max Recursion", Color.yellow, _maxRecursionPreference.Value, 1, 1, 8, (Action<int>)OnSetMaxRecursion);
			if (PortalsMod.HasFusion)
			{
				_disableInFusionElement = _portalsPage.CreateBool("Disable In Fusion", Color.red, _disableInFusionPreference.Value, (Action<bool>)OnSetDisableInFusion);
			}
		}

		private static void OnSetRenderView(bool value)
		{
			RenderView = value;
			_renderViewPreference.Value = value;
			_preferencesCategory.SaveToFile(false);
		}

		private static void OnSetRenderScale(float value)
		{
			RenderScale = value;
			_renderScalePreference.Value = value;
			_preferencesCategory.SaveToFile(false);
		}

		private static void OnSetRenderVolumetrics(bool value)
		{
			RenderVolumetrics = value;
			_renderVolumetricsPreference.Value = value;
			_preferencesCategory.SaveToFile(false);
		}

		private static void OnSetLimitDistance(bool value)
		{
			LimitDistance = value;
			_limitDistancePreference.Value = value;
			_preferencesCategory.SaveToFile(false);
		}

		private static void OnSetRenderDistance(int value)
		{
			RenderDistance = value;
			_renderDistancePreference.Value = value;
			_preferencesCategory.SaveToFile(false);
		}

		private static void OnSetMaxRecursion(int value)
		{
			MaxRecursion = value;
			_maxRecursionPreference.Value = value;
			_preferencesCategory.SaveToFile(false);
		}

		private static void OnSetDisableInFusion(bool value)
		{
			DisableInFusion = value;
			_disableInFusionPreference.Value = value;
			_preferencesCategory.SaveToFile(false);
		}
	}
}
namespace Portals.Rendering
{
	public static class CloneCreator
	{
		private static GameObject _disabledCloningGameObject;

		private static Transform _disabledCloningTransform;

		public static Transform DisabledCloningTransform => _disabledCloningTransform;

		public static void OnLevelLoaded()
		{
			ValidateTempParent();
		}

		private static void ValidateTempParent()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if (!((Object)(object)_disabledCloningGameObject != (Object)null))
			{
				_disabledCloningGameObject = new GameObject("Disabled Cloning Parent");
				_disabledCloningGameObject.SetActive(false);
				_disabledCloningTransform = _disabledCloningGameObject.transform;
			}
		}

		public static CloneRenderer CreateCloneRenderer(GameObject reference)
		{
			CloneRenderer cloneRenderer = CreateCloneGameObject(reference).AddComponent<CloneRenderer>();
			cloneRenderer.Initialize(reference);
			return cloneRenderer;
		}

		private static GameObject CreateCloneGameObject(GameObject reference)
		{
			ValidateTempParent();
			GameObject obj = Object.Instantiate<GameObject>(reference, DisabledCloningTransform);
			obj.SetActive(false);
			obj.transform.parent = null;
			Strip(obj);
			((Object)obj).name = GetCloneName(((Object)reference).name);
			return obj;
		}

		private static string GetCloneName(string original)
		{
			return original + " (Portal Renderer)";
		}

		private static void Strip(GameObject root)
		{
			Il2CppArrayBase<Component> componentsInChildren = root.GetComponentsInChildren<Component>(true);
			for (int i = 0; i < 8; i++)
			{
				int num = 0;
				foreach (Component item in componentsInChildren)
				{
					if (!((Object)(object)item == (Object)null) && !Object.op_Implicit((Object)(object)((Il2CppObjectBase)item).TryCast<Transform>()))
					{
						num++;
						Object.DestroyImmediate((Object)(object)item);
					}
				}
				if (num <= 0)
				{
					break;
				}
			}
		}
	}
	public class PortalCamera
	{
		private RenderTexture _targetTexture;

		public Camera Camera { get; set; }

		public Transform Transform { get; set; }

		public GameObject GameObject { get; set; }

		public RenderTexture TargetTexture
		{
			get
			{
				return _targetTexture;
			}
			set
			{
				_targetTexture = value;
				Camera.targetTexture = value;
				this.OnTargetTextureChanged?.Invoke(value);
			}
		}

		public StereoscopicEye Eye { get; set; }

		public VolumetricRendering VolumetricRendering { get; set; }

		public event Action<RenderTexture> OnTargetTextureChanged;

		public PortalCamera(Portal portal, StereoscopicEye eye)
		{
			//IL_0013: 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_0036: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			GameObject = new GameObject($"{eye} Portal Camera");
			GameObject.SetActive(false);
			Transform = GameObject.transform;
			Transform.parent = ((Component)portal).transform;
			Camera = GameObject.AddComponent<Camera>();
			((Behaviour)Camera).enabled = false;
			Camera.useOcclusionCulling = false;
			Camera.allowHDR = true;
			Camera.allowMSAA = false;
			Camera.clearFlags = (CameraClearFlags)2;
			Camera.backgroundColor = Color.black;
			Camera.stereoTargetEye = (StereoTargetEyeMask)0;
			UniversalAdditionalCameraData obj = GameObject.AddComponent<UniversalAdditionalCameraData>();
			obj.antialiasing = (AntialiasingMode)0;
			obj.allowXRRendering = false;
			VolumetricRendering = VolumetricCreator.AddVolumetricRendering(Camera);
			GameObject.SetActive(true);
			GetDimensions();
			Eye = eye;
			PortalPreferences.OnRenderScaleChanged += OnRenderScaleChanged;
			PortalPreferences.OnRenderVolumetricsChanged += OnRenderVolumetricsChanged;
			OnRenderScaleChanged(PortalPreferences.RenderScale);
			OnRenderVolumetricsChanged(PortalPreferences.RenderVolumetrics);
		}

		public void ReleaseTexture()
		{
			if ((Object)(object)TargetTexture != (Object)null)
			{
				TargetTexture.Release();
				TargetTexture = null;
			}
		}

		private void OnRenderScaleChanged(float value)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			ReleaseTexture();
			(int width, int height) dimensions = GetDimensions();
			int item = dimensions.width;
			int item2 = dimensions.height;
			item = Mathf.RoundToInt((float)item * value);
			item2 = Mathf.RoundToInt((float)item2 * value);
			TargetTexture = new RenderTexture(item, item2, 24);
		}

		private void OnRenderVolumetricsChanged(bool value)
		{
			((Behaviour)VolumetricRendering).enabled = value;
		}

		private static (int width, int height) GetDimensions()
		{
			int num = XRSettings.eyeTextureWidth;
			int num2 = XRSettings.eyeTextureHeight;
			if (num <= 0 || num2 <= 0)
			{
				num = Screen.width;
				num2 = Screen.height;
			}
			return (num, num2);
		}

		public void Destroy()
		{
			PortalPreferences.OnRenderScaleChanged -= OnRenderScaleChanged;
			PortalPreferences.OnRenderVolumetricsChanged -= OnRenderVolumetricsChanged;
			Object.Destroy((Object)(object)GameObject);
			ReleaseTexture();
		}

		public void RenderCamera(ScriptableRenderContext context)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			UpdateVolumetrics();
			UniversalRenderPipeline.RenderSingleCamera(context, Camera);
		}

		private void UpdateVolumetrics()
		{
			if (PortalPreferences.RenderVolumetrics)
			{
				((Behaviour)Camera).enabled = true;
				try
				{
					VolumetricRendering.UpdateFunc();
				}
				catch (Exception ex)
				{
					PortalsMod.Logger.Error("Failed invoking VolumetricRendering.UpdateFunc!", ex);
				}
				((Behaviour)Camera).enabled = false;
			}
		}
	}
	public class PortalNearPlane
	{
		private Il2CppStructArray<Vector3> _frustumCorners = Il2CppStructArray<Vector3>.op_Implicit((Vector3[])(object)new Vector3[4]);

		private Vector3[] _vertices = (Vector3[])(object)new Vector3[5];

		public MeshFilter MeshFilter { get; set; }

		public MeshRenderer MeshRenderer { get; set; }

		public GameObject GameObject { get; set; }

		public Transform Transform { get; set; }

		public Mesh Mesh { get; set; }

		public Material Material { get; set; }

		public PortalNearPlane(Shader shader)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			GameObject = new GameObject("Portal Near Plane");
			Transform = GameObject.transform;
			MeshFilter = GameObject.AddComponent<MeshFilter>();
			MeshRenderer = GameObject.AddComponent<MeshRenderer>();
			Mesh = new Mesh();
			MeshFilter.sharedMesh = Mesh;
			Material = new Material(shader);
			((Renderer)MeshRenderer).sharedMaterial = Material;
		}

		public void Destroy()
		{
			Object.Destroy((Object)(object)GameObject);
		}

		public void Hide()
		{
			((Renderer)MeshRenderer).enabled = false;
		}

		public void Render(Portal portal, Camera camera, MonoOrStereoscopicEye eye)
		{
			//IL_0011: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_0082: Invalid comparison between Unknown and I4
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: 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_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: 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_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: 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_0086: 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_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_026e: 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_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0425: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0434: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0443: Unknown result type (might be due to invalid IL or missing references)
			//IL_0448: Unknown result type (might be due to invalid IL or missing references)
			//IL_044d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Unknown result type (might be due to invalid IL or missing references)
			//IL_045a: Unknown result type (might be due to invalid IL or missing references)
			//IL_045c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0461: Unknown result type (might be due to invalid IL or missing references)
			//IL_0469: Unknown result type (might be due to invalid IL or missing references)
			//IL_046b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0470: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Unknown result type (might be due to invalid IL or missing references)
			//IL_047a: Unknown result type (might be due to invalid IL or missing references)
			//IL_047f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0487: Unknown result type (might be due to invalid IL or missing references)
			//IL_0489: Unknown result type (might be due to invalid IL or missing references)
			//IL_048e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0496: Unknown result type (might be due to invalid IL or missing references)
			//IL_0498: Unknown result type (might be due to invalid IL or missing references)
			//IL_049d: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04de: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e0: 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_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: 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)
			//IL_0317: 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_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: 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_03c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0384: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_040a: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)portal).transform;
			Transform transform2 = ((Component)camera).transform;
			Plane val = default(Plane);
			((Plane)(ref val))..ctor(transform.forward, transform.position);
			float num = Mathf.Sign(((Plane)(ref val)).GetDistanceToPoint(transform2.position));
			float num2 = camera.nearClipPlane + 0.01f;
			camera.CalculateFrustumCorners(new Rect(0f, 0f, 1f, 1f), num2, (MonoOrStereoscopicEye)2, _frustumCorners);
			Matrix4x4 val2 = camera.worldToCameraMatrix;
			if ((int)eye == 0)
			{
				val2 = camera.GetStereoViewMatrix((StereoscopicEye)0);
			}
			else if ((int)eye == 1)
			{
				val2 = camera.GetStereoViewMatrix((StereoscopicEye)1);
			}
			Matrix4x4 inverse = ((Matrix4x4)(ref val2)).inverse;
			Vector3 val3 = ((Il2CppArrayBase<Vector3>)(object)_frustumCorners)[0];
			Vector3 val4 = ((Il2CppArrayBase<Vector3>)(object)_frustumCorners)[3];
			Vector3 val5 = ((Il2CppArrayBase<Vector3>)(object)_frustumCorners)[2];
			Vector3 val6 = ((Il2CppArrayBase<Vector3>)(object)_frustumCorners)[1];
			val3.z = 0f - val3.z;
			val4.z = 0f - val4.z;
			val5.z = 0f - val5.z;
			val6.z = 0f - val6.z;
			Vector3 val7 = ((Matrix4x4)(ref inverse)).MultiplyPoint(val3);
			Vector3 val8 = ((Matrix4x4)(ref inverse)).MultiplyPoint(val4);
			Vector3 val9 = ((Matrix4x4)(ref inverse)).MultiplyPoint(val5);
			Vector3 val10 = ((Matrix4x4)(ref inverse)).MultiplyPoint(val6);
			Vector3 val11 = val7;
			Vector3 position = (val7 + val8 + val9 + val10) / 4f;
			Transform.position = position;
			Transform.rotation = transform2.rotation;
			Vector3[] array = (Vector3[])(object)new Vector3[5] { val7, val8, val9, val10, val11 };
			bool flag = false;
			foreach (Vector3 val12 in array)
			{
				if (Mathf.Sign(((Plane)(ref val)).GetDistanceToPoint(val12)) != num)
				{
					flag = true;
				}
			}
			((Renderer)MeshRenderer).enabled = flag;
			if (!flag)
			{
				return;
			}
			Vector3[] array2 = (Vector3[])(object)new Vector3[5] { val7, val8, val9, val10, val11 };
			int[] array3 = new int[6] { 2, 1, 0, 3, 2, 0 };
			Ray val17 = default(Ray);
			float num8 = default(float);
			Ray val18 = default(Ray);
			float num9 = default(float);
			Ray val20 = default(Ray);
			float num11 = default(float);
			for (int j = 0; j < 4; j++)
			{
				int num3 = Mod(j - 1, 4);
				int num4 = Mod(j + 1, 4);
				Vector3 val13 = array2[num3];
				Vector3 val14 = array2[num4];
				Vector3 val15 = array2[j];
				float num5 = Mathf.Sign(((Plane)(ref val)).GetDistanceToPoint(val13));
				float num6 = Mathf.Sign(((Plane)(ref val)).GetDistanceToPoint(val14));
				float num7 = Mathf.Sign(((Plane)(ref val)).GetDistanceToPoint(val15));
				if (num7 != num)
				{
					continue;
				}
				bool flag2 = false;
				Vector3 val16;
				if (num7 != num5)
				{
					val16 = val13 - val15;
					((Ray)(ref val17))..ctor(val15, ((Vector3)(ref val16)).normalized);
					if (((Plane)(ref val)).Raycast(val17, ref num8))
					{
						array[j] = ((Ray)(ref val17)).origin + ((Ray)(ref val17)).direction * num8;
						flag2 = true;
					}
				}
				if (num7 != num6)
				{
					val16 = val14 - val15;
					((Ray)(ref val18))..ctor(val15, ((Vector3)(ref val16)).normalized);
					if (((Plane)(ref val)).Raycast(val18, ref num9))
					{
						int num10 = j;
						if (flag2)
						{
							num10 = 4;
							int[] obj = new int[9] { 2, 1, 0, 3, 2, 0, 0, 0, 4 };
							obj[6] = j;
							obj[7] = num4;
							array3 = obj;
						}
						array[num10] = ((Ray)(ref val18)).origin + ((Ray)(ref val18)).direction * num9;
						flag2 = true;
					}
				}
				if (flag2)
				{
					continue;
				}
				Vector3 val19 = array2[Mod(j + 2, 4)];
				if (Mathf.Sign(((Plane)(ref val)).GetDistanceToPoint(val19)) != num7)
				{
					val16 = val19 - val15;
					((Ray)(ref val20))..ctor(val15, ((Vector3)(ref val16)).normalized);
					if (((Plane)(ref val)).Raycast(val20, ref num11))
					{
						array[j] = ((Ray)(ref val20)).origin + ((Ray)(ref val20)).direction * num11;
						array[4] = array[j];
					}
				}
			}
			val7 = array[0];
			val8 = array[1];
			val9 = array[2];
			val10 = array[3];
			val11 = array[4];
			val7 = Transform.InverseTransformPoint(val7);
			val8 = Transform.InverseTransformPoint(val8);
			val9 = Transform.InverseTransformPoint(val9);
			val10 = Transform.InverseTransformPoint(val10);
			val11 = Transform.InverseTransformPoint(val11);
			_vertices[0] = val7;
			_vertices[1] = val8;
			_vertices[2] = val9;
			_vertices[3] = val10;
			_vertices[4] = val11;
			Mesh.SetVertices(Il2CppStructArray<Vector3>.op_Implicit(_vertices));
			Mesh.triangles = Il2CppStructArray<int>.op_Implicit(array3);
			Mesh.RecalculateBounds();
		}

		private static int Mod(int a, int b)
		{
			return a - b * Mathf.FloorToInt((float)a / (float)b);
		}
	}
	public static class PortalShaderConstants
	{
		public static readonly int LeftEyeTextureID = Shader.PropertyToID("_LeftEyeTexture");

		public static readonly int RightEyeTextureID = Shader.PropertyToID("_RightEyeTexture");

		public static readonly int MainTextureID = Shader.PropertyToID("_MainTex");

		public static readonly int TargetEyeID = Shader.PropertyToID("_TargetEye");

		public static readonly int ForceEyeID = Shader.PropertyToID("_ForceEye");

		public static readonly int EyeOverrideID = Shader.PropertyToID("_EyeOverride");

		public static readonly int OpenID = Shader.PropertyToID("_Open");

		public static readonly int OutlineID = Shader.PropertyToID("_Outline");

		public static readonly int InsideID = Shader.PropertyToID("_Inside");
	}
	public static class RenderingHooks
	{
		private static bool _hooked;

		private static Action<ScriptableRenderContext, Camera> _hook;

		public static event Action<ScriptableRenderContext, Camera> PreBeginCameraRendering;

		public static event Action<ScriptableRenderContext, Camera> BeginCameraRendering;

		public static void HookRenderPipeline()
		{
			UnHookRenderPipeline();
			_hook = Action<ScriptableRenderContext, Camera>.op_Implicit((Action<ScriptableRenderContext, Camera>)OnBeginCameraRendering);
			RenderPipelineManager.beginCameraRendering += _hook;
			_hooked = true;
		}

		public static void UnHookRenderPipeline()
		{
			if (_hooked)
			{
				RenderPipelineManager.beginCameraRendering -= _hook;
				_hooked = false;
				_hook = null;
			}
		}

		private static void OnBeginCameraRendering(ScriptableRenderContext context, Camera camera)
		{
			//IL_000b: 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)
			try
			{
				RenderingHooks.PreBeginCameraRendering?.Invoke(context, camera);
				RenderingHooks.BeginCameraRendering?.Invoke(context, camera);
			}
			catch (Exception ex)
			{
				PortalsMod.Logger.Error("Caught exception in OnBeginCameraRendering: ", ex);
			}
		}
	}
	public static class VolumetricCreator
	{
		public static VolumetricRendering GetPlayerVolumetricRendering()
		{
			return ((Component)Player.ControllerRig.headset).GetComponent<VolumetricRendering>();
		}

		public static void AssignComputeShaders(VolumetricRendering volumetricRendering)
		{
			VolumetricRendering playerVolumetricRendering = GetPlayerVolumetricRendering();
			volumetricRendering.FroxelFogCompute = playerVolumetricRendering.FroxelFogCompute;
			volumetricRendering.FroxelIntegrationCompute = playerVolumetricRendering.FroxelIntegrationCompute;
			volumetricRendering.ClipmapCompute = playerVolumetricRendering.ClipmapCompute;
			volumetricRendering.BlurCompute = playerVolumetricRendering.BlurCompute;
		}

		public static VolumetricRendering AddVolumetricRendering(Camera camera)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			VolumetricRendering obj = ((Component)camera).gameObject.AddComponent<VolumetricRendering>();
			obj.tempOffset = 0f;
			obj.cam = camera;
			obj.volumetricData = GetVolumetricData();
			obj.reprojectionAmount = 0.95f;
			obj.FroxelBlur = (BlurType)0;
			obj.SliceDistributionUniformity = 0.5f;
			obj.albedo = Color.white;
			obj.meanFreePath = 15f;
			obj.StaticLightMultiplier = 1f;
			AssignComputeShaders(obj);
			return obj;
		}

		public static VolumetricData GetVolumetricData()
		{
			if (HelperMethods.IsAndroid())
			{
				return GraphicsManager.QuestVolumetricRenderingSettings;
			}
			return GraphicsManager.PCVolumetricRenderingSettings;
		}
	}
}
namespace Portals.Pool
{
	public static class PortalEffectSpawner
	{
		public static void ShootProjectile(PortalProjectile.ProjectileData data)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_002c: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			SpawnableCrateReference portalProjectileReference = PortalCrateReferences.PortalProjectileReference;
			Spawnable val = new Spawnable
			{
				crateRef = portalProjectileReference,
				policyData = null
			};
			AssetSpawner.Register(val);
			UniTask<Poolee> val2 = AssetSpawner.SpawnAsync(val, data.Position, Quaternion.LookRotation(data.Direction), new Nullable<Vector3>(Vector3.one), (Transform)null, false, new Nullable<int>(0), (Action<GameObject>)null, (Action<GameObject>)null, (Action<GameObject>)null);
			Awaiter<Poolee> awaiter = val2.GetAwaiter();
			Action action = delegate
			{
				Poolee result = awaiter.GetResult();
				if (!((Object)(object)result == (Object)null))
				{
					((Component)result).GetComponent<PortalProjectile>().Fire(data);
				}
			};
			awaiter.OnCompleted(Action.op_Implicit(action));
		}

		public static void PlayImpactEffect(Vector3 position, Quaternion rotation, Color color)
		{
			//IL_0006: 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_0012: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			SpawnableCrateReference portalImpactReference = PortalCrateReferences.PortalImpactReference;
			Spawnable val = new Spawnable
			{
				crateRef = portalImpactReference,
				policyData = null
			};
			AssetSpawner.Register(val);
			UniTask<Poolee> val2 = AssetSpawner.SpawnAsync(val, position, rotation, new Nullable<Vector3>(Vector3.one), (Transform)null, false, new Nullable<int>(0), (Action<GameObject>)null, (Action<GameObject>)null, (Action<GameObject>)null);
			Awaiter<Poolee> awaiter = val2.GetAwaiter();
			Action action = delegate
			{
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				Poolee result = awaiter.GetResult();
				if ((Object)(object)result == (Object)null)
				{
					return;
				}
				foreach (ParticleSystem componentsInChild in ((Component)result).GetComponentsInChildren<ParticleSystem>())
				{
					componentsInChild.startColor = color;
					componentsInChild.Clear();
					componentsInChild.Play();
				}
			};
			awaiter.OnCompleted(Action.op_Implicit(action));
		}
	}
	public static class PortalSpawner
	{
		public class PortalSpawnInfo
		{
			public Vector3 Position { get; set; } = Vector3.zero;


			public Quaternion Rotation { get; set; } = Quaternion.identity;


			public Vector2 Size { get; set; } = PortalConstants.DefaultSize;


			public PortalShape Shape { get; set; } = PortalShape.ELLIPSE;


			public bool Primary { get; set; } = true;


			public int? ID { get; set; }

			public bool OneSided { get; set; } = true;


			public Action<Portal> SpawnCallback { get; set; }
		}

		public class PortalFizzleInfo
		{
			public bool Primary { get; set; }

			public bool Secondary { get; set; }

			public int ID { get; set; }
		}

		public class PortalPair
		{
			public Portal PrimaryPortal { get; set; }

			public Portal SecondaryPortal { get; set; }
		}

		public static readonly Dictionary<int, PortalPair> PortalLookup = new Dictionary<int, PortalPair>();

		public static bool Fizzle(PortalFizzleInfo info)
		{
			if (!PortalLookup.TryGetValue(info.ID, out var value))
			{
				return false;
			}
			bool result = false;
			if (info.Primary && Object.op_Implicit((Object)(object)value.PrimaryPortal))
			{
				value.PrimaryPortal.Fizzle();
				result = true;
			}
			if (info.Secondary && Object.op_Implicit((Object)(object)value.SecondaryPortal))
			{
				value.SecondaryPortal.Fizzle();
				result = true;
			}
			PortalLookup.Remove(info.ID);
			return result;
		}

		public static void Spawn(PortalSpawnInfo info)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			//IL_00b4: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			if (info.ID.HasValue && PortalLookup.TryGetValue(info.ID.Value, out var value))
			{
				Portal portal = (info.Primary ? value.PrimaryPortal : value.SecondaryPortal);
				if ((Object)(object)portal != (Object)null)
				{
					portal.Close();
				}
			}
			SpawnableCrateReference val = ((info.Shape != 0) ? PortalCrateReferences.PortalEllipseReference : PortalCrateReferences.PortalPlaneReference);
			SpawnableCrateReference crateRef = val;
			Spawnable val2 = new Spawnable
			{
				crateRef = crateRef,
				policyData = null
			};
			AssetSpawner.Register(val2);
			Vector3 val3 = default(Vector3);
			((Vector3)(ref val3))..ctor(info.Size.x, info.Size.y, 1f);
			UniTask<Poolee> val4 = AssetSpawner.SpawnAsync(val2, info.Position, info.Rotation, new Nullable<Vector3>(val3), (Transform)null, false, new Nullable<int>(0), (Action<GameObject>)null, (Action<GameObject>)null, (Action<GameObject>)null);
			Awaiter<Poolee> awaiter = val4.GetAwaiter();
			Action action = delegate
			{
				Poolee result = awaiter.GetResult();
				if (!((Object)(object)result == (Object)null))
				{
					Portal componentInChildren = ((Component)result).GetComponentInChildren<Portal>();
					componentInChildren.Primary = info.Primary;
					componentInChildren.OneSided = info.OneSided;
					if (info.ID.HasValue)
					{
						componentInChildren.ID = info.ID.Value;
						if (!PortalLookup.TryGetValue(info.ID.Value, out var value2))
						{
							value2 = new PortalPair();
						}
						if (info.Primary)
						{
							value2.PrimaryPortal = componentInChildren;
						}
						else
						{
							value2.SecondaryPortal = componentInChildren;
						}
						PortalLookup[info.ID.Value] = value2;
						if (Object.op_Implicit((Object)(object)value2.PrimaryPortal) && Object.op_Implicit((Object)(object)value2.SecondaryPortal))
						{
							value2.PrimaryPortal.OtherPortal = value2.SecondaryPortal;
							value2.SecondaryPortal.OtherPortal = value2.PrimaryPortal;
						}
					}
					info.SpawnCallback?.Invoke(componentInChildren);
				}
			};
			awaiter.OnCompleted(Action.op_Implicit(action));
		}
	}
}
namespace Portals.Patching
{
	[HarmonyPatch(typeof(Constrainer))]
	public static class ConstrainerPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("PrimaryButtonUp")]
		public static void PrimaryButtonUp(Constrainer __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)__instance.mode == 6 || (Object)(object)__instance._gO1 == (Object)null)
			{
				return;
			}
			MarrowBody mb = __instance._mb1;
			MarrowBody mb2 = __instance._mb2;
			if (!((Object)(object)mb == (Object)null) && !((Object)(object)mb2 == (Object)null))
			{
				TeleportableBody component = ((Component)mb).GetComponent<TeleportableBody>();
				TeleportableBody component2 = ((Component)mb2).GetComponent<TeleportableBody>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component2 == (Object)null))
				{
					component2.Pack(component);
				}
			}
		}
	}
	[HarmonyPatch(typeof(ConstraintTracker))]
	public static class ConstraintTrackerPatches
	{
		[HarmonyPrefix]
		[HarmonyPatch("DeleteConstraint")]
		public static void DeleteConstraint(ConstraintTracker __instance)
		{
			TeleportableBody component = ((Component)__instance).GetComponent<TeleportableBody>();
			if (!((Object)(object)component == (Object)null))
			{
				component.Unpack();
			}
		}
	}
	[HarmonyPatch(typeof(MarrowEntity))]
	public static class MarrowEntityPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		public static void Awake(MarrowEntity __instance)
		{
			RigManager componentInParent = ((Component)__instance).GetComponentInParent<RigManager>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				if ((Object)(object)__instance == (Object)(object)componentInParent.physicsRig.marrowEntity)
				{
					((Component)componentInParent).gameObject.AddComponent<TeleportableRigManager>();
				}
			}
			else if (Object.op_Implicit((Object)(object)((Component)__instance).GetComponentInChildren<PuppetMaster>()))
			{
				((Component)__instance).gameObject.AddComponent<TeleportablePuppetMaster>();
			}
			else
			{
				((Component)__instance).gameObject.AddComponent<TeleportableEntity>();
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("Pack")]
		public static void Pack(MarrowBody hostBody, MarrowBody parasiteBody)
		{
			TeleportableBody component = ((Component)hostBody).GetComponent<TeleportableBody>();
			if (!((Object)(object)component == (Object)null))
			{
				TeleportableBody component2 = ((Component)parasiteBody).GetComponent<TeleportableBody>();
				if (!((Object)(object)component2 == (Object)null))
				{
					component2.Pack(component);
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("Unpack")]
		public static void Unpack(MarrowBody hostBody, MarrowBody parasiteBody)
		{
			TeleportableBody component = ((Component)parasiteBody).GetComponent<TeleportableBody>();
			if (!((Object)(object)component == (Object)null))
			{
				component.Unpack();
			}
		}
	}
	[HarmonyPatch(typeof(OpenControllerRig))]
	public static class OpenControllerRigPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("OnMarrowReady")]
		private static void OnMarrowReady()
		{
			RenderingHooks.HookRenderPipeline();
		}
	}
	[HarmonyPatch(typeof(Projectile))]
	public static class ProjectilePatches
	{
		public static bool TeleportOnUpdate { get; set; }

		public static Portal TargetInPortal { get; set; }

		public static Portal TargetOutPortal { get; set; }

		[HarmonyPrefix]
		[HarmonyPatch("SetBulletObject")]
		public static void SetBulletObjectPrefix(Projectile __instance, ProjectileData data, Transform startTransform, Vector3 locPos, Quaternion locRot, Rigidbody EmittingRigidbody, TriggerRefProxy proxy)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)data == (Object)null)
			{
				return;
			}
			Gun componentInParent = ((Component)startTransform).GetComponentInParent<Gun>();
			if ((Object)(object)componentInParent == (Object)null)
			{
				return;
			}
			TeleportableEntity component = ((Component)componentInParent).GetComponent<TeleportableEntity>();
			if (!((Object)(object)component == (Object)null) && component.HasPortals)
			{
				float portalSign = component.GetPortalSign(component.InPortal, startTransform.position);
				if (component.PassedThrough(component.EnterSign, portalSign))
				{
					TeleportOnUpdate = true;
					TargetInPortal = component.InPortal;
					TargetOutPortal = component.OutPortal;
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch("Update")]
		public static void UpdatePrefix(Projectile __instance)
		{
			//IL_0030: 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_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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			if (TeleportOnUpdate)
			{
				TeleportOnUpdate = false;
				Teleport(__instance, TargetInPortal, TargetOutPortal);
				TargetInPortal = null;
				TargetOutPortal = null;
				return;
			}
			Vector3 position = ((Component)__instance).transform.position;
			Vector3 val = ((Component)__instance).transform.position + __instance._direction * __instance.currentSpeed * Time.deltaTime;
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Linecast(position, val, ref val2, 262144, (QueryTriggerInteraction)2) && ((RaycastHit)(ref val2)).collider.isTrigger)
			{
				Portal componentInParent = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<Portal>();
				if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent.OtherPortal != (Object)null)
				{
					Teleport(__instance, componentInParent, componentInParent.OtherPortal);
				}
			}
		}

		private static void Teleport(Projectile projectile, Portal inPortal, Portal outPortal)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			Matrix4x4 portalEnterMatrix = inPortal.PortalEnterMatrix;
			Matrix4x4 portalExitMatrix = outPortal.PortalExitMatrix;
			Matrix4x4 val = Matrix4x4.TRS(((Component)projectile).transform.position, Quaternion.LookRotation(projectile._direction), Vector3.one);
			Matrix4x4 val2 = ((Matrix4x4)(ref portalEnterMatrix)).inverse * val;
			Vector3 val3 = ((Matrix4x4)(ref val2)).GetPosition();
			Vector3 val4 = ((Matrix4x4)(ref val2)).rotation * Vector3.forward;
			Plane val5 = default(Plane);
			((Plane)(ref val5))..ctor(Vector3.forward, Vector3.zero);
			Ray val6 = default(Ray);
			((Ray)(ref val6))..ctor(val3, val4 * Mathf.Sign(val3.z));
			float num = default(float);
			if (((Plane)(ref val5)).Raycast(val6, ref num))
			{
				val3 += ((Ray)(ref val6)).direction * num;
			}
			val2 = Matrix4x4.TRS(val3, ((Matrix4x4)(ref val2)).rotation, ((Matrix4x4)(ref val2)).lossyScale);
			val = portalExitMatrix * val2;
			((Component)projectile).transform.position = ((Matrix4x4)(ref val)).GetPosition();
			projectile._direction = ((Matrix4x4)(ref val)).rotation * Vector3.forward;
			Vector3 lossyScale = ((Matrix4x4)(ref val)).lossyScale;
			projectile.Mass *= lossyScale.x * lossyScale.y * lossyScale.z;
			projectile.currentSpeed *= lossyScale.z;
			projectile.trail.Clear();
		}
	}
}
namespace Portals.MonoBehaviours
{
	[RegisterTypeInIl2Cpp]
	public class CloneRenderer : MonoBehaviour
	{
		private Transform _cloneTransform;

		private Transform _originalTransform;

		private List<SkinnedMeshRenderer> _originalSkinnedRenderers = new List<SkinnedMeshRenderer>();

		private Dictionary<SkinnedMeshRenderer, MeshRenderer> _skinnedToCloneRenderer = new Dictionary<SkinnedMeshRenderer, MeshRenderer>();

		private Dictionary<SkinnedMeshRenderer, MeshFilter> _skinnedToCloneFilter = new Dictionary<SkinnedMeshRenderer, MeshFilter>();

		private List<MeshRenderer> _originalMeshRenderers = new List<MeshRenderer>();

		private Dictionary<MeshRenderer, MeshRenderer> _originalToCloneMeshRenderer = new Dictionary<MeshRenderer, MeshRenderer>();

		public Transform CloneTransform => _cloneTransform;

		public Transform OriginalTransform => _originalTransform;

		public void Initialize(GameObject original)
		{
			_cloneTransform = ((Component)this).transform;
			_originalTransform = original.transform;
			GetRenderers(((Component)this).transform, original.transform);
		}

		private void GetRenderers(Transform clone, Transform original)
		{
			if (!Object.op_Implicit((Object)(object)((Component)original).GetComponentInChildren<Renderer>(true)))
			{
				Object.Destroy((Object)(object)((Component)clone).gameObject);
				return;
			}
			string name = ((Object)original).name;
			int num = name.LastIndexOf("_LOD");
			if (num != -1)
			{
				int num2 = num + 4;
				string text = name;
				int num3 = num2;
				if (int.TryParse(text.Substring(num3, text.Length - num3), out var result) && result > 0)
				{
					return;
				}
			}
			MeshFilter component = ((Component)original).GetComponent<MeshFilter>();
			MeshRenderer component2 = ((Component)original).GetComponent<MeshRenderer>();
			try
			{
				if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component2))
				{
					CopyMeshRenderer(clone, component2, component);
				}
			}
			catch
			{
			}
			SkinnedMeshRenderer component3 = ((Component)original).GetComponent<SkinnedMeshRenderer>();
			try
			{
				if (Object.op_Implicit((Object)(object)component3))
				{
					CopySkinnedMeshRenderer(clone, component3);
				}
			}
			catch
			{
			}
			for (int i = 0; i < clone.childCount; i++)
			{
				Transform child = clone.GetChild(i);
				Transform child2 = original.GetChild(i);
				((Component)child).gameObject.SetActive(true);
				GetRenderers(child, child2);
			}
		}

		private void CopyMeshRenderer(Transform clone, MeshRenderer renderer, MeshFilter filter)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (!IsMaterialBlacklisted(((Renderer)renderer).sharedMaterial))
			{
				((Component)clone).gameObject.AddComponent<MeshFilter>().sharedMesh = filter.sharedMesh;
				MeshRenderer val = ((Component)clone).gameObject.AddComponent<MeshRenderer>();
				((Renderer)val).shadowCastingMode = ((Renderer)renderer).shadowCastingMode;
				((Renderer)val).sharedMaterials = ((Renderer)renderer).sharedMaterials;
				((Renderer)val).enabled = ((Renderer)renderer).enabled;
				_originalMeshRenderers.Add(renderer);
				_originalToCloneMeshRenderer[renderer] = val;
			}
		}

		private void CopySkinnedMeshRenderer(Transform clone, SkinnedMeshRenderer renderer)
		{
			//IL_0040: 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
			if (!IsMaterialBlacklisted(((Renderer)renderer).sharedMaterial))
			{
				MeshFilter val = ((Component)clone).gameObject.AddComponent<MeshFilter>();
				MeshRenderer val2 = ((Component)clone).gameObject.AddComponent<MeshRenderer>();
				((Renderer)val2).sharedMaterials = ((Renderer)renderer).sharedMaterials;
				((Renderer)val2).enabled = ((Renderer)renderer).enabled;
				((Renderer)val2).shadowCastingMode = ((Renderer)renderer).shadowCastingMode;
				val.sharedMesh = new Mesh();
				_originalSkinnedRenderers.Add(renderer);
				_skinnedToCloneFilter[renderer] = val;
				_skinnedToCloneRenderer[renderer] = val2;
			}
		}

		private static bool IsMaterialBlacklisted(Material material)
		{
			if ((Object)(object)material == (Object)null)
			{
				return false;
			}
			if (((Object)material.shader).name == "SLZ/Icon Billboard")
			{
				return true;
			}
			return false;
		}

		public void Show()
		{
			((Component)this).gameObject.SetActive(true);
		}

		public void Hide()
		{
			((Component)this).gameObject.SetActive(false);
		}

		public void OnCloneUpdate()
		{
			OnUpdateMeshRenderers();
			OnUpdateSkinnedRenderers();
		}

		private void OnUpdateMeshRenderers()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
			foreach (MeshRenderer originalMeshRenderer in _originalMeshRenderers)
			{
				if (!((Object)(object)originalMeshRenderer == (Object)null))
				{
					MeshRenderer val = _originalToCloneMeshRenderer[originalMeshRenderer];
					if (CheckActive((Renderer)(object)val, (Renderer)(object)originalMeshRenderer))
					{
						((Renderer)val).shadowCastingMode = ((Renderer)originalMeshRenderer).shadowCastingMode;
						((Renderer)val).sharedMaterials = ((Renderer)originalMeshRenderer).sharedMaterials;
						Transform transform = ((Component)val).transform;
						Transform transform2 = ((Component)originalMeshRenderer).transform;
						Vector3 val2 = _cloneTransform.TransformPoint(_originalTransform.InverseTransformPoint(transform2.position));
						Quaternion val3 = _cloneTransform.rotation * (Quaternion.Inverse(_originalTransform.rotation) * transform2.rotation);
						transform.SetPositionAndRotation(val2, val3);
					}
				}
			}
		}

		private void OnUpdateSkinnedRenderers()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			foreach (SkinnedMeshRenderer originalSkinnedRenderer in _originalSkinnedRenderers)
			{
				if (!((Object)(object)originalSkinnedRenderer == (Object)null))
				{
					MeshRenderer val = _skinnedToCloneRenderer[originalSkinnedRenderer];
					if (CheckActive((Renderer)(object)val, (Renderer)(object)originalSkinnedRenderer))
					{
						MeshFilter val2 = _skinnedToCloneFilter[originalSkinnedRenderer];
						((Renderer)val).shadowCastingMode = ((Renderer)originalSkinnedRenderer).shadowCastingMode;
						((Renderer)val).sharedMaterials = ((Renderer)originalSkinnedRenderer).sharedMaterials;
						Transform transform = ((Component)val2).transform;
						Transform transform2 = ((Component)originalSkinnedRenderer).transform;
						Vector3 val3 = _cloneTransform.TransformPoint(_originalTransform.InverseTransformPoint(transform2.position));
						Quaternion val4 = _cloneTransform.rotation * (Quaternion.Inverse(_originalTransform.rotation) * transform2.rotation);
						transform.SetPositionAndRotation(val3, val4);
						originalSkinnedRenderer.BakeMesh(val2.mesh, true);
					}
				}
			}
		}

		private bool CheckActive(Renderer clone, Renderer original)
		{
			if (!((Component)original).gameObject.activeInHierarchy)
			{
				clone.enabled = false;
				return false;
			}
			if (!original.enabled)
			{
				clone.enabled = false;
				return false;
			}
			clone.enabled = true;
			return true;
		}
	}
	[RegisterTypeInIl2Cpp]
	public class Portal : MonoBehaviour
	{
		public Il2CppReferenceField<MonoBehaviour> otherPortal;

		public Il2CppReferenceField<MonoBehaviour> surface;

		public Il2CppReferenceField<MonoBehaviour> expander;

		public Il2CppValueField<Vector2> size;

		private Portal _otherPortal;

		private PortalSurface _surface;

		private PortalExpander _expander;

		private Vector2 _size = Vector2.zero;

		private Matrix4x4 _cachedEnterMatrix = Matrix4x4.identity;

		private Matrix4x4 _cachedEnterMatrixInverse = Matrix4x4.identity;

		private Matrix4x4 _cachedExitMatrix = Matrix4x4.identity;

		private Matrix4x4 _cachedExitMatrixInverse = Matrix4x4.identity;

		private PortalCamera _leftEyeCamera;

		private PortalCamera _rightEyeCamera;

		private PortalNearPlane _leftEyeNearPlane;

		private PortalNearPlane _rightEyeNearPlane;

		[HideFromIl2Cpp]
		public Portal OtherPortal
		{
			get
			{
				return _otherPortal;
			}
			set
			{
				bool flag = (Object)(object)OtherPortal != (Object)null;
				_otherPortal = value;
				bool flag2 = (Object)(object)value != (Object)null;
				Surface.Open = flag2;
				if (!flag2 && flag)
				{
					this.OnClosedEvent?.Invoke();
				}
			}
		}

		[HideFromIl2Cpp]
		public PortalSurface Surface => _surface;

		[HideFromIl2Cpp]
		public PortalExpander Expander => _expander;

		[HideFromIl2Cpp]
		public Vector2 Size => _size;

		[HideFromIl2Cpp]
		public Matrix4x4 PortalEnterMatrix => _cachedEnterMatrix;

		[HideFromIl2Cpp]
		public Matrix4x4 PortalEnterMatrixInverse => _cachedEnterMatrixInverse;

		[HideFromIl2Cpp]
		public Matrix4x4 PortalExitMatrix => _cachedExitMatrix;

		[HideFromIl2Cpp]
		public Matrix4x4 PortalExitMatrixInverse => _cachedExitMatrixInverse;

		[HideFromIl2Cpp]
		public Vector3 Velocity
		{
			get
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)ParentBody) || !ParentBody.HasRigidbody)
				{
					return Vector3.zero;
				}
				return ParentBody._rigidbody.GetPointVelocity(((Component)this).transform.position);
			}
		}

		[HideFromIl2Cpp]
		public Vector3 AngularVelocity
		{
			get
			{
				//IL_001a: 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)
				if (!Object.op_Implicit((Object)(object)ParentBody) || !ParentBody.HasRigidbody)
				{
					return Vector3.zero;
				}
				return ParentBody._rigidbody.angularVelocity;
			}
		}

		[HideFromIl2Cpp]
		public List<Collider> WallColliders { get; set; } = new List<Collider>();


		[HideFromIl2Cpp]
		public AudioClip[] FizzleSounds { get; set; }

		[HideFromIl2Cpp]
		public Poolee Poolee { get; set; }

		[HideFromIl2Cpp]
		public MarrowBody ParentBody { get; set; }

		[HideFromIl2Cpp]
		public int? ID { get; set; }

		[HideFromIl2Cpp]
		public bool Primary { get; set; }

		[HideFromIl2Cpp]
		public bool OneSided { get; set; } = true;


		[HideFromIl2Cpp]
		public event Action OnClosedEvent;

		public Portal(IntPtr intPtr)
			: base(intPtr)
		{
		}//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0017: 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_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)


		private void Awake()
		{
			//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)
			MonoBehaviour val = otherPortal.Get();
			if ((Object)(object)val != (Object)null)
			{
				OtherPortal = ((Il2CppObjectBase)val).TryCast<Portal>();
			}
			_surface = ((Il2CppObjectBase)surface.Get()).TryCast<PortalSurface>();
			_expander = ((Il2CppObjectBase)expander.Get()).TryCast<PortalExpander>();
			_size = size.Get();
			Expander.ToggleCollision(enabled: false);
		}

		private void Start()
		{
			foreach (Collider componentsInChild in ((Component)this).GetComponentsInChildren<Collider>())
			{
				if (componentsInChild.isTrigger)
				{
					((Component)componentsInChild).gameObject.layer = 18;
				}
			}
			_leftEyeCamera = new PortalCamera(this, (StereoscopicEye)0);
			_rightEyeCamera = new PortalCamera(this, (StereoscopicEye)1);
			_leftEyeNearPlane = new PortalNearPlane(Surface.AlwaysVisibleShader);
			_rightEyeNearPlane = new PortalNearPlane(Surface.AlwaysVisibleShader);
			_leftEyeNearPlane.Material.SetFloat(PortalShaderConstants.TargetEyeID, 0f);
			_rightEyeNearPlane.Material.SetFloat(PortalShaderConstants.TargetEyeID, 1f);
			_leftEyeCamera.OnTargetTextureChanged += OnLeftEyeTextureChanged;
			_rightEyeCamera.OnTargetTextureChanged += OnRightEyeTextureChanged;
			OnLeftEyeTextureChanged(_leftEyeCamera.TargetTexture);
			OnRightEyeTextureChanged(_rightEyeCamera.TargetTexture);
			Surface.CorridorRenderer.enabled = false;
			RenderingHooks.PreBeginCameraRendering += OnPreBeginCameraRendering;
			RenderingHooks.BeginCameraRendering += OnBeginCameraRendering;
			Poolee = ((Component)this).GetComponentInParent<Poolee>();
		}

		public void CollectWallColliders()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			WallColliders.Clear();
			if ((Object)(object)ParentBody != (Object)null)
			{
				foreach (Collider item in (Il2CppArrayBase<Collider>)(object)ParentBody.Colliders)
				{
					if ((Object)(object)item != (Object)null)
					{
						WallColliders.Add(item);
					}
				}
				return;
			}
			Vector3 position = ((Component)this).transform.position;
			Quaternion rotation = ((Component)this).transform.rotation;
			Vector3 lossyScale = ((Component)this).transform.lossyScale;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(Size.x * lossyScale.x, Size.y * lossyScale.y);
			foreach (Collider item2 in (Il2CppArrayBase<Collider>)(object)Physics.OverlapBox(position, new Vector3(val.x * 0.5f, val.y * 0.5f, 2f), rotation, LayerMask.op_Implicit(PortalConstants.HitMask), (QueryTriggerInteraction)1))
			{
				if (!Object.op_Implicit((Object)(object)item2.attachedRigidbody) && !Object.op_Implicit((Object)(object)((Component)item2).GetComponentInParent<Portal>()))
				{
					WallColliders.Add(item2);
				}
			}
		}

		private void LateUpdate()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)this).transform.position;
			Quaternion rotation = ((Component)this).transform.rotation;
			Vector3 flatScale = GetFlatScale(((Component)this).transform.lossyScale);
			_cachedEnterMatrix = Matrix4x4.TRS(position, rotation, flatScale);
			_cachedEnterMatrixInverse = ((Matrix4x4)(ref _cachedEnterMatrix)).inverse;
			_cachedExitMatrix = Matrix4x4.TRS(position, Quaternion.AngleAxis(180f, ((Component)this).transform.up) * rotation, flatScale);
			_cachedExitMatrixInverse = ((Matrix4x4)(ref _cachedExitMatrix)).inverse;
		}

		private void OnLeftEyeTextureChanged(RenderTexture texture)
		{
			Surface.SurfaceMaterial.SetTexture(PortalShaderConstants.LeftEyeTextureID, (Texture)(object)texture);
			_leftEyeNearPlane.Material.SetTexture(PortalShaderConstants.MainTextureID, (Texture)(object)texture);
		}

		private void OnRightEyeTextureChanged(RenderTexture texture)
		{
			Surface.SurfaceMaterial.SetTexture(PortalShaderConstants.RightEyeTextureID, (Texture)(object)texture);
			_rightEyeNearPlane.Material.SetTexture(PortalShaderConstants.MainTextureID, (Texture)(object)texture);
		}

		private void OnDisable()
		{
			if (Object.op_Implicit((Object)(object)OtherPortal))
			{
				OtherPortal.OtherPortal = null;
				OtherPortal = null;
			}
			Expander.ToggleCollision(enabled: false);
			FizzleSounds = null;
		}

		public void Close()
		{
			OtherPortal = null;
			Poolee.Despawn();
		}

		public void Fizzle()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			OtherPortal = null;
			if (FizzleSounds != null)
			{
				Audio3dManager.PlayAtPoint(Il2CppReferenceArray<AudioClip>.op_Implicit(FizzleSounds), ((Component)this).transform.position, Audio3dManager.hardInteraction, 0.6f, 1f, new Nullable<float>(0f), new Nullable<float>(0.4f), new Nullable<float>(1f));
			}
			Poolee.Despawn();
		}

		private void OnDestroy()
		{
			_leftEyeNearPlane.Destroy();
			_rightEyeNearPlane.Destroy();
			_leftEyeCamera.Destroy();
			_rightEyeCamera.Destroy();
			RenderingHooks.PreBeginCameraRendering -= OnPreBeginCameraRendering;
			RenderingHooks.BeginCameraRendering -= OnBeginCameraRendering;
		}

		private Vector3 GetFlatScale(Vector3 scale)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: 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)
			scale.z = Math.Min(scale.x, scale.y);
			return scale;
		}

		public bool HasCamera(Camera cam)
		{
			if (!((Object)(object)cam == (Object)(object)_leftEyeCamera.Camera))
			{
				return (Object)(object)cam == (Object)(object)_rightEyeCamera.Camera;
			}
			return true;
		}

		private void OnPreBeginCameraRendering(ScriptableRenderContext context, Camera camera)
		{
			_leftEyeNearPlane.Hide();
			_rightEyeNearPlane.Hide();
			Surface.CorridorRenderer.enabled = false;
			Surface.FrontRenderer.enabled = true;
			Surface.BackRenderer.enabled = !OneSided;
		}

		private void OnBeginCameraRendering(ScriptableRenderContext context, Camera camera)
		{
			//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)
			//IL_00b6: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			if (!PortalPreferences.RenderView)
			{
				Surface.SurfaceMaterial.SetFloat(PortalShaderConstants.OpenID, 0f);
			}
			else
			{
				if (!Object.op_Implicit((Object)(object)OtherPortal) || HasCamera(camera) || OtherPortal.HasCamera(camera) || Object.op_Implicit((Object)(object)camera.targetTexture) || camera.orthographic || ((Object)(object)Surface.FrontRenderer != (Object)null && !Surface.FrontRenderer.isVisible && !Surface.BackRenderer.isVisible))
				{
					return;
				}
				float num = 1f;
				if (PortalPreferences.LimitDistance)
				{
					Vector3 lossyScale = ((Component)this).transform.lossyScale;
					Vector2 val = default(Vector2);
					((Vector2)(ref val))..ctor(lossyScale.x * Size.x, lossyScale.y * Size.y);
					float num2 = Math.Max(val.x, val.y);
					Vector3 val2 = ((Component)camera).transform.position - ((Component)this).transform.position;
					float magnitude = ((Vector3)(ref val2)).magnitude;
					num = 1f - Math.Clamp(Math.Max(0f, magnitude - num2) / Math.Max(num2, (float)PortalPreferences.RenderDistance - num2), 0f, 1f);
					if (num <= 0f)
					{
						Surface.SurfaceMaterial.SetFloat(PortalShaderConstants.OpenID, 0f);
						return;
					}
				}
				int maxRecursion = PortalPreferences.MaxRecursion;
				int num3 = maxRecursion - 1;
				float num4 = num * Surface.OpenPercent;
				for (int num5 = num3; num5 >= 0; num5--)
				{
					float num6 = 0f;
					if (maxRecursion > 1)
					{
						num6 = num4 * (1f - Math.Clamp((float)num5 / (float)num3, 0f, 1f));
					}
					Surface.SurfaceMaterial.SetFloat(PortalShaderConstants.OpenID, num6);
					ApplyPosition(context, camera, num5);
				}
				Surface.SurfaceMaterial.SetFloat(PortalShaderConstants.OpenID, num4);
				DrawClippingPlane(camera);
			}
		}

		private void ApplyPosition(ScriptableRenderContext context, Camera mainCamera, int iteration = 0)
		{
			//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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: 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_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: 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_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_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_018f: 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_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)mainCamera).transform;
			Transform transform2 = ((Component)OtherPortal).transform;
			Vector3 val = transform.position;
			Quaternion val2 = transform.rotation;
			for (int i = 0; i <= iteration; i++)
			{
				Matrix4x4 val3 = OtherPortal.PortalExitMatrix;
				Matrix4x4 portalEnterMatrixInverse = PortalEnterMatrixInverse;
				val = ((Matrix4x4)(ref val3)).MultiplyPoint3x4(((Matrix4x4)(ref portalEnterMatrixInverse)).MultiplyPoint3x4(val));
				val3 = OtherPortal.PortalExitMatrix;
				Quaternion rotation = ((Matrix4x4)(ref val3)).rotation;
				val3 = PortalEnterMatrixInverse;
				val2 = rotation * (((Matrix4x4)(ref val3)).rotation * val2);
			}
			float num = Math.Sign(Vector3.Dot(transform2.forward, transform2.position - val));
			if (IsVR(mainCamera))
			{
				CopyValues(mainCamera, _leftEyeCamera.Camera);
				CopyValues(mainCamera, _rightEyeCamera.Camera);
				Surface.SurfaceMaterial.SetInt(PortalShaderConstants.ForceEyeID, 1);
				(Vector3 left, Vector3 right) eyes = GetEyes();
				Vector3 item = eyes.left;
				Vector3 item2 = eyes.right;
				Vector3 val4 = CalculateScaleDifference(PortalEnterMatrix, OtherPortal.PortalExitMatrix);
				Matrix4x4 val5 = Matrix4x4.TRS(val, val2, Vector4.op_Implicit(Matrix4x4.Inverse(Matrix4x4.Scale(val4)) * Vector4.op_Implicit(transform.lossyScale)));
				Vector3 val6 = ((Matrix4x4)(ref val5)).MultiplyPoint(item);
				Vector3 val7 = ((Matrix4x4)(ref val5)).MultiplyPoint(item2);
				_leftEyeCamera.Transform.SetPositionAndRotation(val6, val2);
				_leftEyeCamera.Camera.projectionMatrix = CalculateEyeProjectionMatrix(mainCamera, (StereoscopicEye)0, num, transform2, _leftEyeCamera.Transform, _leftEyeCamera.Camera);
				Surface.SurfaceMaterial.SetFloat(PortalShaderConstants.EyeOverrideID, 0f);
				_leftEyeCamera.RenderCamera(context);
				_rightEyeCamera.Transform.SetPositionAndRotation(val7, val2);
				_rightEyeCamera.Camera.projectionMatrix = CalculateEyeProjectionMatrix(mainCamera, (StereoscopicEye)1, num, transform2, _rightEyeCamera.Transform, _rightEyeCamera.Camera);
				Surface.SurfaceMaterial.SetFloat(PortalShaderConstants.EyeOverrideID, 1f);
				_rightEyeCamera.RenderCamera(context);
				Surface.SurfaceMaterial.SetInt(PortalShaderConstants.ForceEyeID, 0);
			}
			else
			{
				CopyValues(mainCamera, _leftEyeCamera.Camera);
				_leftEyeCamera.Transform.SetPositionAndRotation(val, val2);
				Vector4 clipPlane = CalculatePortalClipPlane(transform2, _leftEyeCamera.Transform, _leftEyeCamera.Camera, num);
				Matrix4x4 projectionMatrix = CalculateObliqueMatrix(mainCamera.projectionMatrix, clipPlane);
				_leftEyeCamera.Camera.projectionMatrix = projectionMatrix;
				_leftEyeCamera.RenderCamera(context);
			}
		}

		private void CopyValues(Camera from, Camera to)
		{
			to.nearClipPlane = from.nearClipPlane;
			to.farClipPlane = from.farClipPlane;
			to.fieldOfView = from.fieldOfView;
			to.cullingMask = from.cullingMask;
		}

		private bool IsVR(Camera camera)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			if (!PortalsMod.IsMockHMD)
			{
				return (int)camera.stereoTargetEye == 3;
			}
			return false;
		}

		private void DrawClippingPlane(Camera camera)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_003a: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL