Decompiled source of LethalDeathCam v0.9.2

LethalDeathCam.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("LethalDeathCam")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LethalDeathCam")]
[assembly: AssemblyTitle("LethalDeathCam")]
[assembly: AssemblyMetadata("AI_Assisted_Creation", "Partially created with generative AI (code writing, refactoring and documentation).")]
[assembly: AssemblyMetadata("AI_Model_Vendor", "Anthropic")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 LethalDeathCam
{
	internal static class DeathCam
	{
		private enum State
		{
			Idle,
			Active
		}

		private enum TargetKind
		{
			None,
			Body,
			DetachedHead
		}

		private const float MaxEyeOffset = 0.15f;

		private static EnemyAI carryingBracken;

		private static bool brackenDeath;

		private static Vector3 brackenLastPos;

		private static Vector3 brackenVelocity;

		private static Vector3 brackenAccel;

		private static float brackenSpeed;

		private static Vector3 brackenLookDir;

		private static string loggedDragSource;

		private static readonly FieldInfo f_carryingPlayerBody = Lookup(typeof(FlowermanAI), "carryingPlayerBody");

		private static readonly FieldInfo f_bodyBeingCarried = Lookup(typeof(FlowermanAI), "bodyBeingCarried");

		private const float DragPushAway = 0.15f;

		private const float DragPushUp = 0.25f;

		private static readonly List<Renderer> dragHiddenRenderers = new List<Renderer>();

		private static int viewBlockMask = -1;

		private const float WallMargin = 0.12f;

		private static Vector3 dragSafePoint;

		private static bool haveDragSafePoint;

		private static float clearFraction = 1f;

		private static readonly RaycastHit[] castHits = (RaycastHit[])(object)new RaycastHit[16];

		private const float WobbleStiffness = 55f;

		private const float WobbleDamping = 5f;

		private static float dragBlend;

		private static float wobbleYaw;

		private static float wobblePitch;

		private static float wobbleYawVel;

		private static float wobblePitchVel;

		private static Quaternion wobble = Quaternion.identity;

		private static float swaySeed;

		private static GameObject cameraBackup;

		private static Camera backupCam;

		private static HDAdditionalCameraData backupHd;

		private static int savedLayer;

		private static bool matchedAliveCamera;

		private static State state = State.Idle;

		private static DeathViewMode mode;

		private static PlayerControllerB player;

		private static float startTime;

		private static Vector3 deathEyePosition;

		private static Quaternion deathLookRotation;

		private static TargetKind targetKind = TargetKind.None;

		private static Transform rotationSource;

		private static Transform positionAnchor;

		private static Quaternion rotationOffset = Quaternion.identity;

		private static Vector3 positionOffset;

		private static DeadBodyInfo targetBody;

		private static float nextRetarget;

		private static Camera cam;

		private static Vector3 savedLocalPosition;

		private static Quaternion savedLocalRotation;

		private static float savedFov;

		private static float savedNearClip;

		private static bool subscribed;

		private static bool wasDead;

		private static bool haveAliveView;

		private const float WaitLimit = 0.75f;

		private static readonly FieldInfo f_detachedHead = Lookup(typeof(DeadBodyInfo), "detachedHead");

		private static readonly FieldInfo f_detachedHeadObject = Lookup(typeof(DeadBodyInfo), "detachedHeadObject");

		private static DeadBodyInfo loggedIgnoredPartFor;

		private const float FadeInTime = 0.35f;

		private static string endingReason;

		private static float endingStart;

		private static float fadeInStart = -99f;

		private static GameObject fadeObject;

		private static Image fadeImage;

		private static float fadeAlpha;

		private const int NormalSnapshot = 0;

		private const int GhostSnapshot = 1;

		private static bool ghostAudioOn;

		private static readonly List<Renderer> hiddenRenderers = new List<Renderer>();

		private static readonly Dictionary<CanvasRenderer, float> hiddenHud = new Dictionary<CanvasRenderer, float>();

		private static float nextHudScan;

		private static EnemyAI lastAnimationEnemy;

		private static EnemyAI killer;

		private static EnemyAI frameEnemy;

		private static EnemyAI killCallEnemy;

		private static float killCallTime = -99f;

		private static GameObject deathLight;

		private static Light deathLightComp;

		private static Light sourceLight;

		private static float baseIntensity;

		private static float baseRange;

		private static Color baseColor;

		private static bool diedInside;

		private static bool aliveInside;

		private const float LightHeight = 1.6f;

		private static Vector3 lightPosition;

		private static bool deadSinceAlive;

		private static bool loggedNearbyLights;

		private static float lookYaw;

		private static float lookPitch;

		private static Quaternion lookBase = Quaternion.identity;

		private static bool loggedLookInput;

		private static string loggedLookBlock;

		private static InputAction lookAction;

		private static bool settling;

		private static float calmSince = -1f;

		private static float targetStartTime;

		private const float BodyMargin = 0.08f;

		private const float LimbBlockDistance = 0.3f;

		private const float ShowAgainAfter = 0.5f;

		private const float CollapsedScale = 0.001f;

		private static readonly Vector2[] blockProbes = (Vector2[])(object)new Vector2[5]
		{
			Vector2.zero,
			new Vector2(0.35f, 0f),
			new Vector2(-0.35f, 0f),
			new Vector2(0f, 0.35f),
			new Vector2(0f, -0.35f)
		};

		private static readonly Dictionary<Transform, float> hiddenLimbs = new Dictionary<Transform, float>();

		private static Transform hiddenHead;

		private static readonly Dictionary<SkinnedMeshRenderer, Transform[]> originalBones = new Dictionary<SkinnedMeshRenderer, Transform[]>();

		private static readonly Dictionary<Transform, Transform> standInBones = new Dictionary<Transform, Transform>();

		private static readonly HashSet<Transform> loggedLimbs = new HashSet<Transform>();

		private static readonly List<Renderer> wholeBodyHidden = new List<Renderer>();

		private static bool wholeBodyIsHidden;

		private static bool loggedRender;

		private static Vector3 posePosition;

		private static Quaternion poseRotation;

		private const float PositionBlendTime = 0.35f;

		private static Vector3 blendFrom;

		private static float blendStart = -99f;

		private const float MaxPitch = 89f;

		private static Transform ourParent;

		private static Vector3 ourLocalPosition;

		private static Quaternion ourLocalRotation;

		private static int ViewBlockMask
		{
			get
			{
				if (viewBlockMask == -1)
				{
					viewBlockMask = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.collidersAndRoomMaskAndDefault : LayerMask.GetMask(new string[3] { "Room", "Colliders", "Default" }));
				}
				return viewBlockMask;
			}
		}

		private static bool ShipIsLeaving
		{
			get
			{
				if ((Object)(object)StartOfRound.Instance != (Object)null)
				{
					return StartOfRound.Instance.shipIsLeaving;
				}
				return false;
			}
		}

		private static bool MouseLookAllowed
		{
			get
			{
				if (Plugin.MouseLook.Value && targetKind == TargetKind.Body && !brackenDeath)
				{
					return !settling;
				}
				return false;
			}
		}

		private static void AttachBody(Transform head)
		{
			//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_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_001a: 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_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_0029: 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_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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_0068: 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_0072: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			positionAnchor = head;
			Vector3 val = Flat(poseRotation * Vector3.forward);
			Quaternion val2 = ((((Vector3)(ref val)).sqrMagnitude > 0.0001f) ? Quaternion.LookRotation(val, Vector3.up) : poseRotation);
			rotationOffset = Quaternion.Inverse(head.rotation) * val2;
			Vector3 val3 = Quaternion.Inverse(head.rotation) * (posePosition - head.position);
			positionOffset = ((((Vector3)(ref val3)).magnitude < 0.5f) ? Vector3.ClampMagnitude(val3, 0.15f) : Vector3.zero);
			if (Plugin.HideOwnHead.Value)
			{
				HideHeadOnScreen(head);
			}
			Plugin.logger.LogInfo((object)("Death cam following ragdoll bone '" + ((Object)head).name + "'" + (Plugin.MouseLook.Value ? " (mouse look on)" : " (mouse look off in config)")));
		}

		private static DeadBodyInfo GetBody(PlayerControllerB p)
		{
			if ((Object)(object)p.deadBody != (Object)null && !p.deadBody.deactivated)
			{
				return p.deadBody;
			}
			return ((IEnumerable<DeadBodyInfo>)Object.FindObjectsOfType<DeadBodyInfo>()).FirstOrDefault((Func<DeadBodyInfo, bool>)((DeadBodyInfo b) => (Object)(object)b != (Object)null && (Object)(object)b.playerScript == (Object)(object)p && !b.deactivated));
		}

		private static Transform FindHead(DeadBodyInfo body)
		{
			Transform[] componentsInChildren = ((Component)body).GetComponentsInChildren<Transform>(true);
			Rigidbody[] source = body.bodyParts?.Where((Rigidbody r) => (Object)(object)r != (Object)null).ToArray() ?? Array.Empty<Rigidbody>();
			Plugin.logger.LogInfo((object)("Ragdoll physics parts: " + string.Join(", ", source.Select((Rigidbody r) => ((Object)r).name))));
			string configured = Plugin.HeadBoneName.Value?.Trim();
			if (!string.IsNullOrEmpty(configured))
			{
				Transform val = ((IEnumerable<Transform>)componentsInChildren).FirstOrDefault((Func<Transform, bool>)((Transform b) => ((Object)b).name.Equals(configured, StringComparison.OrdinalIgnoreCase)));
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
				Plugin.logger.LogWarning((object)("Configured HeadBoneName '" + configured + "' not found; searching automatically."));
			}
			Transform val2 = source.Select((Rigidbody r) => ((Component)r).transform).FirstOrDefault((Func<Transform, bool>)IsHeadName) ?? ((IEnumerable<Transform>)componentsInChildren).FirstOrDefault((Func<Transform, bool>)((Transform b) => ((Object)b).name == "spine.004")) ?? ((IEnumerable<Transform>)componentsInChildren).FirstOrDefault((Func<Transform, bool>)((Transform b) => IsHeadName(b) && (Object)(object)((Component)b).GetComponent<Rigidbody>() != (Object)null));
			if ((Object)(object)val2 != (Object)null)
			{
				return val2;
			}
			Rigidbody val3 = source.OrderByDescending((Rigidbody r) => r.position.y).FirstOrDefault();
			if (!((Object)(object)val3 != (Object)null))
			{
				return null;
			}
			return ((Component)val3).transform;
			static bool IsEffect(Transform b)
			{
				if (((Object)b).name.IndexOf("decal", StringComparison.OrdinalIgnoreCase) < 0)
				{
					return ((Object)b).name.IndexOf("blood", StringComparison.OrdinalIgnoreCase) >= 0;
				}
				return true;
			}
			static bool IsHeadName(Transform b)
			{
				if (((Object)b).name.IndexOf("head", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return !IsEffect(b);
				}
				return false;
			}
		}

		private static void UpdateCarryingBracken()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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)
			EnemyAI val = ((targetKind == TargetKind.Body && Plugin.BrackenDragView.Value) ? FindCarryingBracken(targetBody) : null);
			if ((Object)(object)val != (Object)null && (Object)(object)carryingBracken == (Object)null)
			{
				Plugin.logger.LogInfo((object)"Death cam: a Bracken is dragging your body");
				brackenLastPos = ((Component)val).transform.position;
				brackenVelocity = Vector3.zero;
				brackenAccel = Vector3.zero;
				brackenSpeed = 0f;
				carryingBracken = val;
				brackenLookDir = DragAwayDirection();
				if (brackenLookDir == Vector3.zero)
				{
					brackenLookDir = poseRotation * Vector3.forward;
				}
				loggedDragSource = null;
				HideWhileDragged(val);
				wobblePitchVel += Mathf.Min(Plugin.BrackenSway.Value, 15f) * 6f;
			}
			if ((Object)(object)val == (Object)null && (Object)(object)carryingBracken != (Object)null)
			{
				Plugin.logger.LogInfo((object)"Death cam: the Bracken let go of your body");
				RestoreDraggedBody();
			}
			carryingBracken = val;
			if ((Object)(object)val != (Object)null && !brackenDeath)
			{
				brackenDeath = true;
				Plugin.logger.LogInfo((object)"Bracken death: automatic view only (no mouse look)");
			}
		}

		private static EnemyAI FindCarryingBracken(DeadBodyInfo body)
		{
			if ((Object)(object)body == (Object)null || f_bodyBeingCarried == null)
			{
				return null;
			}
			FlowermanAI[] array = Object.FindObjectsOfType<FlowermanAI>();
			foreach (FlowermanAI val in array)
			{
				if (!((Object)(object)val == (Object)null) && !((EnemyAI)val).isEnemyDead && (!(f_carryingPlayerBody != null) || GetBool(f_carryingPlayerBody, val)) && (Object)/*isinst with value type is only supported in some contexts*/ == (Object)(object)body)
				{
					return (EnemyAI)(object)val;
				}
			}
			return null;
		}

		private static void UpdateBracken(float dt)
		{
			//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_0030: 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_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_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_004c: 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_0064: 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_0073: 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_007a: 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_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_008f: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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_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_011c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)carryingBracken != (Object)null && dt > 0f)
			{
				Vector3 position = ((Component)carryingBracken).transform.position;
				Vector3 val = Vector3.ClampMagnitude((position - brackenLastPos) / dt, 12f);
				Vector3 val2 = brackenVelocity;
				brackenVelocity = Vector3.Lerp(brackenVelocity, val, 1f - Mathf.Exp(-8f * dt));
				Vector3 val3 = Vector3.ClampMagnitude((brackenVelocity - val2) / dt, 20f);
				brackenAccel = Vector3.Lerp(brackenAccel, val3, 1f - Mathf.Exp(-6f * dt));
				Vector3 val4 = new Vector3(brackenVelocity.x, 0f, brackenVelocity.z);
				brackenSpeed = ((Vector3)(ref val4)).magnitude;
				brackenLastPos = position;
				UpdateDragSafePoint(position);
				Vector3 val5 = DragAwayDirection();
				if (val5 != Vector3.zero)
				{
					val4 = Vector3.Slerp(brackenLookDir, val5, 1f - Mathf.Exp(-3f * dt));
					brackenLookDir = ((Vector3)(ref val4)).normalized;
				}
			}
			UpdateWobble(dt);
		}

		private static bool TryDragRotation(out Quaternion rotation)
		{
			//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_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)
			rotation = Quaternion.identity;
			if ((Object)(object)carryingBracken == (Object)null || ((Vector3)(ref brackenLookDir)).sqrMagnitude <= 0.0001f)
			{
				return false;
			}
			rotation = Quaternion.LookRotation(brackenLookDir, Vector3.up);
			return true;
		}

		private static void ResetBracken()
		{
			carryingBracken = null;
			swaySeed = Random.Range(0f, 100f);
			ResetWobble();
		}

		private static Vector3 DragAwayDirection()
		{
			//IL_001a: 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_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_0040: 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_005f: 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_006a: 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_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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: 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_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: 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)
			if ((Object)(object)carryingBracken == (Object)null || (Object)(object)positionAnchor == (Object)null)
			{
				return Vector3.zero;
			}
			Vector3 position = ((Component)carryingBracken).transform.position;
			Vector3 val = Flat(BodyCenter() - position);
			string text = "body";
			if (((Vector3)(ref val)).magnitude < 0.25f)
			{
				val = Flat(positionAnchor.position - position);
				text = "head";
			}
			if (((Vector3)(ref val)).magnitude < 0.05f)
			{
				val = Flat(-((Component)carryingBracken).transform.forward);
				text = "bracken facing";
			}
			((Vector3)(ref val)).Normalize();
			Vector3 val2 = Flat(brackenVelocity);
			Vector3 val4;
			if (((Vector3)(ref val2)).magnitude > 0.5f)
			{
				Vector3 val3 = ((Vector3)(ref val2)).normalized;
				if (Vector3.Dot(val3, val) < 0f)
				{
					val3 = -val3;
				}
				val4 = Vector3.Slerp(val, val3, 0.5f);
				val = ((Vector3)(ref val4)).normalized;
				text += " + movement";
			}
			if (loggedDragSource == null)
			{
				loggedDragSource = text;
				bool flag = ((Vector3)(ref val2)).magnitude > 0.5f && Vector3.Dot(val2, Flat(((Component)carryingBracken).transform.forward)) < 0f;
				Plugin.logger.LogInfo((object)("Bracken drag view: looking away using " + text + ((((Vector3)(ref val2)).magnitude > 0.5f) ? (" (Bracken " + (flag ? "backing up" : "walking forward") + ")") : "")));
			}
			Vector3 val5 = Vector3.Cross(Vector3.up, val);
			val4 = Quaternion.AngleAxis(Plugin.BrackenLookDown.Value, val5) * val;
			return ((Vector3)(ref val4)).normalized;
		}

		private static Vector3 Flat(Vector3 v)
		{
			//IL_0000: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(v.x, 0f, v.z);
		}

		private static Vector3 BodyCenter()
		{
			//IL_001e: 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_0088: 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_0082: 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_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_006a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)targetBody == (Object)null || targetBody.bodyParts == null)
			{
				return positionAnchor.position;
			}
			Vector3 val = Vector3.zero;
			int num = 0;
			Rigidbody[] bodyParts = targetBody.bodyParts;
			foreach (Rigidbody val2 in bodyParts)
			{
				if (!((Object)(object)val2 == (Object)null) && !((Object)(object)((Component)val2).transform == (Object)(object)rotationSource))
				{
					val += val2.position;
					num++;
				}
			}
			if (num <= 0)
			{
				return positionAnchor.position;
			}
			return val / (float)num;
		}

		private static Vector3 AdjustForDrag(Vector3 camera)
		{
			//IL_0013: 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_001a: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: 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_002e: 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)
			if (dragBlend <= 0f || !haveDragSafePoint)
			{
				return camera;
			}
			Vector3 val = Flat(brackenLookDir);
			return KeepOutOfWalls((((Vector3)(ref val)).sqrMagnitude > 0.0001f) ? (camera + (((Vector3)(ref val)).normalized * 0.15f + Vector3.up * 0.25f) * dragBlend) : camera);
		}

		private static void UpdateDragSafePoint(Vector3 brackenFeet)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: 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_001b: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = brackenFeet + Vector3.up * 0.3f;
			float num = 0.6f;
			if (CastLevel(val, Vector3.up, num, out var hitDistance))
			{
				num = Mathf.Max(0f, hitDistance - 0.05f);
			}
			dragSafePoint = val + Vector3.up * num;
			if (!haveDragSafePoint)
			{
				clearFraction = 1f;
			}
			haveDragSafePoint = true;
		}

		private static bool CastLevel(Vector3 from, Vector3 dir, float distance, out float hitDistance)
		{
			//IL_0005: 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)
			hitDistance = distance;
			bool result = false;
			int num = Physics.SphereCastNonAlloc(from, 0.12f, dir, castHits, distance, ViewBlockMask, (QueryTriggerInteraction)1);
			for (int i = 0; i < num; i++)
			{
				Transform transform = ((RaycastHit)(ref castHits[i])).transform;
				if (!((Object)(object)transform == (Object)null) && !(((RaycastHit)(ref castHits[i])).distance >= hitDistance) && (!((Object)(object)targetBody != (Object)null) || !transform.IsChildOf(((Component)targetBody).transform)) && (!((Object)(object)carryingBracken != (Object)null) || !transform.IsChildOf(((Component)carryingBracken).transform)))
				{
					hitDistance = ((RaycastHit)(ref castHits[i])).distance;
					result = true;
				}
			}
			return result;
		}

		private static Vector3 KeepOutOfWalls(Vector3 wanted)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//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_000b: 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_0020: 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_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_001c: 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_0077: 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)
			Vector3 val = wanted - dragSafePoint;
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (magnitude < 0.001f)
			{
				return wanted;
			}
			Vector3 dir = val / magnitude;
			float num = 1f;
			if (CastLevel(dragSafePoint, dir, magnitude, out var hitDistance))
			{
				num = Mathf.Clamp01((hitDistance - 0.02f) / magnitude);
			}
			clearFraction = ((num < clearFraction) ? num : Mathf.MoveTowards(clearFraction, num, Time.deltaTime * 1.5f));
			return dragSafePoint + val * clearFraction;
		}

		private static void HideWhileDragged(EnemyAI bracken)
		{
			if (Plugin.BrackenHideBody.Value && (Object)(object)targetBody != (Object)null)
			{
				HideForDrag(((Component)targetBody).transform);
			}
			if (Plugin.BrackenHideBracken.Value && (Object)(object)bracken != (Object)null)
			{
				HideForDrag(((Component)bracken).transform);
			}
		}

		private static void HideForDrag(Transform root)
		{
			Renderer[] componentsInChildren = ((Component)root).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && !val.forceRenderingOff)
				{
					val.forceRenderingOff = true;
					dragHiddenRenderers.Add(val);
				}
			}
		}

		private static void RestoreDraggedBody()
		{
			foreach (Renderer dragHiddenRenderer in dragHiddenRenderers)
			{
				if ((Object)(object)dragHiddenRenderer != (Object)null)
				{
					dragHiddenRenderer.forceRenderingOff = false;
				}
			}
			dragHiddenRenderers.Clear();
		}

		private static void UpdateWobble(float dt)
		{
			//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_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_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_00b7: 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_00bc: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: 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)
			if (dt <= 0f)
			{
				return;
			}
			bool flag = (Object)(object)carryingBracken != (Object)null;
			dragBlend = Mathf.MoveTowards(dragBlend, flag ? 1f : 0f, dt * 1.5f);
			float value = Plugin.BrackenSway.Value;
			if (value <= 0f)
			{
				wobbleYaw = (wobblePitch = (wobbleYawVel = (wobblePitchVel = 0f)));
				wobble = Quaternion.identity;
				return;
			}
			float num = 0f;
			float num2 = 0f;
			if (flag)
			{
				Vector3 val = poseRotation * Vector3.forward;
				val.y = 0f;
				val = ((((Vector3)(ref val)).sqrMagnitude > 0.0001f) ? ((Vector3)(ref val)).normalized : Vector3.forward);
				Vector3 val2 = Vector3.Cross(Vector3.up, val);
				num = (0f - Vector3.Dot(brackenAccel, val2)) * 4f * value;
				num2 = Vector3.Dot(brackenAccel, val) * 3.5f * value;
			}
			int num3 = Mathf.Clamp(Mathf.CeilToInt(dt / 0.01f), 1, 8);
			float num4 = dt / (float)num3;
			for (int i = 0; i < num3; i++)
			{
				wobbleYawVel += (num - 55f * wobbleYaw - 5f * wobbleYawVel) * num4;
				wobblePitchVel += (num2 - 55f * wobblePitch - 5f * wobblePitchVel) * num4;
				wobbleYaw += wobbleYawVel * num4;
				wobblePitch += wobblePitchVel * num4;
			}
			float num5 = value * 1.2f;
			wobbleYaw = Mathf.Clamp(wobbleYaw, 0f - num5, num5);
			wobblePitch = Mathf.Clamp(wobblePitch, 0f - num5, num5);
			float num6 = wobbleYaw;
			float num7 = wobblePitch;
			if (dragBlend > 0f)
			{
				float num8 = Time.time * 0.7f;
				num6 += (Mathf.PerlinNoise(num8, swaySeed) - 0.5f) * value * dragBlend;
				num7 += (Mathf.PerlinNoise(swaySeed + 3.7f, num8) - 0.5f) * value * dragBlend;
				float num9 = Mathf.Clamp01(brackenSpeed / 4f) * dragBlend;
				num7 += Mathf.Sin(Time.time * 7f) * value * 0.3f * num9;
				num6 += Mathf.Sin(Time.time * 3.5f) * value * 0.2f * num9;
			}
			wobble = Quaternion.Euler(num7, num6, 0f);
		}

		private static void ResetWobble()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			wobbleYaw = (wobblePitch = (wobbleYawVel = (wobblePitchVel = 0f)));
			dragBlend = 0f;
			brackenVelocity = (brackenAccel = Vector3.zero);
			wobble = Quaternion.identity;
			haveDragSafePoint = false;
			clearFraction = 1f;
			RestoreDraggedBody();
		}

		private static void MatchAliveCamera()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			matchedAliveCamera = false;
			if (Plugin.MatchAliveCamera.Value && !((Object)(object)cam == (Object)null) && !((Object)(object)player == (Object)null) && !((Object)(object)player.gameplayCamera == (Object)null))
			{
				Camera gameplayCamera = player.gameplayCamera;
				HDAdditionalCameraData component = ((Component)gameplayCamera).GetComponent<HDAdditionalCameraData>();
				HDAdditionalCameraData component2 = ((Component)cam).GetComponent<HDAdditionalCameraData>();
				cameraBackup = new GameObject("LethalDeathCam Camera Backup");
				Object.DontDestroyOnLoad((Object)(object)cameraBackup);
				backupCam = cameraBackup.AddComponent<Camera>();
				((Behaviour)backupCam).enabled = false;
				backupCam.CopyFrom(cam);
				if ((Object)(object)component2 != (Object)null)
				{
					backupHd = cameraBackup.GetComponent<HDAdditionalCameraData>() ?? cameraBackup.AddComponent<HDAdditionalCameraData>();
					component2.CopyTo(backupHd);
				}
				savedLayer = ((Component)cam).gameObject.layer;
				RenderTexture targetTexture = cam.targetTexture;
				int cullingMask = cam.cullingMask;
				cam.CopyFrom(gameplayCamera);
				if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null)
				{
					component.CopyTo(component2);
				}
				cam.targetTexture = targetTexture;
				cam.cullingMask = cullingMask;
				((Component)cam).gameObject.layer = savedLayer;
				matchedAliveCamera = true;
				Plugin.logger.LogInfo((object)$"Death cam uses your alive camera's settings (far clip {cam.farClipPlane:0}, render settings copied: {(Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null})");
			}
		}

		private static void RestoreSpectateCameraSettings()
		{
			if (matchedAliveCamera && (Object)(object)cam != (Object)null && (Object)(object)backupCam != (Object)null)
			{
				RenderTexture targetTexture = cam.targetTexture;
				cam.CopyFrom(backupCam);
				cam.targetTexture = targetTexture;
				((Component)cam).gameObject.layer = savedLayer;
				HDAdditionalCameraData component = ((Component)cam).GetComponent<HDAdditionalCameraData>();
				if ((Object)(object)backupHd != (Object)null && (Object)(object)component != (Object)null)
				{
					backupHd.CopyTo(component);
				}
			}
			if ((Object)(object)cameraBackup != (Object)null)
			{
				Object.Destroy((Object)(object)cameraBackup);
			}
			cameraBackup = null;
			backupCam = null;
			backupHd = null;
			matchedAliveCamera = false;
		}

		internal static bool BlocksSightOf(PlayerControllerB p)
		{
			if (state == State.Active && (Object)(object)p != (Object)null && (Object)(object)p == (Object)(object)player)
			{
				return p.isPlayerDead;
			}
			return false;
		}

		internal static void Tick()
		{
			//IL_006d: 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_0082: 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)
			PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null);
			if ((Object)(object)val == (Object)null)
			{
				wasDead = false;
				haveAliveView = false;
				if (state != State.Idle)
				{
					Stop("left the game");
				}
				return;
			}
			bool isPlayerDead = val.isPlayerDead;
			if (isPlayerDead)
			{
				deadSinceAlive = true;
			}
			if (!isPlayerDead && (Object)(object)val.gameplayCamera != (Object)null)
			{
				deathEyePosition = ((Component)val.gameplayCamera).transform.position;
				deathLookRotation = ((Component)val.gameplayCamera).transform.rotation;
				aliveInside = val.isInsideFactory;
				ClearStaleSpectateTarget(val);
				haveAliveView = true;
				lastAnimationEnemy = val.inAnimationWithEnemy;
			}
			if (isPlayerDead && !wasDead && state == State.Idle && Plugin.Enabled.Value && haveAliveView && !ShipIsLeaving)
			{
				StartDeathCam(val);
			}
			wasDead = isPlayerDead;
			UpdateFadeIn();
			if (state == State.Idle)
			{
				return;
			}
			try
			{
				if (!Plugin.Enabled.Value || (Object)(object)player == (Object)null || !player.isPlayerDead)
				{
					Stop("disabled or revived");
					return;
				}
				float num = Time.time - startTime;
				if (mode == DeathViewMode.FollowBody && targetKind == TargetKind.None && num > 0.75f)
				{
					Stop("nothing to follow (this death leaves no body)");
					return;
				}
				if (num > Plugin.Duration.Value)
				{
					EndSmoothly("time is up");
				}
				if (UpdateEnding())
				{
					return;
				}
				if ((Object)(object)StartOfRound.Instance == (Object)null || (Object)(object)StartOfRound.Instance.activeCamera != (Object)(object)cam)
				{
					Stop("another camera took over the screen");
				}
				else if (mode != DeathViewMode.FollowBody || CheckTarget())
				{
					UpdateSettling();
					UpdateMouseLook();
					UpdatePose(Time.deltaTime);
					ApplyPose();
					UpdateLight();
					LogNearbyLights();
					UpdateOwnBody();
					if (Time.time >= nextHudScan)
					{
						HideHud();
					}
				}
			}
			catch (Exception arg)
			{
				Plugin.logger.LogError((object)$"Death cam error, falling back to spectating: {arg}");
				Stop("error");
			}
		}

		internal static void OnLocalPlayerKilled(PlayerControllerB p)
		{
			try
			{
				if (state == State.Idle && Plugin.Enabled.Value && haveAliveView && !((Object)(object)p == (Object)null) && p.isPlayerDead && !ShipIsLeaving && !((Object)(object)GameNetworkManager.Instance == (Object)null) && !((Object)(object)p != (Object)(object)GameNetworkManager.Instance.localPlayerController))
				{
					StartDeathCam(p);
					wasDead = true;
				}
			}
			catch (Exception arg)
			{
				Plugin.logger.LogError((object)$"Death cam error, falling back to spectating: {arg}");
				Stop("error");
			}
		}

		private static void StartDeathCam(PlayerControllerB local)
		{
			player = local;
			startTime = Time.time;
			mode = Plugin.ViewMode.Value;
			loggedLookInput = false;
			loggedLookBlock = null;
			killer = (((Object)(object)local.inAnimationWithEnemy != (Object)null) ? local.inAnimationWithEnemy : lastAnimationEnemy);
			if ((Object)(object)killer != (Object)null)
			{
				Plugin.logger.LogInfo((object)("Killed during an animation with: " + EnemyName(killer)));
			}
			frameEnemy = PickKiller(local);
			brackenDeath = frameEnemy is FlowermanAI || killer is FlowermanAI;
			Plugin.logger.LogInfo((object)((mode == DeathViewMode.FrozenView) ? "Local player died: keeping the first-person view." : "Local player died, looking for something to follow..."));
			Begin();
			if (state == State.Active && mode == DeathViewMode.FollowBody)
			{
				CheckTarget();
			}
		}

		private static bool CheckTarget()
		{
			bool flag = TargetLost();
			if (!flag && targetKind != TargetKind.None && Time.time < nextRetarget)
			{
				return true;
			}
			nextRetarget = Time.time + 0.2f;
			if (TryFindTarget(out var kind, out var t, out var body))
			{
				if (kind != targetKind || (Object)(object)t != (Object)(object)rotationSource)
				{
					SwitchTarget(kind, t, body);
				}
			}
			else if (flag)
			{
				Stop("the body is gone");
				return false;
			}
			UpdateCarryingBracken();
			return true;
		}

		private static bool TargetLost()
		{
			TargetKind targetKind = DeathCam.targetKind;
			if ((uint)(targetKind - 1) <= 1u)
			{
				if (!((Object)(object)rotationSource == (Object)null) && !((Object)(object)targetBody == (Object)null))
				{
					return targetBody.deactivated;
				}
				return true;
			}
			return false;
		}

		private static bool TryFindTarget(out TargetKind kind, out Transform t, out DeadBodyInfo body)
		{
			kind = TargetKind.None;
			t = null;
			body = GetBody(player);
			if ((Object)(object)body == (Object)null)
			{
				return false;
			}
			if (TryFindDetachedHead(body, out t))
			{
				kind = TargetKind.DetachedHead;
				return true;
			}
			Transform val = ((targetKind == TargetKind.Body && (Object)(object)targetBody == (Object)(object)body && (Object)(object)rotationSource != (Object)null) ? rotationSource : FindHead(body));
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			kind = TargetKind.Body;
			t = val;
			return true;
		}

		private static void Begin()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_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)
			cam = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.spectateCamera : null);
			if ((Object)(object)cam == (Object)null)
			{
				Stop("no spectator camera found");
				return;
			}
			if ((Object)(object)StartOfRound.Instance.activeCamera != (Object)(object)cam)
			{
				StartOfRound.Instance.SwitchCamera(cam);
			}
			savedLocalPosition = ((Component)cam).transform.localPosition;
			savedLocalRotation = ((Component)cam).transform.localRotation;
			ourParent = ((Component)cam).transform.parent;
			ourLocalPosition = savedLocalPosition;
			ourLocalRotation = savedLocalRotation;
			savedFov = cam.fieldOfView;
			savedNearClip = cam.nearClipPlane;
			MatchAliveCamera();
			cam.fieldOfView = ((Plugin.FieldOfView.Value > 1f) ? Plugin.FieldOfView.Value : player.gameplayCamera.fieldOfView);
			cam.nearClipPlane = Plugin.NearClip.Value;
			poseRotation = deathLookRotation;
			posePosition = deathEyePosition;
			if (mode == DeathViewMode.FrozenView)
			{
				Plugin.logger.LogInfo((object)$"Death cam holding your view for {Plugin.Duration.Value:0.#}s");
			}
			if (!subscribed)
			{
				RenderPipelineManager.beginCameraRendering += OnBeginCameraRendering;
				subscribed = true;
			}
			state = State.Active;
			loggedRender = false;
			nextRetarget = Time.time;
			CreateLight();
			StartGhostAudio();
			HideHud();
			ApplyPose();
		}

		private static void SwitchTarget(TargetKind kind, Transform t, DeadBodyInfo body)
		{
			RestoreHiddenModels();
			ResetOwnBody();
			StartPositionBlend();
			lookYaw = 0f;
			lookPitch = 0f;
			settling = kind == TargetKind.Body && !brackenDeath;
			calmSince = -1f;
			targetStartTime = Time.time;
			targetKind = kind;
			targetBody = body;
			rotationSource = t;
			ResetBracken();
			switch (kind)
			{
			case TargetKind.DetachedHead:
				AttachDetachedHead(t);
				break;
			case TargetKind.Body:
				AttachBody(t);
				break;
			}
		}

		private static void Stop(string reason = null)
		{
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			if (reason != null && state != State.Idle)
			{
				Plugin.logger.LogInfo((object)("Death cam ended: " + reason + ((targetKind != TargetKind.Body || !Plugin.MouseLook.Value) ? "" : (loggedLookInput ? $" (view was turned {lookYaw:0}° sideways, {0f - lookPitch:0}° up)" : " (no mouse input was received)"))));
			}
			FinishEnding();
			DestroyLight();
			StopGhostAudio();
			if (state == State.Active)
			{
				RestoreHud();
			}
			RestoreHiddenModels();
			ResetOwnBody();
			RestoreSpectateCameraSettings();
			if (state == State.Active && (Object)(object)cam != (Object)null)
			{
				((Component)cam).transform.localPosition = savedLocalPosition;
				((Component)cam).transform.localRotation = savedLocalRotation;
				cam.fieldOfView = savedFov;
				cam.nearClipPlane = savedNearClip;
			}
			if (subscribed)
			{
				RenderPipelineManager.beginCameraRendering -= OnBeginCameraRendering;
				subscribed = false;
			}
			state = State.Idle;
			player = null;
			targetKind = TargetKind.None;
			rotationSource = null;
			positionAnchor = null;
			targetBody = null;
			ResetBracken();
			killer = null;
			frameEnemy = null;
			brackenDeath = false;
			settling = false;
			cam = null;
		}

		private static bool TryFindDetachedHead(DeadBodyInfo body, out Transform head)
		{
			head = null;
			if (!Plugin.DetachedHeadView.Value || !GetBool(f_detachedHead, body))
			{
				return false;
			}
			object field = GetField(f_detachedHeadObject, body);
			Transform val = (Transform)((field is Transform) ? field : null);
			if ((Object)(object)val == (Object)null || !((Component)val).gameObject.activeInHierarchy || !IsRealDetachedHead(val, body))
			{
				return false;
			}
			head = val;
			return true;
		}

		private static void AttachDetachedHead(Transform head)
		{
			//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_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0025: Unknown result type (might be due to invalid IL or missing references)
			positionAnchor = head;
			positionOffset = Vector3.zero;
			rotationOffset = Quaternion.Inverse(head.rotation) * poseRotation;
			HideRenderers(head);
			Plugin.logger.LogInfo((object)("Death cam: following your detached head '" + ((Object)head).name + "'"));
		}

		private static bool IsRealDetachedHead(Transform detached, DeadBodyInfo body)
		{
			bool num = ((Object)detached).name.IndexOf("leg", StringComparison.OrdinalIgnoreCase) >= 0;
			bool flag = ((Object)body).name.IndexOf("sliced", StringComparison.OrdinalIgnoreCase) >= 0 || ((Object)body).name.IndexOf("half", StringComparison.OrdinalIgnoreCase) >= 0;
			if (!num && !flag)
			{
				return true;
			}
			if ((Object)(object)loggedIgnoredPartFor != (Object)(object)body)
			{
				loggedIgnoredPartFor = body;
				Plugin.logger.LogInfo((object)("Body was cut in half: ignoring the separate piece '" + ((Object)detached).name + "', following the top half instead"));
			}
			return false;
		}

		private static void EndSmoothly(string reason)
		{
			if (endingReason == null)
			{
				if (Plugin.EndFade.Value <= 0f)
				{
					Stop(reason);
					return;
				}
				endingReason = reason;
				endingStart = Time.time;
			}
		}

		private static bool UpdateEnding()
		{
			if (endingReason == null)
			{
				return false;
			}
			float num = ((Plugin.EndFade.Value > 0f) ? ((Time.time - endingStart) / Plugin.EndFade.Value) : 1f);
			SetFade(Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(num)));
			if (num < 1f)
			{
				return false;
			}
			Stop(endingReason);
			return true;
		}

		private static void UpdateFadeIn()
		{
			if (!(fadeAlpha <= 0f) && endingReason == null)
			{
				float num = (Time.time - fadeInStart) / 0.35f;
				SetFade(1f - Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(num)));
			}
		}

		internal static void OnEndOfRound()
		{
			try
			{
				if (state != State.Idle)
				{
					endingReason = null;
					Stop("the round is over (Performance Report)");
					SetFade(0f);
				}
			}
			catch (Exception arg)
			{
				Plugin.logger.LogError((object)$"Death cam error at the end of the round: {arg}");
			}
		}

		private static void FinishEnding()
		{
			endingReason = null;
			if (fadeAlpha > 0f)
			{
				fadeInStart = Time.time - 0.35f * (1f - fadeAlpha);
			}
		}

		private static void SetFade(float alpha)
		{
			//IL_00d0: 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_002e: Expected O, but got Unknown
			//IL_0058: 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_0093: 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_00a9: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			fadeAlpha = alpha;
			if ((Object)(object)fadeObject == (Object)null)
			{
				if (alpha <= 0f)
				{
					return;
				}
				fadeObject = new GameObject("LethalDeathCam Fade");
				Object.DontDestroyOnLoad((Object)(object)fadeObject);
				Canvas obj = fadeObject.AddComponent<Canvas>();
				obj.renderMode = (RenderMode)0;
				obj.sortingOrder = 32767;
				GameObject val = new GameObject("Black");
				val.transform.SetParent(fadeObject.transform, false);
				fadeImage = val.AddComponent<Image>();
				((Graphic)fadeImage).raycastTarget = false;
				RectTransform rectTransform = ((Graphic)fadeImage).rectTransform;
				rectTransform.anchorMin = Vector2.zero;
				rectTransform.anchorMax = Vector2.one;
				Vector2 offsetMin = (rectTransform.offsetMax = Vector2.zero);
				rectTransform.offsetMin = offsetMin;
			}
			((Graphic)fadeImage).color = new Color(0f, 0f, 0f, alpha);
			fadeObject.SetActive(alpha > 0f);
		}

		private static FieldInfo Lookup(Type type, string name)
		{
			FieldInfo fieldInfo = AccessTools.Field(type, name);
			if (fieldInfo == null)
			{
				Plugin.logger.LogWarning((object)("Field " + type.Name + "." + name + " not found; that death view is disabled."));
			}
			return fieldInfo;
		}

		private static object GetField(FieldInfo f, object owner)
		{
			if (!(f != null) || owner == null)
			{
				return null;
			}
			return f.GetValue(owner);
		}

		private static bool GetBool(FieldInfo f, object owner)
		{
			object field = GetField(f, owner);
			bool flag = default(bool);
			int num;
			if (field is bool)
			{
				flag = (bool)field;
				num = 1;
			}
			else
			{
				num = 0;
			}
			return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
		}

		private static void StartGhostAudio()
		{
			ghostAudioOn = false;
			if (Plugin.GhostAudio.Value && !((Object)(object)SoundManager.Instance == (Object)null))
			{
				SoundManager.Instance.SetDiageticMixerSnapshot(1, Plugin.GhostAudioFade.Value);
				ghostAudioOn = true;
			}
		}

		internal static bool AllowMixerSnapshot(int snapshotID)
		{
			if (ghostAudioOn)
			{
				return snapshotID != 0;
			}
			return true;
		}

		private static void StopGhostAudio()
		{
			if (ghostAudioOn)
			{
				ghostAudioOn = false;
				if ((Object)(object)SoundManager.Instance != (Object)null && SoundManager.Instance.currentMixerSnapshotID == 1)
				{
					SoundManager.Instance.SetDiageticMixerSnapshot(0, Plugin.GhostAudioFade.Value);
				}
			}
		}

		private static void HideRenderers(Transform root, bool includeSkinned = true)
		{
			if (!Plugin.HideOwnHead.Value)
			{
				return;
			}
			Renderer[] componentsInChildren = ((Component)root).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && !val.forceRenderingOff && (includeSkinned || !(val is SkinnedMeshRenderer)))
				{
					val.forceRenderingOff = true;
					hiddenRenderers.Add(val);
				}
			}
		}

		private static void RestoreHiddenModels()
		{
			foreach (Renderer hiddenRenderer in hiddenRenderers)
			{
				if ((Object)(object)hiddenRenderer != (Object)null)
				{
					hiddenRenderer.forceRenderingOff = false;
				}
			}
			hiddenRenderers.Clear();
		}

		private static void HideHud()
		{
			nextHudScan = Time.time + 0.25f;
			if (!Plugin.HideHud.Value || (Object)(object)HUDManager.Instance == (Object)null)
			{
				return;
			}
			object value = Traverse.Create((object)HUDManager.Instance).Field("HUDContainer").GetValue();
			GameObject val = (GameObject)((value is GameObject) ? value : null);
			HashSet<Transform> hashSet = new HashSet<Transform>();
			AddRootCanvas(hashSet, val);
			AddRootCanvas(hashSet, HudObject("spectatingPlayerText"));
			AddRootCanvas(hashSet, HudObject("SpectateBoxesContainer"));
			AddRootCanvas(hashSet, HudObject("spectatorTipText"));
			List<Transform> parents = EscapeMenuPanels(((Object)(object)val != (Object)null) ? val.transform : null);
			foreach (Transform item in hashSet)
			{
				CanvasRenderer[] componentsInChildren = ((Component)item).GetComponentsInChildren<CanvasRenderer>(true);
				foreach (CanvasRenderer val2 in componentsInChildren)
				{
					if (!((Object)(object)val2 == (Object)null) && !hiddenHud.ContainsKey(val2) && !IsScreenImage(val2) && !IsInAny(((Component)val2).transform, parents))
					{
						hiddenHud[val2] = val2.GetAlpha();
						val2.SetAlpha(0f);
					}
				}
			}
		}

		private static void RestoreHud()
		{
			foreach (KeyValuePair<CanvasRenderer, float> item in hiddenHud)
			{
				if ((Object)(object)item.Key != (Object)null)
				{
					item.Key.SetAlpha(item.Value);
				}
			}
			hiddenHud.Clear();
		}

		private static List<Transform> EscapeMenuPanels(Transform hud)
		{
			List<Transform> list = new List<Transform>();
			QuickMenuManager val = (((Object)(object)player != (Object)null && (Object)(object)player.quickMenuManager != (Object)null) ? player.quickMenuManager : Object.FindObjectOfType<QuickMenuManager>());
			if ((Object)(object)val == (Object)null)
			{
				return list;
			}
			FieldInfo[] fields = typeof(QuickMenuManager).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			int num = 0;
			while (num < fields.Length)
			{
				object value = fields[num].GetValue(val);
				GameObject val2 = (GameObject)((value is GameObject) ? value : null);
				Transform val4;
				if (val2 == null)
				{
					Component val3 = (Component)((value is Component) ? value : null);
					if (val3 == null || !((Object)(object)val3 != (Object)null))
					{
						goto IL_00ac;
					}
					val4 = val3.transform;
				}
				else
				{
					if (!((Object)(object)val2 != (Object)null))
					{
						goto IL_00ac;
					}
					val4 = val2.transform;
				}
				goto IL_00af;
				IL_00af:
				Transform val5 = val4;
				if (!((Object)(object)val5 == (Object)null) && !((Object)(object)((Component)val5).GetComponentInParent<Canvas>(true) == (Object)null) && (!((Object)(object)hud != (Object)null) || !hud.IsChildOf(val5)))
				{
					list.Add(val5);
				}
				num++;
				continue;
				IL_00ac:
				val4 = null;
				goto IL_00af;
			}
			return list;
		}

		private static bool IsInAny(Transform t, List<Transform> parents)
		{
			foreach (Transform parent in parents)
			{
				if (t.IsChildOf(parent))
				{
					return true;
				}
			}
			return false;
		}

		private static GameObject HudObject(string field)
		{
			object value = Traverse.Create((object)HUDManager.Instance).Field(field).GetValue();
			GameObject val = (GameObject)((value is GameObject) ? value : null);
			if (val == null)
			{
				Component val2 = (Component)((value is Component) ? value : null);
				if (val2 != null)
				{
					return ((Object)(object)val2 != (Object)null) ? val2.gameObject : null;
				}
				return null;
			}
			return val;
		}

		internal static void AfterSpectateUIUpdate()
		{
			if (state == State.Active)
			{
				HideHud();
			}
		}

		private static void AddRootCanvas(HashSet<Transform> roots, GameObject go)
		{
			if (!((Object)(object)go == (Object)null))
			{
				Canvas componentInParent = go.GetComponentInParent<Canvas>();
				if ((Object)(object)componentInParent != (Object)null)
				{
					roots.Add(((Component)componentInParent.rootCanvas).transform);
				}
			}
		}

		private static bool IsScreenImage(CanvasRenderer cr)
		{
			Component component = ((Component)cr).GetComponent("RawImage");
			if ((Object)(object)component == (Object)null)
			{
				return false;
			}
			return ((object)component).GetType().GetProperty("texture")?.GetValue(component) is RenderTexture;
		}

		internal static void OnKillPlayer(PlayerControllerB p)
		{
			//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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)GameNetworkManager.Instance == (Object)null || (Object)(object)p != (Object)(object)GameNetworkManager.Instance.localPlayerController || p.isPlayerDead)
				{
					return;
				}
				if ((Object)(object)p.gameplayCamera != (Object)null)
				{
					deathEyePosition = ((Component)p.gameplayCamera).transform.position;
					deathLookRotation = ((Component)p.gameplayCamera).transform.rotation;
					haveAliveView = true;
				}
				Type type = null;
				StackFrame[] array = new StackTrace(1, fNeedFileInfo: false).GetFrames() ?? Array.Empty<StackFrame>();
				for (int i = 0; i < array.Length; i++)
				{
					Type type2 = array[i].GetMethod()?.DeclaringType;
					while (type2 != null)
					{
						if (typeof(EnemyAI).IsAssignableFrom(type2))
						{
							type = type2;
							break;
						}
						type2 = type2.DeclaringType;
					}
					if (type != null)
					{
						break;
					}
				}
				killCallEnemy = null;
				killCallTime = Time.time;
				if (type == null)
				{
					return;
				}
				float num = 30f;
				Object[] array2 = Object.FindObjectsOfType(type);
				foreach (Object obj in array2)
				{
					EnemyAI val = (EnemyAI)(object)((obj is EnemyAI) ? obj : null);
					if (val != null && !((Object)(object)val == (Object)null))
					{
						float num2 = Vector3.Distance(((Component)val).transform.position, ((Component)p).transform.position);
						if (num2 < num)
						{
							num = num2;
							killCallEnemy = val;
						}
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.logger.LogWarning((object)("Couldn't tell which enemy killed you: " + ex.Message));
			}
		}

		private static EnemyAI PickKiller(PlayerControllerB p)
		{
			if ((Object)(object)killCallEnemy != (Object)null && Time.time - killCallTime < 1f)
			{
				Plugin.logger.LogInfo((object)("Killed by: " + EnemyName(killCallEnemy)));
				return killCallEnemy;
			}
			if ((Object)(object)killer != (Object)null)
			{
				Plugin.logger.LogInfo((object)("Killed by: " + EnemyName(killer) + " (kill animation)"));
				return killer;
			}
			Plugin.logger.LogInfo((object)"No enemy killed you (or it couldn't be identified)");
			return null;
		}

		private static string EnemyName(EnemyAI e)
		{
			if (!((Object)(object)e.enemyType != (Object)null) || string.IsNullOrEmpty(e.enemyType.enemyName))
			{
				return ((Object)e).name;
			}
			return e.enemyType.enemyName;
		}

		private static void CreateLight()
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: 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_0100: 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)
			DestroyLight();
			loggedNearbyLights = false;
			diedInside = (Object)(object)player != (Object)null && (aliveInside || player.isInsideFactory);
			if (!((Object)(object)player == (Object)null) && !((Object)(object)player.nightVision == (Object)null) && !((Object)(object)cam == (Object)null))
			{
				deathLight = Object.Instantiate<GameObject>(((Component)player.nightVision).gameObject);
				((Object)deathLight).name = "LethalDeathCam Light";
				lightPosition = LightTargetPosition();
				deathLight.transform.position = lightPosition;
				deathLightComp = deathLight.GetComponent<Light>();
				if ((Object)(object)deathLightComp == (Object)null)
				{
					DestroyLight();
					return;
				}
				sourceLight = player.nightVision;
				baseIntensity = deathLightComp.intensity;
				baseRange = deathLightComp.range;
				baseColor = deathLightComp.color;
				Plugin.logger.LogInfo((object)($"Death cam light: copied the game's light (intensity {baseIntensity:0.###}, range {baseRange:0.##}, " + $"colour {baseColor}, was on: {((Behaviour)sourceLight).enabled && ((Component)sourceLight).gameObject.activeInHierarchy}, died inside: {diedInside})"));
				UpdateLight();
			}
		}

		private static void UpdateLight()
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: 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_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)deathLightComp == (Object)null)
			{
				return;
			}
			bool flag = Plugin.DeathLight.Value switch
			{
				DeathLightMode.Always => true, 
				DeathLightMode.Inside => diedInside, 
				_ => false, 
			};
			if (deathLight.activeSelf != flag)
			{
				deathLight.SetActive(flag);
			}
			if (flag)
			{
				if ((Object)(object)sourceLight != (Object)null && ((Behaviour)sourceLight).isActiveAndEnabled && sourceLight.intensity > 0f)
				{
					baseIntensity = sourceLight.intensity;
					baseRange = sourceLight.range;
					baseColor = sourceLight.color;
				}
				lightPosition = Vector3.Lerp(lightPosition, LightTargetPosition(), 1f - Mathf.Exp(-8f * Time.deltaTime));
				deathLight.transform.position = lightPosition;
				((Behaviour)deathLightComp).enabled = true;
				deathLightComp.intensity = baseIntensity * Plugin.LightBrightness.Value;
				deathLightComp.range = baseRange * Plugin.LightRange.Value;
				deathLightComp.color = (Plugin.LightNeutralColor.Value ? Color.white : baseColor);
			}
		}

		private static Vector3 LightTargetPosition()
		{
			//IL_000a: 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_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_0052: 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_005f: 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_0077: 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_0089: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Vector3 position = ((Component)cam).transform.position;
			int num = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.collidersAndRoomMaskAndDefault : (-5));
			RaycastHit val = default(RaycastHit);
			float num2 = (Physics.Raycast(position, Vector3.down, ref val, 3f, num, (QueryTriggerInteraction)1) ? ((RaycastHit)(ref val)).point.y : (position.y - 0.3f));
			Vector3 val2 = default(Vector3);
			((Vector3)(ref val2))..ctor(position.x, Mathf.Max(num2 + 1.6f, position.y), position.z);
			float num3 = val2.y - position.y;
			RaycastHit val3 = default(RaycastHit);
			if (num3 > 0.01f && Physics.Raycast(position, Vector3.up, ref val3, num3 + 0.15f, num, (QueryTriggerInteraction)1))
			{
				val2.y = Mathf.Max(position.y, ((RaycastHit)(ref val3)).point.y - 0.15f);
			}
			return val2;
		}

		internal static void AfterNightVisionUpdate(PlayerControllerB p)
		{
			if (!((Object)(object)p == (Object)null) && !((Object)(object)p.nightVision == (Object)null) && ((Behaviour)p.nightVision).enabled)
			{
				PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null);
				if (!((Object)(object)val == (Object)null) && !((Object)(object)p == (Object)(object)val) && (state == State.Active || !val.isPlayerDead))
				{
					((Behaviour)p.nightVision).enabled = false;
				}
			}
		}

		private static void ClearStaleSpectateTarget(PlayerControllerB local)
		{
			if ((Object)(object)local.spectatedPlayerScript != (Object)null)
			{
				Plugin.logger.LogInfo((object)("You're alive but still marked as spectating " + local.spectatedPlayerScript.playerUsername + " (e.g. after a revive): cleared"));
				local.spectatedPlayerScript = null;
			}
			if (deadSinceAlive)
			{
				SwitchOffOldBodyRadarLights(local);
			}
			deadSinceAlive = false;
		}

		private static void SwitchOffOldBodyRadarLights(PlayerControllerB local)
		{
			DeadBodyInfo[] array = Object.FindObjectsOfType<DeadBodyInfo>();
			foreach (DeadBodyInfo val in array)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.playerScript != (Object)(object)local) && !((Object)(object)val.nightVisionRadar == (Object)null) && ((Behaviour)val.nightVisionRadar).enabled)
				{
					((Behaviour)val.nightVisionRadar).enabled = false;
					Plugin.logger.LogInfo((object)"You're alive again: switched off the radar light left on your old body");
				}
			}
		}

		private static void LogNearbyLights()
		{
			if (!loggedNearbyLights && !((Object)(object)cam == (Object)null) && !(Time.time - startTime < 1.5f))
			{
				loggedNearbyLights = true;
				LogLightsAround(cam, "Death cam");
			}
		}

		internal static void LogLightsNow()
		{
			Camera val = (((Object)(object)StartOfRound.Instance != (Object)null && (Object)(object)StartOfRound.Instance.activeCamera != (Object)null) ? StartOfRound.Instance.activeCamera : Camera.main);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.logger.LogInfo((object)"Log nearby lights: no camera found");
			}
			else
			{
				LogLightsAround(val, "Lights around your view ('" + ((Object)val).name + "')");
			}
		}

		private static void LogLightsAround(Camera view, string title)
		{
			//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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Invalid comparison between Unknown and I4
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_0113: 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)
			Vector3 position = ((Component)view).transform.position;
			PlayerControllerB local = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null);
			StringBuilder stringBuilder = new StringBuilder(title + ": lights near the camera:");
			int num = 0;
			Light[] array = Object.FindObjectsOfType<Light>();
			foreach (Light val in array)
			{
				if ((Object)(object)val == (Object)null || !((Behaviour)val).isActiveAndEnabled || val.intensity <= 0f)
				{
					continue;
				}
				if ((int)val.type == 1)
				{
					stringBuilder.Append($"\n  [sun/moon] {Path(((Component)val).transform)} colour {val.color} intensity {val.intensity:0.##}");
					num++;
					continue;
				}
				float num2 = Vector3.Distance(((Component)val).transform.position, position);
				if (!(num2 > Mathf.Max(val.range, 1f) + 1f))
				{
					stringBuilder.Append($"\n  {Path(((Component)val).transform)} ({val.type}) {num2:0.0}m away, range {val.range:0.#}, colour {val.color}, intensity {val.intensity:0.##}" + (((Object)(object)val == (Object)(object)deathLightComp) ? "  <- death cam light" : "") + Owner(val, local));
					num++;
				}
			}
			if ((Object)(object)deathLight != (Object)null && deathLight.transform.childCount > 0)
			{
				stringBuilder.Append($"\n  (the death cam light copy has {deathLight.transform.childCount} child object(s))");
			}
			Plugin.logger.LogInfo((object)((num == 0) ? (title + ": no lights near the camera") : stringBuilder.ToString()));
		}

		private static string Owner(Light l, PlayerControllerB local)
		{
			PlayerControllerB componentInParent = ((Component)l).GetComponentInParent<PlayerControllerB>();
			if ((Object)(object)componentInParent != (Object)null && (Object)(object)l == (Object)(object)componentInParent.nightVision)
			{
				return "  <- night vision of " + componentInParent.playerUsername + (((Object)(object)componentInParent == (Object)(object)local) ? " (you)" : "") + (componentInParent.isPlayerDead ? ", dead" : "");
			}
			GrabbableObject componentInParent2 = ((Component)l).GetComponentInParent<GrabbableObject>();
			if ((Object)(object)componentInParent2 != (Object)null)
			{
				return "  <- item '" + (((Object)(object)componentInParent2.itemProperties != (Object)null) ? componentInParent2.itemProperties.itemName : ((Object)componentInParent2).name) + "'" + (((Object)(object)componentInParent2.playerHeldBy != (Object)null) ? (", held by " + componentInParent2.playerHeldBy.playerUsername) : "");
			}
			DeadBodyInfo componentInParent3 = ((Component)l).GetComponentInParent<DeadBodyInfo>();
			if ((Object)(object)componentInParent3 != (Object)null)
			{
				if (!((Object)(object)l == (Object)(object)componentInParent3.nightVisionRadar))
				{
					return "  <- on a dead body";
				}
				return "  <- ship radar light on " + (((Object)(object)componentInParent3.playerScript != (Object)null) ? componentInParent3.playerScript.playerUsername : "a") + "'s dead body (the game's green body glow)";
			}
			if ((Object)(object)componentInParent != (Object)null)
			{
				return "  <- on player " + componentInParent.playerUsername;
			}
			return "";
		}

		private static string Path(Transform t)
		{
			string text = ((Object)t).name;
			for (int i = 0; i < 3; i++)
			{
				if (!((Object)(object)t.parent != (Object)null))
				{
					break;
				}
				t = t.parent;
				text = ((Object)t).name + "/" + text;
			}
			return text;
		}

		private static void DestroyLight()
		{
			if ((Object)(object)deathLight != (Object)null)
			{
				Object.Destroy((Object)(object)deathLight);
			}
			deathLight = null;
			deathLightComp = null;
			sourceLight = null;
		}

		private static Vector2 ReadLook()
		{
			//IL_0058: 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_005d: 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_005f: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			if (lookAction == null && (Object)(object)IngamePlayerSettings.Instance != (Object)null && (Object)(object)IngamePlayerSettings.Instance.playerInput != (Object)null)
			{
				lookAction = IngamePlayerSettings.Instance.playerInput.actions.FindAction("Look", false);
			}
			Vector2 val = ((lookAction != null) ? lookAction.ReadValue<Vector2>() : Vector2.zero);
			if (val == Vector2.zero && Mouse.current != null)
			{
				val = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).delta).ReadValue();
			}
			return val;
		}

		private static void LogLookBlock(string reason)
		{
			if (!(loggedLookBlock == reason))
			{
				loggedLookBlock = reason;
				Plugin.logger.LogInfo((object)("Mouse look paused: " + reason));
			}
		}

		private static void UpdateMouseLook()
		{
			//IL_006d: 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_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_00e1: 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_007b: 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_0101: 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)
			if (!MouseLookAllowed)
			{
				return;
			}
			if ((Object)(object)player != (Object)null && player.isTypingChat)
			{
				LogLookBlock("typing in chat");
				return;
			}
			if ((Object)(object)player != (Object)null && (Object)(object)player.quickMenuManager != (Object)null && player.quickMenuManager.isMenuOpen)
			{
				LogLookBlock("menu open");
				return;
			}
			loggedLookBlock = null;
			Vector2 val = ReadLook();
			if (!loggedLookInput && val != Vector2.zero)
			{
				loggedLookInput = true;
				Plugin.logger.LogInfo((object)string.Format("Mouse look: receiving input ({0}), first movement {1}", (lookAction != null) ? "game Look action" : "mouse", val));
			}
			Vector2 val2 = val * (0.08f * Plugin.MouseSensitivity.Value);
			float value = Plugin.MaxLookAngle.Value;
			lookYaw = Mathf.Clamp(lookYaw + val2.x, 0f - value, value);
			float num = (Plugin.InvertMouseY.Value ? val2.y : (0f - val2.y));
			lookPitch = Mathf.Clamp(lookPitch + num, 0f - Mathf.Min(value, 85f), Mathf.Min(value, 85f));
		}

		private static void UpdateSettling()
		{
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			if (!settling || (Object)(object)targetBody == (Object)null)
			{
				return;
			}
			if ((Object)(object)carryingBracken != (Object)null)
			{
				calmSince = -1f;
				return;
			}
			Rigidbody[] array = targetBody.bodyParts?.Where((Rigidbody r) => (Object)(object)r != (Object)null && !r.isKinematic).ToArray() ?? Array.Empty<Rigidbody>();
			if (array.Length == 0 || array.Average(delegate(Rigidbody r)
			{
				//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)
				Vector3 velocity = r.velocity;
				return ((Vector3)(ref velocity)).magnitude;
			}) < 0.35f)
			{
				if (calmSince < 0f)
				{
					calmSince = Time.time;
				}
			}
			else
			{
				calmSince = -1f;
			}
			float num = Time.time - targetStartTime;
			if ((calmSince >= 0f && Time.time - calmSince > 0.4f && num > 0.6f) || num > 4f)
			{
				settling = false;
				lookYaw = 0f;
				lookPitch = 0f;
				lookBase = poseRotation;
				if (Plugin.MouseLook.Value && !brackenDeath)
				{
					Plugin.logger.LogInfo((object)"Body came to rest: mouse look enabled");
				}
			}
		}

		private static Vector3 KeepOutOfOwnBody(Vector3 camera)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_0125: 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_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_00d5: Unknown result type (might be due to invalid IL or missing references)
			if (targetKind != TargetKind.Body || (Object)(object)targetBody == (Object)null || targetBody.bodyParts == null || (Object)(object)positionAnchor == (Object)null)
			{
				return camera;
			}
			Vector3 position = positionAnchor.position;
			Vector3 val = camera - position;
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (magnitude < 0.001f)
			{
				return camera;
			}
			Ray val2 = default(Ray);
			((Ray)(ref val2))..ctor(position, val / magnitude);
			float num = magnitude;
			Rigidbody[] bodyParts = targetBody.bodyParts;
			RaycastHit val5 = default(RaycastHit);
			foreach (Rigidbody val3 in bodyParts)
			{
				if ((Object)(object)val3 == (Object)null || (Object)(object)((Component)val3).transform == (Object)(object)rotationSource)
				{
					continue;
				}
				Collider[] components = ((Component)val3).GetComponents<Collider>();
				foreach (Collider val4 in components)
				{
					if (!((Object)(object)val4 == (Object)null) && val4.enabled && !ContainsHead(val4) && val4.Raycast(val2, ref val5, magnitude + 0.08f))
					{
						num = Mathf.Min(num, Mathf.Max(0f, ((RaycastHit)(ref val5)).distance - 0.08f));
					}
				}
			}
			return position + ((Ray)(ref val2)).direction * num;
		}

		private static bool ContainsHead(Collider col)
		{
			//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_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_002c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)rotationSource != (Object)null)
			{
				Vector3 val = col.ClosestPoint(rotationSource.position) - rotationSource.position;
				return ((Vector3)(ref val)).sqrMagnitude < 0.0001f;
			}
			return false;
		}

		private static void UpdateOwnBody()
		{
			OwnBodyMode value = Plugin.HideOwnBody.Value;
			if (targetKind != TargetKind.Body || (Object)(object)targetBody == (Object)null || (Object)(object)cam == (Object)null || value == OwnBodyMode.Never)
			{
				ShowOwnBody();
			}
			else
			{
				if ((Object)(object)carryingBracken != (Object)null && Plugin.BrackenHideBody.Value)
				{
					return;
				}
				if (value == OwnBodyMode.Always)
				{
					ClearHiddenLimbs();
					HideWholeBody();
					return;
				}
				ShowWholeBody();
				HashSet<Transform> hashSet = LimbsOverLens();
				bool flag = false;
				foreach (Transform item in hashSet)
				{
					if (!hiddenLimbs.ContainsKey(item))
					{
						flag = true;
						if (loggedLimbs.Add(item))
						{
							Plugin.logger.LogInfo((object)("Your " + ((Object)item).name + " was over the camera: hiding it until it moves away"));
						}
					}
					hiddenLimbs[item] = -1f;
				}
				foreach (Transform item2 in hiddenLimbs.Keys.ToList())
				{
					if (!hashSet.Contains(item2))
					{
						float num = hiddenLimbs[item2];
						if (num < 0f)
						{
							hiddenLimbs[item2] = Time.time;
						}
						else if (Time.time - num > 0.5f)
						{
							hiddenLimbs.Remove(item2);
							flag = true;
						}
					}
				}
				if (flag)
				{
					ApplyLimbs();
				}
			}
		}

		private static HashSet<Transform> LimbsOverLens()
		{
			//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_00b5: 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_00bb: 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_00e8: 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_00f0: 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_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_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_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_0132: 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_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: 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)
			HashSet<Transform> hashSet = new HashSet<Transform>();
			Transform transform = ((Component)cam).transform;
			Vector3 position = transform.position;
			float num = Mathf.Tan(cam.fieldOfView * 0.5f * ((float)Math.PI / 180f));
			Rigidbody[] bodyParts = targetBody.bodyParts;
			RaycastHit val5 = default(RaycastHit);
			foreach (Rigidbody val in bodyParts)
			{
				if ((Object)(object)val == (Object)null || !IsLimb(((Component)val).transform))
				{
					continue;
				}
				bool flag = false;
				bool flag2 = false;
				int num2 = 0;
				Collider[] components = ((Component)val).GetComponents<Collider>();
				foreach (Collider val2 in components)
				{
					if ((Object)(object)val2 == (Object)null || !val2.enabled || ContainsHead(val2))
					{
						continue;
					}
					Vector3 val3 = val2.ClosestPoint(position) - position;
					if (((Vector3)(ref val3)).sqrMagnitude < 0.0001f)
					{
						flag = true;
						break;
					}
					for (int k = 0; k < blockProbes.Length; k++)
					{
						Vector2 val4 = blockProbes[k];
						val3 = transform.forward + transform.right * (val4.x * num * cam.aspect) + transform.up * (val4.y * num);
						Vector3 normalized = ((Vector3)(ref val3)).normalized;
						if (val2.Raycast(new Ray(position, normalized), ref val5, 0.3f))
						{
							num2++;
							if (k == 0)
							{
								flag2 = true;
							}
						}
					}
				}
				if (flag || flag2 || num2 >= 2)
				{
					hashSet.Add(LimbRoot(((Component)val).transform));
				}
			}
			return hashSet;
		}

		private static bool IsLimb(Transform t)
		{
			if ((Object)(object)t == (Object)null || (Object)(object)t == (Object)(object)rotationSource || (Object)(object)t == (Object)(object)((Component)targetBody).transform)
			{
				return false;
			}
			if (((Object)t).name.IndexOf("spine", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return false;
			}
			if (((Object)t).name.IndexOf("ragdoll", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return false;
			}
			return (Object)(object)((Component)t).GetComponent<Rigidbody>() != (Object)null;
		}

		private static Transform LimbRoot(Transform t)
		{
			while ((Object)(object)t.parent != (Object)null && IsLimb(t.parent))
			{
				t = t.parent;
			}
			return t;
		}

		private static void ApplyLimbs()
		{
			if ((Object)(object)targetBody == (Object)null)
			{
				return;
			}
			if (originalBones.Count == 0)
			{
				SkinnedMeshRenderer[] componentsInChildren = ((Component)targetBody).GetComponentsInChildren<SkinnedMeshRenderer>(true);
				foreach (SkinnedMeshRenderer val in componentsInChildren)
				{
					if ((Object)(object)val != (Object)null && val.bones != null)
					{
						originalBones[val] = val.bones;
					}
				}
			}
			foreach (KeyValuePair<SkinnedMeshRenderer, Transform[]> originalBone in originalBones)
			{
				if ((Object)(object)originalBone.Key == (Object)null)
				{
					continue;
				}
				Transform[] array = (Transform[])originalBone.Value.Clone();
				for (int j = 0; j < array.Length; j++)
				{
					if ((Object)(object)array[j] != (Object)null && IsHiddenBone(array[j]))
					{
						array[j] = StandIn(array[j]);
					}
				}
				originalBone.Key.bones = array;
			}
		}

		private static bool IsHiddenBone(Transform bone)
		{
			if (!((Object)(object)hiddenHead != (Object)null) || !bone.IsChildOf(hiddenHead))
			{
				return hiddenLimbs.Keys.Any((Transform limb) => (Object)(object)limb != (Object)null && bone.IsChildOf(limb));
			}
			return true;
		}

		private static void HideHeadOnScreen(Transform head)
		{
			hiddenHead = head;
			ApplyLimbs();
			HideRenderers(head, includeSkinned: false);
		}

		private static Transform StandIn(Transform bone)
		{
			//IL_001f: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			if (standInBones.TryGetValue(bone, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			value = new GameObject("LethalDeathCam hidden bone").transform;
			value.SetParent(bone, false);
			value.localPosition = Vector3.zero;
			value.localRotation = Quaternion.identity;
			value.localScale = Vector3.one * 0.001f;
			standInBones[bone] = value;
			return value;
		}

		private static void ClearHiddenLimbs()
		{
			if (hiddenLimbs.Count != 0)
			{
				hiddenLimbs.Clear();
				ApplyLimbs();
			}
		}

		private static void RestoreAllBones()
		{
			foreach (KeyValuePair<SkinnedMeshRenderer, Transform[]> originalBone in originalBones)
			{
				if ((Object)(object)originalBone.Key != (Object)null)
				{
					originalBone.Key.bones = originalBone.Value;
				}
			}
			originalBones.Clear();
			hiddenLimbs.Clear();
			hiddenHead = null;
			foreach (Transform value in standInBones.Values)
			{
				if ((Object)(object)value != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)value).gameObject);
				}
			}
			standInBones.Clear();
		}

		private static void HideWholeBody()
		{
			if (wholeBodyIsHidden)
			{
				return;
			}
			wholeBodyIsHidden = true;
			Renderer[] componentsInChildren = ((Component)targetBody).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && !val.forceRenderingOff)
				{
					val.forceRenderingOff = true;
					wholeBodyHidden.Add(val);
				}
			}
			Plugin.logger.LogInfo((object)"Hiding your body from your view");
		}

		private static void ShowWholeBody()
		{
			foreach (Renderer item in wholeBodyHidden)
			{
				if ((Object)(object)item != (Object)null)
				{
					item.forceRenderingOff = false;
				}
			}
			wholeBodyHidden.Clear();
			wholeBodyIsHidden = false;
		}

		private static void ShowOwnBody()
		{
			ClearHiddenLimbs();
			ShowWholeBody();
		}

		private static void ResetOwnBody()
		{
			RestoreAllBones();
			ShowWholeBody();
			loggedLimbs.Clear();
		}

		private static void StartPositionBlend()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			blendFrom = posePosition;
			blendStart = Time.time;
		}

		private static Quaternion TargetRotation()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0032: Unknown result type (might be due to invalid IL or missing references)
			Quaternion val = rotationSource.rotation * rotationOffset;
			if (TryDragRotation(out var rotation))
			{
				val = rotation;
			}
			if (Plugin.LockRoll.Value)
			{
				val = Level(val);
			}
			return val;
		}

		private static void HeadingAndPitch(Quaternion q, out float yaw, out float pitch)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = q * Vector3.forward;
			Vector3 v = q * Vector3.up;
			Vector3 val2 = Flat(val) - Flat(v) * val.y;
			yaw = ((((Vector3)(ref val2)).sqrMagnitude > 1E-08f) ? (Mathf.Atan2(val2.x, val2.z) * 57.29578f) : 0f);
			pitch = (0f - Mathf.Asin(Mathf.Clamp(val.y, -1f, 1f))) * 57.29578f;
		}

		private static Quaternion Level(Quaternion q)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missin