Decompiled source of Portals v1.2.0

PortalMod.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("PortalMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Go Go Gadget Portals for Big Walk")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0")]
[assembly: AssemblyProduct("PortalMod")]
[assembly: AssemblyTitle("PortalMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace PortalFlashlightMod
{
	public enum PortalColorId
	{
		White,
		Orange,
		Blue,
		Red,
		Green,
		Purple,
		Yellow
	}
	[BepInPlugin("com.gogogadgetjustice.portalflashlightmod", "Portal Flashlight", "1.0.1")]
	public class PortalFlashlightPlugin : BasePlugin
	{
		public const string GUID = "com.gogogadgetjustice.portalflashlightmod";

		public const string PluginName = "Portal Flashlight";

		public const string Version = "1.0.1";

		public static ManualLogSource Log;

		public static ConfigEntry<string> MenuToggleKeys;

		public static ConfigEntry<bool> FreeCursorInMenu;

		public static ConfigEntry<KeyCode> ToggleFlashlightKey;

		public static ConfigEntry<KeyCode> CycleColorForwardKey;

		public static ConfigEntry<KeyCode> CycleColorBackwardKey;

		public static ConfigEntry<bool> UseScrollWheelToCycle;

		public static ConfigEntry<KeyCode> FirePortalKey;

		public static ConfigEntry<float> Range;

		public static ConfigEntry<float> Intensity;

		public static ConfigEntry<float> SpotAngle;

		public static ConfigEntry<float> OffsetForward;

		public static ConfigEntry<float> OffsetDown;

		public static ConfigEntry<float> PortalFireRaycastDistance;

		public static ConfigEntry<float> PortalCameraRefreshInterval;

		public static ConfigEntry<float> PortalCameraMaxDistance;

		public override void Load()
		{
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Expected O, but got Unknown
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Expected O, but got Unknown
			Log = ((BasePlugin)this).Log;
			MenuToggleKeys = ((BasePlugin)this).Config.Bind<string>("Menu", "ToggleKeys", "Quote,F10", "Keys that open/close the config panel. Comma-separated KeyCode names.");
			FreeCursorInMenu = ((BasePlugin)this).Config.Bind<bool>("Menu", "FreeCursor", true, "Unlock and show the mouse cursor while the config panel is open.");
			ToggleFlashlightKey = ((BasePlugin)this).Config.Bind<KeyCode>("Flashlight", "ToggleKey", (KeyCode)102, "Press to switch the flashlight on/off.");
			CycleColorForwardKey = ((BasePlugin)this).Config.Bind<KeyCode>("Flashlight", "ColorForwardKey", (KeyCode)99, "Cycle the flashlight/portal color forward.");
			CycleColorBackwardKey = ((BasePlugin)this).Config.Bind<KeyCode>("Flashlight", "ColorBackwardKey", (KeyCode)118, "Cycle the flashlight/portal color backward.");
			UseScrollWheelToCycle = ((BasePlugin)this).Config.Bind<bool>("Flashlight", "UseScrollWheel", true, "Also let the mouse scroll wheel cycle colors.");
			FirePortalKey = ((BasePlugin)this).Config.Bind<KeyCode>("Portals", "FireKey", (KeyCode)323, "Fires a portal in whatever color the flashlight currently shows.");
			Range = ((BasePlugin)this).Config.Bind<float>("Flashlight", "Range", 20f, "How far the light reaches, in meters.");
			Intensity = ((BasePlugin)this).Config.Bind<float>("Flashlight", "Intensity", 4f, "Brightness of the light.");
			SpotAngle = ((BasePlugin)this).Config.Bind<float>("Flashlight", "SpotAngle", 50f, "Cone width of the spotlight, in degrees.");
			OffsetForward = ((BasePlugin)this).Config.Bind<float>("Flashlight", "OffsetForward", 0.35f, "How far in front of the camera the light sits, in meters.");
			OffsetDown = ((BasePlugin)this).Config.Bind<float>("Flashlight", "OffsetDown", 0.08f, "How far below the camera the light sits, in meters.");
			PortalFireRaycastDistance = ((BasePlugin)this).Config.Bind<float>("Performance", "PortalFireRaycastDistance", 50f, "Max distance the portal-fire raycast checks for a surface to place a portal on.");
			PortalCameraRefreshInterval = ((BasePlugin)this).Config.Bind<float>("Performance", "PortalCameraRefreshInterval", 0f, "How often (in seconds) portal preview cameras re-render. Set to 0 for static mode (updates only once when a portal is fired/moved, recommended for low-end PCs).");
			PortalCameraMaxDistance = ((BasePlugin)this).Config.Bind<float>("Performance", "PortalCameraMaxDistance", 25f, "Portal preview cameras skip rendering when further than this distance, in meters.");
			ClassInjector.RegisterTypeInIl2Cpp<PortalFlashlightController>();
			ClassInjector.RegisterTypeInIl2Cpp<PortalRimSpinner>();
			ClassInjector.RegisterTypeInIl2Cpp<PortalMenuRuntime>();
			GameObject val = new GameObject("PortalModMenuHost")
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)(object)val);
			val.AddComponent<PortalMenuRuntime>();
			((BasePlugin)this).AddComponent<PortalFlashlightController>();
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(22, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("Portal Flashlight");
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" ");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("1.0.1");
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" loaded successfully.");
			}
			log.LogInfo(val2);
		}
	}
	public class PortalMenuRuntime : MonoBehaviour
	{
		private bool _open;

		private bool _inputDead;

		private CursorLockMode _lockWas;

		private bool _cursorWas;

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

		private void Update()
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			if (_inputDead)
			{
				return;
			}
			try
			{
				if (KeyList.AnyDown(PortalFlashlightPlugin.MenuToggleKeys.Value))
				{
					_open = !_open;
					SetCursor(_open);
				}
			}
			catch (Exception ex)
			{
				_inputDead = true;
				ManualLogSource log = PortalFlashlightPlugin.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(37, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[PortalMenu] Input handling failure: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
		}

		private void SetCursor(bool free)
		{
			//IL_0043: 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)
			if (PortalFlashlightPlugin.FreeCursorInMenu.Value)
			{
				if (free)
				{
					_lockWas = Cursor.lockState;
					_cursorWas = Cursor.visible;
					Cursor.lockState = (CursorLockMode)0;
					Cursor.visible = true;
				}
				else
				{
					Cursor.lockState = _lockWas;
					Cursor.visible = _cursorWas;
				}
			}
		}

		private void OnGUI()
		{
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0445: Expected O, but got Unknown
			//IL_0470: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0075: Unknown result type (might be due to invalid IL or missing references)
			if (!_open)
			{
				return;
			}
			if (PortalFlashlightPlugin.FreeCursorInMenu.Value)
			{
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
			Matrix4x4 matrix = GUI.matrix;
			GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3(1.2f, 1.2f, 1f));
			try
			{
				GUILayout.BeginArea(new Rect(15f, 15f, 380f, 480f), "Portal Flashlight Config", GUI.skin.window);
				GUILayout.Space(10f);
				GUILayout.Label("<b>Flashlight Settings</b>", (Il2CppReferenceArray<GUILayoutOption>)null);
				GUILayout.Label($"Intensity: {PortalFlashlightPlugin.Intensity.Value:F1}", (Il2CppReferenceArray<GUILayoutOption>)null);
				float num = GUILayout.HorizontalSlider(PortalFlashlightPlugin.Intensity.Value, 0.5f, 10f, Array.Empty<GUILayoutOption>());
				if (num != PortalFlashlightPlugin.Intensity.Value)
				{
					PortalFlashlightPlugin.Intensity.Value = num;
					PortalFlashlightController.Instance?.ApplySettings();
				}
				GUILayout.Label($"Range (meters): {PortalFlashlightPlugin.Range.Value:F1}", (Il2CppReferenceArray<GUILayoutOption>)null);
				float num2 = GUILayout.HorizontalSlider(PortalFlashlightPlugin.Range.Value, 5f, 100f, Array.Empty<GUILayoutOption>());
				if (num2 != PortalFlashlightPlugin.Range.Value)
				{
					PortalFlashlightPlugin.Range.Value = num2;
					PortalFlashlightController.Instance?.ApplySettings();
				}
				GUILayout.Label($"Spotlight Angle: {PortalFlashlightPlugin.SpotAngle.Value:F0}", (Il2CppReferenceArray<GUILayoutOption>)null);
				float num3 = GUILayout.HorizontalSlider(PortalFlashlightPlugin.SpotAngle.Value, 10f, 120f, Array.Empty<GUILayoutOption>());
				if (num3 != PortalFlashlightPlugin.SpotAngle.Value)
				{
					PortalFlashlightPlugin.SpotAngle.Value = num3;
					PortalFlashlightController.Instance?.ApplySettings();
				}
				GUILayout.Space(10f);
				GUILayout.Label("<b>Portal & Performance</b>", (Il2CppReferenceArray<GUILayoutOption>)null);
				GUILayout.Label($"Portal Raycast Dist: {PortalFlashlightPlugin.PortalFireRaycastDistance.Value:F0}m", (Il2CppReferenceArray<GUILayoutOption>)null);
				PortalFlashlightPlugin.PortalFireRaycastDistance.Value = GUILayout.HorizontalSlider(PortalFlashlightPlugin.PortalFireRaycastDistance.Value, 10f, 1000f, Array.Empty<GUILayoutOption>());
				GUILayout.Label($"Camera Max Dist: {PortalFlashlightPlugin.PortalCameraMaxDistance.Value:F0}m", (Il2CppReferenceArray<GUILayoutOption>)null);
				PortalFlashlightPlugin.PortalCameraMaxDistance.Value = GUILayout.HorizontalSlider(PortalFlashlightPlugin.PortalCameraMaxDistance.Value, 5f, 100f, Array.Empty<GUILayoutOption>());
				float value = PortalFlashlightPlugin.PortalCameraRefreshInterval.Value;
				GUILayout.Label("Cam Refresh Interval: " + ((value <= 0f) ? "Static (On Fire Only)" : (value.ToString("F2") + "s")), (Il2CppReferenceArray<GUILayoutOption>)null);
				PortalFlashlightPlugin.PortalCameraRefreshInterval.Value = GUILayout.HorizontalSlider(value, 0f, 0.5f, Array.Empty<GUILayoutOption>());
				GUILayout.Space(10f);
				PortalFlashlightPlugin.UseScrollWheelToCycle.Value = GUILayout.Toggle(PortalFlashlightPlugin.UseScrollWheelToCycle.Value, "Use Mouse Scroll to Cycle Colors", Array.Empty<GUILayoutOption>());
				GUILayout.Space(15f);
				if (GUILayout.Button("Close Menu", (Il2CppReferenceArray<GUILayoutOption>)null))
				{
					_open = false;
					SetCursor(free: false);
				}
				GUILayout.EndArea();
			}
			catch (Exception ex)
			{
				_open = false;
				SetCursor(free: false);
				ManualLogSource log = PortalFlashlightPlugin.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(51, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[PortalMenu] UI exception triggered, closing menu: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
			finally
			{
				GUI.matrix = matrix;
			}
		}
	}
	internal static class KeyList
	{
		private static readonly Dictionary<string, KeyCode[]> Parsed = new Dictionary<string, KeyCode[]>();

		public static bool AnyDown(string spec)
		{
			//IL_0010: 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)
			KeyCode[] array = Parse(spec);
			foreach (KeyCode val in array)
			{
				if (Input.GetKeyDown(val))
				{
					return true;
				}
			}
			return false;
		}

		private static KeyCode[] Parse(string spec)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			if (Parsed.TryGetValue(spec, out var value))
			{
				return value;
			}
			List<KeyCode> list = new List<KeyCode>();
			string[] array = spec.Split(',');
			foreach (string text in array)
			{
				string text2 = text.Trim();
				if (text2.Length > 0 && Enum.TryParse<KeyCode>(text2, ignoreCase: true, out KeyCode result))
				{
					list.Add(result);
				}
			}
			KeyCode[] array2 = list.ToArray();
			Parsed[spec] = array2;
			return array2;
		}
	}
	public class PortalRimSpinner : MonoBehaviour
	{
		public PortalRimSpinner(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Update()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).transform.Rotate(Vector3.up, 40f * Time.deltaTime, (Space)1);
		}
	}
	public class PortalRuntimeData
	{
		public GameObject Object;

		public Camera Cam;

		public RenderTexture RT;

		public Material Mat;

		public bool HasCleared = true;
	}
	public class PortalFlashlightController : MonoBehaviour
	{
		private const bool VerboseLogging = true;

		private Light _noseLight;

		private Camera _attachedCamera;

		private bool _isOn;

		private static readonly PortalColorId[] CycleOrder = new PortalColorId[7]
		{
			PortalColorId.White,
			PortalColorId.Orange,
			PortalColorId.Blue,
			PortalColorId.Red,
			PortalColorId.Green,
			PortalColorId.Purple,
			PortalColorId.Yellow
		};

		private int _cycleIndex = 0;

		private static readonly Dictionary<PortalColorId, Color> DisplayColors = new Dictionary<PortalColorId, Color>
		{
			{
				PortalColorId.White,
				Color.white
			},
			{
				PortalColorId.Orange,
				new Color(1f, 0.365f, 0f)
			},
			{
				PortalColorId.Blue,
				new Color(0.153f, 0.655f, 0.847f)
			},
			{
				PortalColorId.Red,
				new Color(0.898f, 0.145f, 0.129f)
			},
			{
				PortalColorId.Green,
				new Color(0.282f, 0.678f, 0.086f)
			},
			{
				PortalColorId.Purple,
				new Color(0.329f, 0.024f, 0.455f)
			},
			{
				PortalColorId.Yellow,
				new Color(1f, 1f, 0.192f)
			}
		};

		private static readonly Dictionary<PortalColorId, PortalColorId> Partner = new Dictionary<PortalColorId, PortalColorId>
		{
			{
				PortalColorId.Orange,
				PortalColorId.Blue
			},
			{
				PortalColorId.Blue,
				PortalColorId.Orange
			},
			{
				PortalColorId.Red,
				PortalColorId.Green
			},
			{
				PortalColorId.Green,
				PortalColorId.Red
			},
			{
				PortalColorId.Purple,
				PortalColorId.Yellow
			},
			{
				PortalColorId.Yellow,
				PortalColorId.Purple
			}
		};

		private readonly Dictionary<PortalColorId, PortalRuntimeData> portals = new Dictionary<PortalColorId, PortalRuntimeData>();

		private float globalCooldown = 0f;

		private const float PortalClearCheckRadius = 0.15f;

		private const float PortalNudgeStep = 0.05f;

		private const int PortalNudgeMaxAttempts = 8;

		private const float ClearDistance = 2.5f;

		private const float ClearDistanceSqr = 6.25f;

		private const float TeleportDistance = 1.8f;

		private const float TeleportDistanceSqr = 3.2399998f;

		private static Shader _cachedUnlitShader;

		private static Shader _cachedLitShader;

		private Rigidbody playerRootRb;

		private Vector3 previousRootPos;

		private Vector3 manualRootVelocity;

		private Vector3 activeMomentum = Vector3.zero;

		private const float MomentumDecayPerSecond = 0.6f;

		private const float MomentumCutoff = 0.5f;

		public static PortalFlashlightController Instance { get; private set; }

		private PortalColorId CurrentColor => CycleOrder[_cycleIndex];

		public PortalFlashlightController(IntPtr ptr)
			: base(ptr)
		{
		}//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)


		private void Awake()
		{
			Instance = this;
		}

		private void Start()
		{
			MonoBehaviourExtensions.StartCoroutine((MonoBehaviour)(object)this, ProximityCheckLoop());
			MonoBehaviourExtensions.StartCoroutine((MonoBehaviour)(object)this, PortalCameraUpdateLoop());
		}

		private void Update()
		{
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_attachedCamera == (Object)null)
			{
				Camera main = Camera.main;
				if ((Object)(object)main != (Object)null)
				{
					AttachFlashlightTo(main);
				}
			}
			if ((Object)(object)_attachedCamera != (Object)null && (Object)(object)playerRootRb == (Object)null)
			{
				Transform val = ((Component)_attachedCamera).transform;
				while ((Object)(object)val.parent != (Object)null)
				{
					val = val.parent;
				}
				playerRootRb = ((Component)val).GetComponent<Rigidbody>() ?? ((Component)val).GetComponentInChildren<Rigidbody>();
				if ((Object)(object)playerRootRb != (Object)null)
				{
					previousRootPos = playerRootRb.position;
				}
			}
			if ((Object)(object)playerRootRb != (Object)null && Time.deltaTime > 0f)
			{
				manualRootVelocity = (playerRootRb.position - previousRootPos) / Time.deltaTime;
				previousRootPos = playerRootRb.position;
			}
			if (globalCooldown > 0f)
			{
				globalCooldown -= Time.deltaTime;
			}
			if (Input.GetKeyDown(PortalFlashlightPlugin.ToggleFlashlightKey.Value))
			{
				ToggleFlashlight();
			}
			if (Input.GetKeyDown(PortalFlashlightPlugin.CycleColorForwardKey.Value))
			{
				CycleColor(1);
			}
			if (Input.GetKeyDown(PortalFlashlightPlugin.CycleColorBackwardKey.Value))
			{
				CycleColor(-1);
			}
			if (PortalFlashlightPlugin.UseScrollWheelToCycle.Value)
			{
				float axis = Input.GetAxis("Mouse ScrollWheel");
				if (axis > 0.01f)
				{
					CycleColor(1);
				}
				else if (axis < -0.01f)
				{
					CycleColor(-1);
				}
			}
			if (_isOn)
			{
				if (Input.GetKeyDown(PortalFlashlightPlugin.FirePortalKey.Value))
				{
					FirePortalColor(CurrentColor);
				}
				if (Input.GetKeyDown((KeyCode)324) && Partner.TryGetValue(CurrentColor, out var value))
				{
					FirePortalColor(value);
				}
			}
		}

		private void FixedUpdate()
		{
			//IL_0069: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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)
			if (!((Object)(object)playerRootRb == (Object)null) && !playerRootRb.isKinematic)
			{
				if (((Vector3)(ref activeMomentum)).sqrMagnitude <= 0.25f)
				{
					activeMomentum = Vector3.zero;
					return;
				}
				float num = Mathf.Pow(0.39999998f, Time.fixedDeltaTime);
				float num2 = 1f - num;
				Rigidbody obj = playerRootRb;
				obj.linearVelocity += activeMomentum * num2;
				activeMomentum *= num;
			}
		}

		private void AttachFlashlightTo(Camera cam)
		{
			_attachedCamera = cam;
			if ((Object)(object)_noseLight == (Object)null)
			{
				CreateLight();
			}
			((Component)_noseLight).transform.SetParent(((Component)cam).transform, false);
			ApplyOffset();
		}

		private void CreateLight()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			GameObject val = new GameObject("PortalFlashlight");
			_noseLight = ((Il2CppObjectBase)val.AddComponent(Il2CppType.Of<Light>())).Cast<Light>();
			_noseLight.type = (LightType)0;
			_noseLight.shadows = (LightShadows)2;
			val.SetActive(_isOn);
			ApplySettings();
			UpdateLightColor();
		}

		private void ApplyOffset()
		{
			//IL_0038: 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)
			if (!((Object)(object)_noseLight == (Object)null))
			{
				((Component)_noseLight).transform.localPosition = new Vector3(0f, 0f - PortalFlashlightPlugin.OffsetDown.Value, PortalFlashlightPlugin.OffsetForward.Value);
				((Component)_noseLight).transform.localRotation = Quaternion.identity;
			}
		}

		public void ApplySettings()
		{
			if (!((Object)(object)_noseLight == (Object)null))
			{
				_noseLight.range = PortalFlashlightPlugin.Range.Value;
				_noseLight.intensity = PortalFlashlightPlugin.Intensity.Value;
				_noseLight.spotAngle = PortalFlashlightPlugin.SpotAngle.Value;
				ApplyOffset();
			}
		}

		private void ToggleFlashlight()
		{
			if ((Object)(object)_noseLight == (Object)null)
			{
				Camera main = Camera.main;
				if ((Object)(object)main == (Object)null)
				{
					return;
				}
				AttachFlashlightTo(main);
			}
			ApplySettings();
			_isOn = !_isOn;
			((Component)_noseLight).gameObject.SetActive(_isOn);
		}

		private void CycleColor(int direction)
		{
			_cycleIndex = (_cycleIndex + direction + CycleOrder.Length) % CycleOrder.Length;
			UpdateLightColor();
		}

		private void UpdateLightColor()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_noseLight == (Object)null))
			{
				_noseLight.color = DisplayColors[CurrentColor];
			}
		}

		private PortalRuntimeData GetOrCreateData(PortalColorId color)
		{
			if (!portals.TryGetValue(color, out var value) || value == null)
			{
				value = new PortalRuntimeData();
				portals[color] = value;
			}
			return value;
		}

		private void FirePortalColor(PortalColorId color)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_0062: 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_006a: 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_008b: 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_00bc: 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_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Expected O, but got Unknown
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			if (color == PortalColorId.White || (Object)(object)_attachedCamera == (Object)null)
			{
				return;
			}
			Transform root = ((Component)_attachedCamera).transform.root;
			Vector3 val = ((Component)_attachedCamera).transform.position + ((Component)_attachedCamera).transform.forward * 0.5f;
			Ray val2 = default(Ray);
			((Ray)(ref val2))..ctor(val, ((Component)_attachedCamera).transform.forward);
			float value = PortalFlashlightPlugin.PortalFireRaycastDistance.Value;
			RaycastHit[] array = Il2CppArrayBase<RaycastHit>.op_Implicit((Il2CppArrayBase<RaycastHit>)(object)Physics.RaycastAll(val2, value));
			RaycastHit val3 = default(RaycastHit);
			float num = float.PositiveInfinity;
			bool flag = false;
			RaycastHit[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				RaycastHit val4 = array2[i];
				if (!((Object)(object)((RaycastHit)(ref val4)).collider == (Object)null) && !((RaycastHit)(ref val4)).collider.isTrigger && !((Object)((RaycastHit)(ref val4)).collider).name.Contains("Plane") && !((Object)(object)((RaycastHit)(ref val4)).transform.root == (Object)(object)root) && ((RaycastHit)(ref val4)).distance < num)
				{
					num = ((RaycastHit)(ref val4)).distance;
					val3 = val4;
					flag = true;
				}
			}
			if (flag && !((Object)(object)((RaycastHit)(ref val3)).collider == (Object)null))
			{
				PortalRuntimeData orCreateData = GetOrCreateData(color);
				if ((Object)(object)orCreateData.Object != (Object)null)
				{
					Object.Destroy((Object)(object)orCreateData.Object);
				}
				GameObject val5 = new GameObject($"Portal_{color}");
				val5.transform.position = ((RaycastHit)(ref val3)).point + ((RaycastHit)(ref val3)).normal * 0.05f;
				val5.transform.rotation = Quaternion.FromToRotation(Vector3.up, ((RaycastHit)(ref val3)).normal);
				SetupPortalVisuals(val5, color, orCreateData);
				orCreateData.Object = val5;
				orCreateData.HasCleared = false;
				EnsurePortalClearance(val5);
				RenderPortalCamerasFor(color);
				if (Partner.TryGetValue(color, out var value2))
				{
					RenderPortalCamerasFor(value2);
				}
			}
		}

		private void EnsurePortalClearance(GameObject portalObj)
		{
			//IL_000f: 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_00bc: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 8; i++)
			{
				Collider[] array = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(portalObj.transform.position, 0.15f));
				bool flag = false;
				Collider[] array2 = array;
				foreach (Collider val in array2)
				{
					if (!((Object)(object)val == (Object)null) && !((Component)val).transform.IsChildOf(portalObj.transform) && !((Object)val).name.Contains("Plane") && !val.isTrigger)
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					break;
				}
				Transform transform = portalObj.transform;
				transform.position += portalObj.transform.up * 0.05f;
				Light componentInChildren = portalObj.GetComponentInChildren<Light>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					((Component)componentInChildren).transform.position = portalObj.transform.position + portalObj.transform.up * 0.5f;
				}
			}
		}

		private bool IsPortalBlocked(GameObject portalObj)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			Collider[] array = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(portalObj.transform.position, 0.15f));
			Collider[] array2 = array;
			foreach (Collider val in array2)
			{
				if (!((Object)(object)val == (Object)null) && !((Component)val).transform.IsChildOf(portalObj.transform) && !((Object)val).name.Contains("Plane") && !val.isTrigger)
				{
					return true;
				}
			}
			return false;
		}

		private static Shader GetUnlitShader()
		{
			if ((Object)(object)_cachedUnlitShader == (Object)null)
			{
				_cachedUnlitShader = Shader.Find("Universal Render Pipeline/Unlit") ?? Shader.Find("Unlit/Texture") ?? Shader.Find("UI/Default") ?? Shader.Find("Sprites/Default");
			}
			return _cachedUnlitShader;
		}

		private static Shader GetLitShader()
		{
			if ((Object)(object)_cachedLitShader == (Object)null)
			{
				_cachedLitShader = Shader.Find("Universal Render Pipeline/Lit") ?? Shader.Find("Standard");
			}
			return _cachedLitShader;
		}

		private static void MakeEmissive(Material mat, Color color, float intensity)
		{
			//IL_0023: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			if (mat.HasProperty("_EmissionColor"))
			{
				mat.EnableKeyword("_EMISSION");
				mat.SetColor("_EmissionColor", color * intensity);
				mat.globalIlluminationFlags = (MaterialGlobalIlluminationFlags)1;
			}
			if (mat.HasProperty("_Color"))
			{
				mat.color = color;
			}
		}

		private static void AddPortalRimGlow(GameObject portalObj, float radius, Color color)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_00b1: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("PortalRim");
			val.transform.SetParent(portalObj.transform, false);
			Vector3 localPosition = default(Vector3);
			for (int i = 0; i < 20; i++)
			{
				float num = 18f * (float)i * ((float)Math.PI / 180f);
				((Vector3)(ref localPosition))..ctor(Mathf.Cos(num) * radius, 0f, Mathf.Sin(num) * radius);
				GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)0);
				Object.Destroy((Object)(object)val2.GetComponent<Collider>());
				val2.transform.SetParent(val.transform, false);
				val2.transform.localPosition = localPosition;
				val2.transform.localScale = Vector3.one * 0.025f;
				Material val3 = new Material(GetUnlitShader());
				MakeEmissive(val3, color, 3f);
				val2.GetComponent<Renderer>().material = val3;
			}
			val.AddComponent<PortalRimSpinner>();
		}

		private void SetupPortalVisuals(GameObject portalObj, PortalColorId color, PortalRuntimeData data)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: 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_0329: Expected O, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Expected O, but got Unknown
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Expected O, but got Unknown
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Expected O, but got Unknown
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Expected O, but got Unknown
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: 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)
			Color val = DisplayColors[color];
			GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)4);
			Object.Destroy((Object)(object)val2.GetComponent<Collider>());
			val2.transform.SetParent(portalObj.transform, false);
			val2.transform.localScale = new Vector3(0.25f, 0.25f, 0.25f);
			val2.transform.localPosition = new Vector3(0f, -0.08f, 0f);
			Material val3 = new Material(GetLitShader());
			MakeEmissive(val3, val, 22.5f);
			val2.GetComponent<Renderer>().material = val3;
			GameObject val4 = GameObject.CreatePrimitive((PrimitiveType)4);
			Object.Destroy((Object)(object)val4.GetComponent<Collider>());
			val4.transform.SetParent(portalObj.transform, false);
			val4.transform.localScale = new Vector3(0.15f, 0.15f, 0.15f);
			val4.transform.localPosition = Vector3.zero;
			if ((Object)(object)data.RT == (Object)null)
			{
				data.RT = new RenderTexture(256, 256, 24);
			}
			if ((Object)(object)data.Mat == (Object)null)
			{
				data.Mat = new Material(GetUnlitShader());
			}
			data.Mat.mainTexture = (Texture)(object)data.RT;
			val4.GetComponent<Renderer>().material = data.Mat;
			if ((Object)(object)data.Cam == (Object)null)
			{
				GameObject val5 = new GameObject($"PortalCam_{color}");
				data.Cam = ((Il2CppObjectBase)val5.AddComponent(Il2CppType.Of<Camera>())).Cast<Camera>();
				data.Cam.targetTexture = data.RT;
				((Behaviour)data.Cam).enabled = false;
			}
			GameObject val6 = new GameObject($"{color}_Light");
			val6.transform.position = portalObj.transform.position + portalObj.transform.up * 0.5f;
			val6.transform.SetParent(portalObj.transform);
			Light val7 = ((Il2CppObjectBase)val6.AddComponent(Il2CppType.Of<Light>())).Cast<Light>();
			val7.type = (LightType)2;
			val7.color = val;
			val7.range = 5f;
			val7.intensity = 2.5f;
			val7.renderMode = (LightRenderMode)2;
			AddPortalRimGlow(portalObj, 0.15f, val);
			Color val8 = val;
			if (Partner.TryGetValue(color, out var value))
			{
				val8 = (DisplayColors.ContainsKey(value) ? DisplayColors[value] : val8);
			}
			Il2CppArrayBase<ParticleSystem> componentsInChildren = portalObj.GetComponentsInChildren<ParticleSystem>(true);
			bool flag2 = default(bool);
			foreach (ParticleSystem item in componentsInChildren)
			{
				try
				{
					MainModule main = item.main;
					main.startColor = MinMaxGradient.op_Implicit(val8);
				}
				catch (Exception ex)
				{
					bool flag = true;
					ManualLogSource log = PortalFlashlightPlugin.Log;
					BepInExWarningLogInterpolatedStringHandler val9 = new BepInExWarningLogInterpolatedStringHandler(41, 1, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val9).AppendLiteral("[PortalFlashlight] Particle color error: ");
						((BepInExLogInterpolatedStringHandler)val9).AppendFormatted<string>(ex.Message);
					}
					log.LogWarning(val9);
				}
			}
		}

		private void RenderPortalCamerasFor(PortalColorId color)
		{
			//IL_0098: 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_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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: 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_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: 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)
			if (Partner.TryGetValue(color, out var value) && portals.TryGetValue(value, out var value2) && !((Object)(object)value2?.Object == (Object)null) && portals.TryGetValue(color, out var value3) && !((Object)(object)value3?.Cam == (Object)null))
			{
				Camera cam = value3.Cam;
				GameObject val = value2.Object;
				((Component)cam).transform.position = val.transform.position + val.transform.up * 0.1f;
				Vector3 val2 = Vector3.up;
				if (Mathf.Abs(Vector3.Dot(val.transform.up, Vector3.up)) > 0.99f && (Object)(object)_attachedCamera != (Object)null)
				{
					val2 = ((Component)_attachedCamera).transform.forward;
				}
				((Component)cam).transform.rotation = Quaternion.LookRotation(val.transform.up, val2);
				cam.fieldOfView = 70f;
				cam.Render();
			}
		}

		private bool ShouldRenderPortal(GameObject portalObj)
		{
			//IL_002d: 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_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)
			if ((Object)(object)_attachedCamera == (Object)null || (Object)(object)portalObj == (Object)null)
			{
				return false;
			}
			Vector3 val = portalObj.transform.position - ((Component)_attachedCamera).transform.position;
			float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
			float value = PortalFlashlightPlugin.PortalCameraMaxDistance.Value;
			if (sqrMagnitude > value * value)
			{
				return false;
			}
			if (sqrMagnitude < 0.0001f)
			{
				return true;
			}
			float num = Vector3.Dot(((Component)_attachedCamera).transform.forward, ((Vector3)(ref val)).normalized);
			return num > -0.2f;
		}

		private IEnumerator PortalCameraUpdateLoop()
		{
			while (true)
			{
				float interval = PortalFlashlightPlugin.PortalCameraRefreshInterval.Value;
				if (interval <= 0f)
				{
					yield return (object)new WaitForSeconds(1f);
					continue;
				}
				yield return (object)new WaitForSeconds(interval);
				if ((Object)(object)_attachedCamera == (Object)null)
				{
					continue;
				}
				foreach (KeyValuePair<PortalColorId, PortalRuntimeData> kvp in portals)
				{
					PortalColorId color = kvp.Key;
					PortalRuntimeData data = kvp.Value;
					if (!((Object)(object)data?.Object == (Object)null) && !((Object)(object)data.Cam == (Object)null) && Partner.TryGetValue(color, out var partnerColor) && portals.TryGetValue(partnerColor, out var partnerData) && !((Object)(object)partnerData?.Object == (Object)null) && ShouldRenderPortal(data.Object))
					{
						RenderPortalCamerasFor(color);
						partnerData = null;
					}
				}
			}
		}

		private IEnumerator ProximityCheckLoop()
		{
			WaitForSeconds wait = new WaitForSeconds(0.03f);
			while (true)
			{
				if ((Object)(object)_attachedCamera != (Object)null)
				{
					Vector3 standingPos = ((Component)_attachedCamera).transform.position;
					foreach (PortalColorId color in Partner.Keys)
					{
						if (portals.TryGetValue(color, out var data) && !((Object)(object)data?.Object == (Object)null) && Partner.TryGetValue(color, out var partnerColor) && portals.TryGetValue(partnerColor, out var partnerData) && !((Object)(object)partnerData?.Object == (Object)null))
						{
							Vector3 val = standingPos - data.Object.transform.position;
							float sqrDist = ((Vector3)(ref val)).sqrMagnitude;
							if (sqrDist > 6.25f)
							{
								data.HasCleared = true;
							}
							if (data.HasCleared && globalCooldown <= 0f && sqrDist < 3.2399998f && !IsPortalBlocked(data.Object))
							{
								TeleportPlayerAndHeldItems(data.Object, partnerData.Object);
								data.HasCleared = false;
								partnerData.HasCleared = false;
								globalCooldown = 1f;
								break;
							}
							data = null;
							partnerData = null;
						}
					}
				}
				yield return wait;
			}
		}

		private void TeleportPlayerAndHeldItems(GameObject sourcePortal, GameObject targetPortal)
		{
			//IL_0075: 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_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_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_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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: 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_0116: 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_011c: 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_0128: 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_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: 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_00dc: 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_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: 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_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: 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_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: 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_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: 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_04e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0507: Unknown result type (might be due to invalid IL or missing references)
			//IL_0510: Unknown result type (might be due to invalid IL or missing references)
			//IL_0512: Unknown result type (might be due to invalid IL or missing references)
			//IL_0530: Unknown result type (might be due to invalid IL or missing references)
			//IL_0535: Unknown result type (might be due to invalid IL or missing references)
			//IL_0552: Unknown result type (might be due to invalid IL or missing references)
			//IL_0554: 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_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b8: 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_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f5: 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_03d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: 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_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_044c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0451: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_045e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0463: Unknown result type (might be due to invalid IL or missing references)
			//IL_0470: Unknown result type (might be due to invalid IL or missing references)
			//IL_040c: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0410: Unknown result type (might be due to invalid IL or missing references)
			//IL_0412: Unknown result type (might be due to invalid IL or missing references)
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0423: 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_0427: Unknown result type (might be due to invalid IL or missing references)
			//IL_0429: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0441: Unknown result type (might be due to invalid IL or missing references)
			//IL_0446: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_attachedCamera == (Object)null)
			{
				return;
			}
			Transform val = ((Component)_attachedCamera).transform;
			while ((Object)(object)val.parent != (Object)null)
			{
				val = val.parent;
			}
			GameObject gameObject = ((Component)val).gameObject;
			try
			{
				float magnitude = ((Vector3)(ref manualRootVelocity)).magnitude;
				float num = 0.3f + Mathf.Clamp(magnitude * 0.03f, 0f, 1f);
				Vector3 val2 = targetPortal.transform.position + targetPortal.transform.up * (1.2f + num);
				CharacterController val3 = gameObject.GetComponent<CharacterController>() ?? gameObject.GetComponentInChildren<CharacterController>();
				Vector3 linearVelocity = manualRootVelocity;
				if (((Vector3)(ref linearVelocity)).magnitude < 1f && (Object)(object)playerRootRb != (Object)null)
				{
					linearVelocity = playerRootRb.linearVelocity;
				}
				Matrix4x4 localToWorldMatrix = sourcePortal.transform.localToWorldMatrix;
				Matrix4x4 localToWorldMatrix2 = targetPortal.transform.localToWorldMatrix;
				Matrix4x4 val4 = Matrix4x4.Rotate(Quaternion.Euler(180f, 0f, 0f));
				Matrix4x4 val5 = localToWorldMatrix2 * val4 * ((Matrix4x4)(ref localToWorldMatrix)).inverse;
				Vector3 val6 = ((Matrix4x4)(ref val5)).MultiplyVector(linearVelocity) * 1.2f;
				float num2 = 0f - Vector3.Dot(linearVelocity, sourcePortal.transform.up);
				if (num2 > 6f)
				{
					float num3 = Mathf.Clamp((num2 - 6f) * 0.6f, 0f, 30f);
					Vector3 val7 = -sourcePortal.transform.up * num3;
					Vector3 val8 = ((Matrix4x4)(ref val5)).MultiplyVector(val7);
					val6 += val8;
					globalCooldown = Mathf.Max(globalCooldown, 0.75f + num2 * 0.05f);
				}
				float magnitude2 = ((Vector3)(ref linearVelocity)).magnitude;
				Vector3 up = targetPortal.transform.up;
				float num4 = Mathf.Lerp(1.5f, 6f, Mathf.InverseLerp(0f, 30f, magnitude2));
				float num5 = Vector3.Dot(val6, up);
				if (num5 < num4)
				{
					val6 += up * (num4 - num5);
					num5 = num4;
				}
				if (magnitude2 > 6f)
				{
					Vector3 val9 = val6 - up * num5;
					float magnitude3 = ((Vector3)(ref val9)).magnitude;
					if (magnitude3 > 0.01f)
					{
						float num6 = 1f + Mathf.Clamp((magnitude2 - 6f) / 10f, 0f, 1.5f);
						Vector3 val10 = val9 * num6;
						val6 = up * num5 + val10;
						float num7 = Mathf.Max(25f, magnitude2 * 1.5f);
						if (((Vector3)(ref val6)).magnitude > num7)
						{
							val6 = ((Vector3)(ref val6)).normalized * num7;
						}
					}
					globalCooldown = Mathf.Max(globalCooldown, 0.75f + magnitude2 * 0.04f);
				}
				Collider[] array = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(sourcePortal.transform.position, 2f));
				Collider[] array2 = array;
				foreach (Collider val11 in array2)
				{
					if ((Object)(object)((Component)val11).gameObject == (Object)(object)gameObject || ((Object)val11).name.Contains("Plane"))
					{
						continue;
					}
					Rigidbody component = ((Component)val11).GetComponent<Rigidbody>();
					if ((Object)(object)component != (Object)null && !component.isKinematic)
					{
						Vector3 val12 = ((Matrix4x4)(ref val5)).MultiplyVector(component.linearVelocity) * 1.5f;
						float num8 = Vector3.Dot(val12, up);
						if (num8 < 1.5f)
						{
							val12 += up * (1.5f - num8);
						}
						Vector3 linearVelocity2 = component.linearVelocity;
						if (((Vector3)(ref linearVelocity2)).magnitude > 6f)
						{
							Vector3 val13 = val12 - up * Vector3.Dot(val12, up);
							val12 = up * Vector3.Dot(val12, up) + val13 * 1.25f;
						}
						component.position += val2 - sourcePortal.transform.position;
						component.linearVelocity = val12;
					}
				}
				if ((Object)(object)val3 != (Object)null)
				{
					((Collider)val3).enabled = false;
				}
				Vector3 val14 = val2 - gameObject.transform.position;
				Rigidbody[] array3 = Il2CppArrayBase<Rigidbody>.op_Implicit(gameObject.GetComponentsInChildren<Rigidbody>());
				Rigidbody[] array4 = array3;
				foreach (Rigidbody val15 in array4)
				{
					val15.WakeUp();
					val15.position += val14;
				}
				gameObject.transform.position = val2;
				manualRootVelocity = val6;
				if ((Object)(object)playerRootRb != (Object)null)
				{
					previousRootPos = playerRootRb.position;
				}
				if ((Object)(object)val3 != (Object)null)
				{
					((Collider)val3).enabled = true;
				}
				activeMomentum = val6;
			}
			catch (Exception ex)
			{
				PortalFlashlightPlugin.Log.LogError((object)("[PortalFlashlight] Teleport error: " + ex.Message));
			}
		}
	}
}