Decompiled source of TrumpParodyEmotes v0.7.0

TrumpParodyEmotes.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TrumpParodyEmotes")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.7.0.0")]
[assembly: AssemblyInformationalVersion("0.7.0")]
[assembly: AssemblyProduct("TrumpParodyEmotes")]
[assembly: AssemblyTitle("TrumpParodyEmotes")]
[assembly: AssemblyVersion("0.7.0.0")]
namespace TrumpParodyEmotes;

internal static class Clips
{
	private static readonly Dictionary<int, AudioClip> loaded = new Dictionary<int, AudioClip>();

	internal static AudioClip For(int line)
	{
		if (line < 1 || line > 7)
		{
			return null;
		}
		if (loaded.TryGetValue(line, out var value))
		{
			return value;
		}
		string path = Path.Combine(Plugin.Folder, "line" + line + ".wav");
		try
		{
			if (File.Exists(path))
			{
				value = Parse(File.OpenRead(path), "line" + line);
			}
			else
			{
				Stream manifestResourceStream = typeof(Clips).Assembly.GetManifestResourceStream("line" + line + ".wav");
				if (manifestResourceStream != null)
				{
					value = Parse(manifestResourceStream, "line" + line);
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Could not load " + Path.GetFileName(path) + ": " + ex.Message));
		}
		return loaded[line] = value;
	}

	private static AudioClip Parse(Stream stream, string name)
	{
		BinaryReader r = new BinaryReader(stream);
		try
		{
			if (Tag() != "RIFF")
			{
				throw new InvalidDataException("not a WAV file");
			}
			r.ReadInt32();
			if (Tag() != "WAVE")
			{
				throw new InvalidDataException("not a WAV file");
			}
			int num = 0;
			int num2 = 0;
			while (r.BaseStream.Position + 8 <= r.BaseStream.Length)
			{
				string text = Tag();
				int num3 = r.ReadInt32();
				long position = r.BaseStream.Position + num3 + (num3 & 1);
				if (text == "fmt ")
				{
					short num4 = r.ReadInt16();
					num = r.ReadInt16();
					num2 = r.ReadInt32();
					r.ReadInt32();
					r.ReadInt16();
					if (num4 != 1 || r.ReadInt16() != 16)
					{
						throw new InvalidDataException("only 16-bit PCM is supported");
					}
				}
				else if (text == "data")
				{
					if (num < 1 || num2 < 1)
					{
						throw new InvalidDataException("no format before the data");
					}
					byte[] array = r.ReadBytes(num3);
					float[] array2 = new float[array.Length / 2];
					for (int i = 0; i < array2.Length; i++)
					{
						array2[i] = (float)(short)(array[i * 2] | (array[i * 2 + 1] << 8)) / 32768f;
					}
					AudioClip obj = AudioClip.Create(name, array2.Length / num, num, num2, false);
					((Object)obj).hideFlags = (HideFlags)61;
					obj.SetData(array2, 0);
					return obj;
				}
				r.BaseStream.Position = position;
			}
			throw new InvalidDataException("no audio data");
		}
		finally
		{
			if (r != null)
			{
				((IDisposable)r).Dispose();
			}
		}
		string Tag()
		{
			return Encoding.ASCII.GetString(r.ReadBytes(4));
		}
	}
}
internal static class HeadModel
{
	private static Mesh mesh;

	private static Texture2D texture;

	internal static Mesh Mesh
	{
		get
		{
			if (!((Object)(object)mesh != (Object)null))
			{
				return mesh = LoadMesh();
			}
			return mesh;
		}
	}

	internal static Texture2D Texture
	{
		get
		{
			if (!((Object)(object)texture != (Object)null))
			{
				return texture = LoadTexture();
			}
			return texture;
		}
	}

	internal static byte[] Read(string name)
	{
		using Stream stream = typeof(HeadModel).Assembly.GetManifestResourceStream(name);
		if (stream == null)
		{
			throw new FileNotFoundException("Missing embedded file " + name);
		}
		byte[] array = new byte[stream.Length];
		int num;
		for (int i = 0; i < array.Length; i += num)
		{
			if ((num = stream.Read(array, i, array.Length - i)) <= 0)
			{
				break;
			}
		}
		return array;
	}

	private static Mesh LoadMesh()
	{
		//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)
		//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_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_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Expected O, but got Unknown
		using BinaryReader binaryReader = new BinaryReader(new MemoryStream(Read("head.bin")));
		if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "TPM1")
		{
			throw new InvalidDataException("head.bin is not a head mesh");
		}
		int num = binaryReader.ReadInt32();
		int num2 = binaryReader.ReadInt32();
		Vector3[] array = (Vector3[])(object)new Vector3[num];
		Vector3[] array2 = (Vector3[])(object)new Vector3[num];
		Vector2[] array3 = (Vector2[])(object)new Vector2[num];
		for (int i = 0; i < num; i++)
		{
			array[i] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
			array2[i] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
			array3[i] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
		}
		int[] array4 = new int[num2];
		for (int j = 0; j < num2; j++)
		{
			array4[j] = binaryReader.ReadUInt16();
		}
		Mesh val = new Mesh
		{
			name = "TrumpParodyHead",
			hideFlags = (HideFlags)61,
			vertices = array,
			normals = array2,
			uv = array3,
			triangles = array4
		};
		val.RecalculateTangents();
		val.RecalculateBounds();
		return val;
	}

	private static Texture2D LoadTexture()
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: 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_002d: Expected O, but got Unknown
		//IL_003b: Expected O, but got Unknown
		Texture2D val = new Texture2D(2, 2, (TextureFormat)3, true)
		{
			name = "TrumpParodyHead",
			hideFlags = (HideFlags)61
		};
		if (!ImageConversion.LoadImage(val, Read("head.jpg"), true))
		{
			throw new InvalidDataException("head.jpg could not be read");
		}
		return val;
	}
}
internal class Look : MonoBehaviour
{
	private static readonly Color Navy = new Color(0.1f, 0.14f, 0.28f);

	private PlayerControllerB player;

	private readonly List<Renderer> parts = new List<Renderer>();

	private readonly List<Object> owned = new List<Object>();

	private bool built;

	private bool hasSuit;

	private bool dressed;

	private AudioSource voice;

	private TextMeshPro bubble;

	private float bubbleUntil;

	private bool firstPersonHidden;

	internal bool Wearing { get; private set; }

	internal ulong Owner { get; private set; }

	internal static Look For(PlayerControllerB p)
	{
		Look look = ((Component)p).GetComponent<Look>();
		if ((Object)(object)look == (Object)null)
		{
			look = ((Component)p).gameObject.AddComponent<Look>();
			look.player = p;
		}
		return look;
	}

	internal void Set(bool wearing, ulong owner)
	{
		Wearing = wearing;
		Owner = owner;
	}

	internal void Say(string text, int line)
	{
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		if (string.IsNullOrEmpty(text))
		{
			return;
		}
		if ((Object)(object)bubble == (Object)null)
		{
			BuildBubble();
		}
		((TMP_Text)bubble).text = text;
		AudioClip val = Clips.For(line);
		bubbleUntil = Time.time + (((Object)(object)val != (Object)null) ? Mathf.Max(4f, val.length) : 4f);
		if ((Object)(object)val == (Object)null || player.isPlayerDead)
		{
			return;
		}
		if ((Object)(object)voice == (Object)null)
		{
			voice = new GameObject("TrumpParodyVoice").AddComponent<AudioSource>();
			((Component)voice).transform.SetParent(player.playerGlobalHead, false);
			voice.spatialBlend = 1f;
			voice.rolloffMode = (AudioRolloffMode)1;
			voice.minDistance = 2f;
			voice.maxDistance = 25f;
			voice.dopplerLevel = 0f;
			if ((Object)(object)player.itemAudio != (Object)null)
			{
				voice.outputAudioMixerGroup = player.itemAudio.outputAudioMixerGroup;
			}
			owned.Add((Object)(object)((Component)voice).gameObject);
		}
		voice.Stop();
		voice.clip = val;
		voice.volume = Mathf.Clamp01(Plugin.Volume.Value);
		voice.Play();
	}

	private void LateUpdate()
	{
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)player == (Object)null)
		{
			return;
		}
		bool flag = (Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)player == (Object)(object)GameNetworkManager.Instance.localPlayerController;
		bool flag2 = Wearing && !player.isPlayerDead && (flag || player.actualClientId == Owner);
		if (flag2 && !built)
		{
			Build();
		}
		if (built)
		{
			SkinnedMeshRenderer thisPlayerModel = player.thisPlayerModel;
			bool flag3 = flag2 && flag && ThirdPerson.Active;
			if (flag)
			{
				HideFirstPerson(flag3);
			}
			foreach (Renderer part in parts)
			{
				if (!((Object)(object)part == (Object)null))
				{
					part.enabled = flag2 && ((Renderer)thisPlayerModel).enabled;
					part.shadowCastingMode = (ShadowCastingMode)(flag3 ? 1 : ((int)((Renderer)thisPlayerModel).shadowCastingMode));
					((Component)part).gameObject.layer = ((!flag3) ? ((Component)thisPlayerModel).gameObject.layer : 0);
				}
			}
			if (flag2 != dressed)
			{
				Dress(flag2);
			}
		}
		if ((Object)(object)bubble != (Object)null)
		{
			UpdateBubble();
		}
	}

	private void HideFirstPerson(bool hide)
	{
		if (hide == firstPersonHidden)
		{
			return;
		}
		firstPersonHidden = hide;
		if ((Object)(object)player.thisPlayerModelArms != (Object)null)
		{
			((Renderer)player.thisPlayerModelArms).forceRenderingOff = hide;
		}
		if ((Object)(object)player.localVisor != (Object)null)
		{
			Renderer[] componentsInChildren = ((Component)player.localVisor).GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].forceRenderingOff = hide;
			}
		}
	}

	private void UpdateBubble()
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		bool flag = Time.time < bubbleUntil && !player.isPlayerDead && (Object)(object)player != (Object)(object)GameNetworkManager.Instance.localPlayerController;
		((Component)bubble).gameObject.SetActive(flag);
		if (flag)
		{
			bubble.transform.position = player.playerGlobalHead.position + Vector3.up * 0.95f;
			Camera val = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.activeCamera : null);
			if ((Object)(object)val != (Object)null)
			{
				bubble.transform.rotation = Quaternion.LookRotation(bubble.transform.position - ((Component)val).transform.position);
			}
		}
	}

	private void BuildBubble()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_009d: 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)
		GameObject val = new GameObject("TrumpParodyBubble");
		val.transform.SetParent(((Component)player).transform, false);
		bubble = val.AddComponent<TextMeshPro>();
		if ((Object)(object)player.usernameBillboardText != (Object)null)
		{
			((TMP_Text)bubble).font = ((TMP_Text)player.usernameBillboardText).font;
		}
		((TMP_Text)bubble).richText = false;
		((TMP_Text)bubble).fontSize = 2.2f;
		((TMP_Text)bubble).alignment = (TextAlignmentOptions)514;
		((Graphic)bubble).color = new Color(1f, 0.85f, 0.3f);
		((TMP_Text)bubble).rectTransform.sizeDelta = new Vector2(3f, 1f);
	}

	private void Build()
	{
		built = true;
		try
		{
			AddHead();
		}
		catch (Exception ex)
		{
			Plugin.Log.LogError((object)("Could not add the head: " + ex));
		}
		try
		{
			AddSuit();
			hasSuit = true;
		}
		catch (Exception ex2)
		{
			Plugin.Log.LogError((object)("Could not add the suit: " + ex2));
		}
	}

	private void AddHead()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0058: 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_0077: 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)
		GameObject val = new GameObject("TrumpParodyHead");
		owned.Add((Object)(object)val);
		val.transform.SetParent(Anchor("spine.004", player.playerGlobalHead), false);
		val.transform.localPosition = new Vector3(0f, Plugin.HeadHeight.Value, Plugin.HeadForward.Value);
		val.transform.localScale = Vector3.one * Plugin.HeadScale.Value;
		val.AddComponent<MeshFilter>().sharedMesh = HeadModel.Mesh;
		MeshRenderer val2 = val.AddComponent<MeshRenderer>();
		((Renderer)val2).sharedMaterial = NewMaterial(Color.white, (Texture)(object)HeadModel.Texture);
		parts.Add((Renderer)(object)val2);
	}

	private void AddSuit()
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		SuitModel instance = SuitModel.Instance;
		SkinnedMeshRenderer val = instance.Create(player.thisPlayerModel, Plugin.SuitGirth.Value);
		owned.Add((Object)(object)val.sharedMesh);
		owned.Add((Object)(object)((Component)val).gameObject);
		Material[] array = (Material[])(object)new Material[instance.Colors.Length];
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = NewMaterial(instance.Colors[i], null);
		}
		((Renderer)val).sharedMaterials = array;
		parts.Add((Renderer)(object)val);
	}

	private Material NewMaterial(Color color, Texture texture)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		Material val = new Material(((Renderer)player.thisPlayerModel).sharedMaterial);
		owned.Add((Object)(object)val);
		val.SetTexture("_BaseColorMap", texture);
		val.SetTexture("_NormalMap", (Texture)null);
		val.SetTexture("_MaskMap", (Texture)null);
		val.DisableKeyword("_NORMALMAP");
		val.DisableKeyword("_MASKMAP");
		val.SetColor("_BaseColor", color);
		val.SetFloat("_Smoothness", 0.2f);
		val.SetFloat("_Metallic", 0f);
		return val;
	}

	private Transform Anchor(string boneName, Transform fallback)
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0204: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: 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_0137: 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_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		SkinnedMeshRenderer thisPlayerModel = player.thisPlayerModel;
		Transform[] bones = thisPlayerModel.bones;
		int num = Find(boneName);
		int num2 = Find("spine");
		int num3 = Find("arm.L_upper");
		int num4 = Find("arm.R_upper");
		Transform val = ((num >= 0) ? bones[num] : fallback);
		Quaternion localRotation = Quaternion.Inverse(val.rotation) * ((Component)player).transform.rotation;
		Matrix4x4[] binds = (((Object)(object)thisPlayerModel.sharedMesh != (Object)null) ? thisPlayerModel.sharedMesh.bindposes : null);
		if (num >= 0 && num2 >= 0 && num3 >= 0 && num4 >= 0 && binds != null && binds.Length == bones.Length)
		{
			Vector3 val2 = (Rest(num3) + Rest(num4)) * 0.5f - Rest(num2);
			Vector3 normalized = ((Vector3)(ref val2)).normalized;
			val2 = Vector3.Cross(Rest(num4) - Rest(num3), normalized);
			Vector3 normalized2 = ((Vector3)(ref val2)).normalized;
			if (((Vector3)(ref normalized2)).sqrMagnitude > 0.1f)
			{
				localRotation = Quaternion.LookRotation(((Matrix4x4)(ref binds[num])).MultiplyVector(normalized2), ((Matrix4x4)(ref binds[num])).MultiplyVector(normalized));
			}
		}
		else
		{
			Plugin.Log.LogWarning((object)("Bone '" + boneName + "' setup not found; the head may sit crooked."));
		}
		Transform transform = new GameObject("TrumpParody_" + boneName).transform;
		owned.Add((Object)(object)((Component)transform).gameObject);
		transform.SetParent(val, false);
		transform.localRotation = localRotation;
		Vector3 lossyScale = val.lossyScale;
		transform.localScale = new Vector3(Inverse(lossyScale.x), Inverse(lossyScale.y), Inverse(lossyScale.z));
		return transform;
		int Find(string n)
		{
			return Array.FindIndex(bones, (Transform b) => (Object)(object)b != (Object)null && ((Object)b).name == n);
		}
		Vector3 Rest(int n)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			Matrix4x4 inverse = ((Matrix4x4)(ref binds[n])).inverse;
			return ((Matrix4x4)(ref inverse)).MultiplyPoint3x4(Vector3.zero);
		}
	}

	private static float Inverse(float v)
	{
		if (!(Mathf.Abs(v) < 0.0001f))
		{
			return 1f / Mathf.Abs(v);
		}
		return 1f;
	}

	private void Dress(bool on)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		dressed = on;
		MaterialPropertyBlock val = null;
		if (on)
		{
			val = new MaterialPropertyBlock();
			val.SetTexture("_BaseColorMap", (Texture)(object)Texture2D.whiteTexture);
			val.SetColor("_BaseColor", Navy);
		}
		if ((Object)(object)player.thisPlayerModelArms != (Object)null)
		{
			((Renderer)player.thisPlayerModelArms).SetPropertyBlock(val);
		}
		Renderer[] array = (Renderer[])(object)new Renderer[3]
		{
			(Renderer)player.thisPlayerModel,
			(Renderer)player.thisPlayerModelLOD1,
			(Renderer)player.thisPlayerModelLOD2
		};
		foreach (Renderer val2 in array)
		{
			if (!((Object)(object)val2 == (Object)null))
			{
				val2.SetPropertyBlock(val);
				val2.forceRenderingOff = on && hasSuit;
			}
		}
		Renderer val3 = (((Object)(object)player.playerBadgeMesh != (Object)null) ? ((Component)player.playerBadgeMesh).GetComponent<Renderer>() : null);
		if ((Object)(object)val3 != (Object)null)
		{
			val3.forceRenderingOff = on && hasSuit;
		}
		if ((Object)(object)player.playerBetaBadgeMesh != (Object)null)
		{
			((Renderer)player.playerBetaBadgeMesh).forceRenderingOff = on && hasSuit;
		}
	}

	private void OnDestroy()
	{
		foreach (Object item in owned)
		{
			if (item != (Object)null)
			{
				Object.Destroy(item);
			}
		}
	}
}
internal static class Net
{
	private const string Channel = "TrumpParodyEmotes.v3";

	private const int MaxText = 160;

	private const byte KindState = 0;

	private const byte KindQuote = 1;

	private const byte KindRequest = 2;

	internal static void OnLocalPlayerConnected()
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		NetworkManager singleton = NetworkManager.Singleton;
		if (!((Object)(object)singleton == (Object)null) && singleton.CustomMessagingManager != null)
		{
			singleton.CustomMessagingManager.UnregisterNamedMessageHandler("TrumpParodyEmotes.v3");
			singleton.CustomMessagingManager.RegisterNamedMessageHandler("TrumpParodyEmotes.v3", new HandleNamedMessageDelegate(Receive));
			SetLocalWearing(Plugin.WearOnJoin.Value);
			if (!singleton.IsServer)
			{
				Send(0uL, 2, 0, 0uL, flag: false, "", 0);
			}
		}
	}

	internal static void SetLocalWearing(bool wearing)
	{
		PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
		if (!((Object)(object)localPlayerController == (Object)null))
		{
			ulong localClientId = NetworkManager.Singleton.LocalClientId;
			Look.For(localPlayerController).Set(wearing, localClientId);
			Broadcast(0, (int)localPlayerController.playerClientId, localClientId, wearing, "", 0);
		}
	}

	internal static void SendQuote(string text, int line)
	{
		PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
		if (!((Object)(object)localPlayerController == (Object)null))
		{
			text = Clean(text);
			ulong localClientId = NetworkManager.Singleton.LocalClientId;
			Look.For(localPlayerController).Say(text, line);
			Broadcast(1, (int)localPlayerController.playerClientId, localClientId, flag: false, text, line);
		}
	}

	private static void Broadcast(byte kind, int slot, ulong owner, bool flag, string text, int line)
	{
		NetworkManager singleton = NetworkManager.Singleton;
		if ((Object)(object)singleton == (Object)null || singleton.CustomMessagingManager == null)
		{
			return;
		}
		if (!singleton.IsServer)
		{
			Send(0uL, kind, slot, owner, flag, text, line);
			return;
		}
		foreach (ulong connectedClientsId in singleton.ConnectedClientsIds)
		{
			if (connectedClientsId != singleton.LocalClientId && connectedClientsId != owner)
			{
				Send(connectedClientsId, kind, slot, owner, flag, text, line);
			}
		}
	}

	private unsafe static void Send(ulong target, byte kind, int slot, ulong owner, bool flag, string text, int line)
	{
		//IL_0015: 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_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0067: 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_0083: Unknown result type (might be due to invalid IL or missing references)
		FastBufferWriter val = default(FastBufferWriter);
		((FastBufferWriter)(ref val))..ctor(32, (Allocator)2, 1024);
		try
		{
			((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref kind, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref slot, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref owner, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
			((FastBufferWriter)(ref val)).WriteValueSafe(text, false);
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref line, default(ForPrimitives));
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("TrumpParodyEmotes.v3", target, val, (NetworkDelivery)3);
		}
		finally
		{
			((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
		}
	}

	private static void Receive(ulong sender, FastBufferReader r)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: 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_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: 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_005c: 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)
		try
		{
			byte b = default(byte);
			((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref b, default(ForPrimitives));
			int num = default(int);
			((FastBufferReader)(ref r)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			ulong owner = default(ulong);
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref owner, default(ForPrimitives));
			bool flag = default(bool);
			((FastBufferReader)(ref r)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
			string text = default(string);
			((FastBufferReader)(ref r)).ReadValueSafe(ref text, false);
			int line = default(int);
			((FastBufferReader)(ref r)).ReadValueSafe<int>(ref line, default(ForPrimitives));
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				return;
			}
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			if (singleton.IsServer && b == 2)
			{
				PlayerControllerB[] array = allPlayerScripts;
				foreach (PlayerControllerB val in array)
				{
					Look look = Look.For(val);
					if (look.Wearing)
					{
						Send(sender, 0, (int)val.playerClientId, look.Owner, flag: true, "", 0);
					}
				}
			}
			else
			{
				if (num < 0 || num >= allPlayerScripts.Length)
				{
					return;
				}
				PlayerControllerB val2 = allPlayerScripts[num];
				if (singleton.IsServer)
				{
					if (val2.actualClientId != sender)
					{
						return;
					}
					owner = sender;
				}
				else if (sender != 0L)
				{
					return;
				}
				text = Clean(text);
				switch (b)
				{
				case 0:
					Look.For(val2).Set(flag, owner);
					break;
				case 1:
					Look.For(val2).Say(text, line);
					break;
				default:
					return;
				}
				if (singleton.IsServer)
				{
					Broadcast(b, num, owner, flag, text, line);
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Ignored a bad message: " + ex.Message));
		}
	}

	private static string Clean(string text)
	{
		text = (text ?? "").Replace('\n', ' ').Replace('\r', ' ');
		if (text.Length <= 160)
		{
			return text;
		}
		return text.Substring(0, 160);
	}
}
[BepInPlugin("trumpparodyemotes", "Trump Parody Emotes", "0.7.0")]
public class Plugin : BaseUnityPlugin
{
	public const string Guid = "trumpparodyemotes";

	public const int QuoteCount = 7;

	internal static ManualLogSource Log;

	internal static string Folder;

	internal static ConfigEntry<float> Volume;

	internal static ConfigEntry<bool> WearOnJoin;

	internal static ConfigEntry<Key> ToggleKey;

	internal static ConfigEntry<Key> ViewKey;

	internal static ConfigEntry<float> HeadHeight;

	internal static ConfigEntry<float> HeadForward;

	internal static ConfigEntry<float> HeadScale;

	internal static ConfigEntry<float> SuitGirth;

	internal static readonly ConfigEntry<Key>[] QuoteKeys = new ConfigEntry<Key>[7];

	internal static readonly ConfigEntry<string>[] Quotes = new ConfigEntry<string>[7];

	private static readonly string[] DefaultQuotes = new string[7] { "We're gonna make Lethal Company great again!|1", "Many are saying I have the largest piece of scrap on the ship. That's true. No one has ever seen scrap this big.|2", "We're winning so much quota, you'll say, 'Please, sir, no more scrap.'|1", "We have the best crew, folks. Most of them are dead, but the best.|2", "I've been to every moon. Many people say I invented the moons.|1", "The Company's treating us very unfairly. Thirty percent? Terrible deal.|2", "I could say the stupidest things and you'd clap.|2" };

	private void Awake()
	{
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e2: Expected O, but got Unknown
		//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		Folder = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
		Volume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "Volume", 1f, "Loudness of line audio, 0 to 1.");
		WearOnJoin = ((BaseUnityPlugin)this).Config.Bind<bool>("Look", "WearOnJoin", true, "Wear the parody look when you join a lobby.");
		ToggleKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Hotkeys", "ToggleLook", (Key)103, "Turns the parody look on or off.");
		ViewKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Hotkeys", "ThirdPerson", (Key)104, "Switches between first person, behind and front view.");
		HeadHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "HeadUp", 0.17f, "Height of the head above the head bone, in metres.");
		HeadForward = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "HeadOffsetForward", 0.02f, "How far forward the head sits, in metres.");
		HeadScale = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "HeadSize", 0.55f, "Size of the head model. 1 is about a metre tall, collar included.");
		SuitGirth = ((BaseUnityPlugin)this).Config.Bind<float>("Look", "SuitGirth", 1.15f, "How thick the suit is.");
		for (int i = 0; i < 7; i++)
		{
			QuoteKeys[i] = ((BaseUnityPlugin)this).Config.Bind<Key>("Hotkeys", "Line" + (i + 1), (Key)(94 + i), "Key for line " + (i + 1) + ".");
			Quotes[i] = ((BaseUnityPlugin)this).Config.Bind<string>("ParodyLines", "Line" + (i + 1), DefaultQuotes[i], "Text|emote. Emote: 0 none, 1 dance, 2 point.");
		}
		GameObject val = new GameObject("TrumpParodyEmotes")
		{
			hideFlags = (HideFlags)61
		};
		Object.DontDestroyOnLoad((Object)val);
		val.AddComponent<Controls>();
		val.AddComponent<ThirdPerson>();
		new Harmony("trumpparodyemotes").PatchAll(typeof(ConnectPatch));
		Log.LogInfo((object)"Trump Parody Emotes loaded (parody; not affiliated with or endorsed by anyone).");
	}
}
[HarmonyPatch(typeof(PlayerControllerB), "ConnectClientToPlayerObject")]
internal static class ConnectPatch
{
	private static void Postfix()
	{
		Net.OnLocalPlayerConnected();
	}
}
internal class Controls : MonoBehaviour
{
	private static readonly MethodInfo CanEmote = AccessTools.Method(typeof(PlayerControllerB), "CheckConditionsForEmote", (Type[])null, (Type[])null);

	private float nextQuote;

	private string ownLine;

	private float ownLineUntil;

	private GUIStyle style;

	private void Update()
	{
		//IL_0068: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
		Keyboard current = Keyboard.current;
		PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null);
		if (current == null || (Object)(object)val == (Object)null || val.isPlayerDead || val.isTypingChat || val.inTerminalMenu || ((Object)(object)val.quickMenuManager != (Object)null && val.quickMenuManager.isMenuOpen))
		{
			return;
		}
		if (Pressed(current, Plugin.ToggleKey.Value))
		{
			Net.SetLocalWearing(!Look.For(val).Wearing);
		}
		if (Pressed(current, Plugin.ViewKey.Value))
		{
			ThirdPerson.Next();
		}
		if (Time.time < nextQuote)
		{
			return;
		}
		for (int i = 0; i < 7; i++)
		{
			if (Pressed(current, Plugin.QuoteKeys[i].Value))
			{
				nextQuote = Time.time + 2f;
				Say(val, Plugin.Quotes[i].Value, i + 1);
				break;
			}
		}
	}

	private static bool Pressed(Keyboard keyboard, Key key)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		if ((int)key != 0)
		{
			return ((ButtonControl)keyboard[key]).wasPressedThisFrame;
		}
		return false;
	}

	private void Say(PlayerControllerB player, string entry, int line)
	{
		int result = 0;
		string text = entry;
		int num = entry.LastIndexOf('|');
		if (num >= 0)
		{
			text = entry.Substring(0, num);
			int.TryParse(entry.Substring(num + 1).Trim(), out result);
		}
		text = text.Trim();
		if (text.Length != 0)
		{
			if ((result == 1 || result == 2) && player.timeSinceStartingEmote >= 0.5f && CanEmote != null && (bool)CanEmote.Invoke(player, null))
			{
				player.timeSinceStartingEmote = 0f;
				player.performingEmote = true;
				player.playerBodyAnimator.SetInteger("emoteNumber", result);
				player.StartPerformingEmoteServerRpc();
			}
			ownLine = text;
			AudioClip val = Clips.For(line);
			ownLineUntil = Time.time + (((Object)(object)val != (Object)null) ? Mathf.Max(4f, val.length) : 4f);
			Net.SendQuote(text, line);
		}
	}

	private void OnGUI()
	{
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: 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_00f3: 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_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_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Expected O, but got Unknown
		if (ownLine != null && !(Time.time > ownLineUntil))
		{
			if (style == null)
			{
				style = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)4,
					fontSize = 26,
					richText = false,
					wordWrap = true
				};
			}
			Rect val = default(Rect);
			((Rect)(ref val))..ctor((float)Screen.width * 0.2f, (float)Screen.height * 0.72f, (float)Screen.width * 0.6f, 80f);
			GUI.color = Color.black;
			GUI.Label(new Rect(((Rect)(ref val)).x + 2f, ((Rect)(ref val)).y + 2f, ((Rect)(ref val)).width, ((Rect)(ref val)).height), ownLine, style);
			GUI.color = new Color(1f, 0.85f, 0.3f);
			GUI.Label(val, ownLine, style);
			GUI.color = Color.white;
		}
	}
}
internal class SuitModel
{
	private class Torso
	{
		private static readonly string[] Spine = new string[5] { "spine", "spine.001", "spine.002", "spine.003", "spine.004" };

		private readonly Vector3[] from = (Vector3[])(object)new Vector3[Spine.Length];

		private readonly Vector3[] to = (Vector3[])(object)new Vector3[Spine.Length];

		private readonly float size;

		private readonly float girth;

		private readonly float hipY;

		private readonly float shoulderY;

		private readonly float neckY;

		private readonly float hipWide;

		private readonly float shoulderWide;

		private readonly float neckWide;

		public Torso(Dictionary<string, Vector3> suit, Dictionary<string, Vector3> game, float size, float girth)
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, Vector3> game2 = game;
			Dictionary<string, Vector3> suit2 = suit;
			float size2 = size;
			base..ctor();
			this.size = size2;
			this.girth = girth;
			for (int i = 0; i < Spine.Length; i++)
			{
				from[i] = suit2[Spine[i]];
				to[i] = game2[Spine[i]];
				if (i > 0 && to[i].y < to[i - 1].y)
				{
					to[i].y = to[i - 1].y;
				}
			}
			hipWide = Ratio("thigh.L", "thigh.R", 0.9f, 1.6f);
			shoulderWide = Ratio("arm.L_upper", "arm.R_upper", 0.8f, 2f);
			neckWide = size2 * 1.05f;
			hipY = suit2["thigh.L"].y;
			shoulderY = suit2["arm.L_upper"].y;
			neckY = suit2["spine.004"].y;
			float Ratio(string l, string r, float min, float max)
			{
				//IL_0008: 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_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				return Mathf.Clamp((game2[r].x - game2[l].x) / (suit2[r].x - suit2[l].x), size2 * min, size2 * max);
			}
		}

		public Vector3 Point(Vector3 p)
		{
			//IL_000b: 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_0035: 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_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			int num = from.Length - 1;
			float num2;
			float num3;
			float num4;
			if (p.y <= from[0].y)
			{
				num2 = to[0].y + (p.y - from[0].y) * size;
				num3 = from[0].z;
				num4 = to[0].z;
			}
			else if (p.y >= from[num].y)
			{
				num2 = to[num].y + (p.y - from[num].y) * size;
				num3 = from[num].z;
				num4 = to[num].z;
			}
			else
			{
				int i;
				for (i = 1; p.y > from[i].y; i++)
				{
				}
				float num5 = Mathf.InverseLerp(from[i - 1].y, from[i].y, p.y);
				num2 = Mathf.Lerp(to[i - 1].y, to[i].y, num5);
				num3 = Mathf.Lerp(from[i - 1].z, from[i].z, num5);
				num4 = Mathf.Lerp(to[i - 1].z, to[i].z, num5);
			}
			float num6 = ((p.y <= shoulderY) ? Mathf.Lerp(hipWide, shoulderWide, Mathf.InverseLerp(hipY, shoulderY, p.y)) : Mathf.Lerp(shoulderWide, neckWide, Mathf.InverseLerp(shoulderY, neckY, p.y)));
			return new Vector3(p.x * num6, num2, num4 + (p.z - num3) * size * girth);
		}
	}

	private struct Segment
	{
		public Vector3 From;

		public Vector3 To;

		public Vector3 Along;

		public Quaternion Turn;

		public float Stretch;

		public float Girth;

		public Torso Torso;

		public Vector3 Point(Vector3 p)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_0024: 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_003c: 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_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_0054: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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)
			if (Torso != null)
			{
				return Torso.Point(p);
			}
			Vector3 val = p - From;
			float num = Vector3.Dot(val, Along);
			return To + Turn * (Along * num * Stretch + (val - Along * num) * Girth);
		}
	}

	private string[] bones;

	private readonly Dictionary<string, Vector3> joints = new Dictionary<string, Vector3>();

	private Vector3[] positions;

	private Vector3[] normals;

	private BoneWeight[] weights;

	private Color[] colors;

	private int[][] triangles;

	private static bool logged;

	private static SuitModel instance;

	internal static SuitModel Instance => instance ?? (instance = Load());

	internal Color[] Colors => colors;

	private static SuitModel Load()
	{
		//IL_0096: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: 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_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		SuitModel suitModel = new SuitModel();
		using BinaryReader binaryReader = new BinaryReader(new MemoryStream(HeadModel.Read("suit.bin")), Encoding.ASCII);
		if (Encoding.ASCII.GetString(binaryReader.ReadBytes(4)) != "TPS1")
		{
			throw new InvalidDataException("suit.bin is not a suit");
		}
		suitModel.bones = new string[binaryReader.ReadInt32()];
		for (int i = 0; i < suitModel.bones.Length; i++)
		{
			suitModel.bones[i] = Name(binaryReader);
		}
		for (int num = binaryReader.ReadInt32(); num > 0; num--)
		{
			suitModel.joints[Name(binaryReader)] = Vector(binaryReader);
		}
		int num2 = binaryReader.ReadInt32();
		suitModel.positions = (Vector3[])(object)new Vector3[num2];
		suitModel.normals = (Vector3[])(object)new Vector3[num2];
		suitModel.weights = (BoneWeight[])(object)new BoneWeight[num2];
		for (int j = 0; j < num2; j++)
		{
			suitModel.positions[j] = Vector(binaryReader);
			suitModel.normals[j] = Vector(binaryReader);
			byte[] array = binaryReader.ReadBytes(4);
			BoneWeight[] array2 = suitModel.weights;
			int num3 = j;
			BoneWeight val = default(BoneWeight);
			((BoneWeight)(ref val)).boneIndex0 = array[0];
			((BoneWeight)(ref val)).boneIndex1 = array[1];
			((BoneWeight)(ref val)).boneIndex2 = array[2];
			((BoneWeight)(ref val)).boneIndex3 = array[3];
			((BoneWeight)(ref val)).weight0 = binaryReader.ReadSingle();
			((BoneWeight)(ref val)).weight1 = binaryReader.ReadSingle();
			((BoneWeight)(ref val)).weight2 = binaryReader.ReadSingle();
			((BoneWeight)(ref val)).weight3 = binaryReader.ReadSingle();
			array2[num3] = val;
		}
		int num4 = binaryReader.ReadInt32();
		suitModel.colors = (Color[])(object)new Color[num4];
		suitModel.triangles = new int[num4][];
		for (int k = 0; k < num4; k++)
		{
			Vector3 val2 = Vector(binaryReader);
			Color[] array3 = suitModel.colors;
			int num5 = k;
			Color val3 = new Color(val2.x, val2.y, val2.z);
			array3[num5] = ((Color)(ref val3)).gamma;
			suitModel.triangles[k] = new int[binaryReader.ReadInt32()];
			for (int l = 0; l < suitModel.triangles[k].Length; l++)
			{
				suitModel.triangles[k][l] = binaryReader.ReadUInt16();
			}
		}
		return suitModel;
	}

	private static string Name(BinaryReader r)
	{
		return Encoding.ASCII.GetString(r.ReadBytes(r.ReadByte()));
	}

	private static Vector3 Vector(BinaryReader r)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		return new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
	}

	private static string Child(string bone)
	{
		switch (bone)
		{
		case "spine":
			return "spine.001";
		case "spine.001":
			return "spine.002";
		case "spine.002":
			return "spine.003";
		case "spine.003":
			return "spine.004";
		default:
		{
			string text = (bone.Contains(".L") ? "L" : "R");
			if (bone.StartsWith("shoulder"))
			{
				return "arm." + text + "_upper";
			}
			if (bone.EndsWith("_upper"))
			{
				return "arm." + text + "_lower";
			}
			if (bone.EndsWith("_lower"))
			{
				return "hand." + text;
			}
			if (bone.StartsWith("thigh"))
			{
				return "shin." + text;
			}
			if (bone.StartsWith("shin"))
			{
				return "foot." + text;
			}
			if (bone.StartsWith("foot"))
			{
				return "toe." + text;
			}
			return null;
		}
		}
	}

	internal SkinnedMeshRenderer Create(SkinnedMeshRenderer body, float girth)
	{
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: 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)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_017b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_0314: Unknown result type (might be due to invalid IL or missing references)
		//IL_0319: Unknown result type (might be due to invalid IL or missing references)
		//IL_0323: Unknown result type (might be due to invalid IL or missing references)
		//IL_0328: Unknown result type (might be due to invalid IL or missing references)
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0334: Unknown result type (might be due to invalid IL or missing references)
		//IL_033b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0340: Unknown result type (might be due to invalid IL or missing references)
		//IL_028e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0294: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: Unknown result type (might be due to invalid IL or missing references)
		//IL_0558: Unknown result type (might be due to invalid IL or missing references)
		//IL_055d: Unknown result type (might be due to invalid IL or missing references)
		//IL_055f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0564: Unknown result type (might be due to invalid IL or missing references)
		//IL_056e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0573: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0604: Unknown result type (might be due to invalid IL or missing references)
		//IL_0608: Unknown result type (might be due to invalid IL or missing references)
		//IL_060d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0627: Unknown result type (might be due to invalid IL or missing references)
		//IL_062c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0637: Unknown result type (might be due to invalid IL or missing references)
		//IL_0641: Expected O, but got Unknown
		//IL_038e: Unknown result type (might be due to invalid IL or missing references)
		//IL_039b: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_037f: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_06bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_06c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0725: Unknown result type (might be due to invalid IL or missing references)
		//IL_072a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0741: Unknown result type (might be due to invalid IL or missing references)
		//IL_074d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0757: Unknown result type (might be due to invalid IL or missing references)
		//IL_0763: Unknown result type (might be due to invalid IL or missing references)
		//IL_076d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0779: Unknown result type (might be due to invalid IL or missing references)
		//IL_07a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_04fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0503: Unknown result type (might be due to invalid IL or missing references)
		//IL_0508: Unknown result type (might be due to invalid IL or missing references)
		//IL_050d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0417: Unknown result type (might be due to invalid IL or missing references)
		//IL_041c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0423: Unknown result type (might be due to invalid IL or missing references)
		//IL_0425: Unknown result type (might be due to invalid IL or missing references)
		//IL_0427: Unknown result type (might be due to invalid IL or missing references)
		//IL_042c: Unknown result type (might be due to invalid IL or missing references)
		Transform[] array = body.bones;
		Matrix4x4[] bodyBinds = body.sharedMesh.bindposes;
		if (array.Length != bodyBinds.Length)
		{
			throw new InvalidOperationException("bone and bind pose counts differ");
		}
		Dictionary<string, int> index = new Dictionary<string, int>();
		for (int i = 0; i < array.Length; i++)
		{
			if ((Object)(object)array[i] != (Object)null && !index.ContainsKey(((Object)array[i]).name))
			{
				index[((Object)array[i]).name] = i;
			}
		}
		string[] array2 = bones;
		foreach (string text in array2)
		{
			if (!index.ContainsKey(text))
			{
				throw new InvalidOperationException("player has no skinned bone '" + text + "'");
			}
		}
		Vector3 val = (Rest("arm.L_upper") + Rest("arm.R_upper")) * 0.5f - Rest("spine");
		Vector3 up = ((Vector3)(ref val)).normalized;
		Vector3 right = Rest("arm.R_upper") - Rest("arm.L_upper");
		val = right - up * Vector3.Dot(right, up);
		right = ((Vector3)(ref val)).normalized;
		Vector3 forward = Vector3.Cross(right, up);
		Dictionary<string, Vector3> dictionary = new Dictionary<string, Vector3>();
		foreach (string key2 in joints.Keys)
		{
			if (index.ContainsKey(key2))
			{
				dictionary[key2] = ToBody(Rest(key2));
			}
		}
		float num = Tall(dictionary) / Tall(joints);
		if (!(num > 0f) || float.IsInfinity(num))
		{
			throw new InvalidOperationException("odd player proportions");
		}
		Torso torso = new Torso(joints, dictionary, num, girth);
		if (!logged)
		{
			logged = true;
			StringBuilder stringBuilder = new StringBuilder("Suit fit, size " + num.ToString("F4") + ":");
			foreach (KeyValuePair<string, Vector3> item in dictionary)
			{
				StringBuilder stringBuilder2 = stringBuilder.Append(' ').Append(item.Key).Append('=');
				val = item.Value / num;
				stringBuilder2.Append(((Vector3)(ref val)).ToString("F3"));
			}
			Plugin.Log.LogInfo((object)stringBuilder.ToString());
		}
		Segment[] array3 = new Segment[bones.Length];
		for (int k = 0; k < bones.Length; k++)
		{
			string text2 = bones[k];
			string text3 = Child(text2);
			Segment segment = new Segment
			{
				From = joints[text2],
				To = dictionary[text2],
				Turn = Quaternion.identity,
				Along = Vector3.up,
				Stretch = num,
				Girth = num * girth
			};
			bool flag = text3 != null && joints.ContainsKey(text3) && dictionary.ContainsKey(text3);
			Vector3 val2 = (flag ? (joints[text3] - joints[text2]) : Vector3.zero);
			Vector3 val3 = (flag ? (dictionary[text3] - dictionary[text2]) : Vector3.zero);
			if (text2.StartsWith("spine") || text2.StartsWith("shoulder"))
			{
				segment.Torso = torso;
			}
			else if (flag && ((Vector3)(ref val2)).sqrMagnitude > 1E-06f && ((Vector3)(ref val3)).sqrMagnitude > 1E-12f)
			{
				segment.Along = ((Vector3)(ref val2)).normalized;
				segment.Turn = Quaternion.FromToRotation(val2, val3);
				segment.Stretch = Mathf.Clamp(((Vector3)(ref val3)).magnitude / ((Vector3)(ref val2)).magnitude, num * 0.4f, num * 2.5f);
			}
			else if (text2.StartsWith("hand"))
			{
				string key = "arm." + text2.Substring(5) + "_lower";
				segment.Stretch = (segment.Girth = num * 0.9f);
				val = joints[text2] - joints[key];
				segment.Along = ((Vector3)(ref val)).normalized;
				segment.Turn = Quaternion.FromToRotation(joints[text2] - joints[key], dictionary[text2] - dictionary[key]);
			}
			array3[k] = segment;
		}
		Vector3[] array4 = (Vector3[])(object)new Vector3[positions.Length];
		Vector3[] array5 = (Vector3[])(object)new Vector3[positions.Length];
		for (int l = 0; l < positions.Length; l++)
		{
			Vector3 p = Vector3.zero;
			Vector3 n = Vector3.zero;
			BoneWeight val4 = weights[l];
			Blend(ref p, ref n, array3, l, ((BoneWeight)(ref val4)).boneIndex0, ((BoneWeight)(ref val4)).weight0);
			Blend(ref p, ref n, array3, l, ((BoneWeight)(ref val4)).boneIndex1, ((BoneWeight)(ref val4)).weight1);
			Blend(ref p, ref n, array3, l, ((BoneWeight)(ref val4)).boneIndex2, ((BoneWeight)(ref val4)).weight2);
			Blend(ref p, ref n, array3, l, ((BoneWeight)(ref val4)).boneIndex3, ((BoneWeight)(ref val4)).weight3);
			array4[l] = FromBody(p);
			int num2 = l;
			val = FromBody(n);
			array5[num2] = ((Vector3)(ref val)).normalized;
		}
		Mesh val5 = new Mesh
		{
			name = "TrumpParodySuit",
			hideFlags = (HideFlags)61
		};
		val5.vertices = array4;
		val5.normals = array5;
		val5.boneWeights = weights;
		Transform[] array6 = (Transform[])(object)new Transform[bones.Length];
		Matrix4x4[] array7 = (Matrix4x4[])(object)new Matrix4x4[bones.Length];
		for (int m = 0; m < bones.Length; m++)
		{
			array6[m] = array[index[bones[m]]];
			array7[m] = bodyBinds[index[bones[m]]];
		}
		val5.bindposes = array7;
		val5.subMeshCount = triangles.Length;
		for (int num3 = 0; num3 < triangles.Length; num3++)
		{
			val5.SetTriangles(triangles[num3], num3);
		}
		val5.RecalculateBounds();
		GameObject val6 = new GameObject("TrumpParodySuit");
		val6.transform.SetParent(((Component)body).transform.parent, false);
		val6.transform.localPosition = ((Component)body).transform.localPosition;
		val6.transform.localRotation = ((Component)body).transform.localRotation;
		val6.transform.localScale = ((Component)body).transform.localScale;
		SkinnedMeshRenderer obj = val6.AddComponent<SkinnedMeshRenderer>();
		obj.sharedMesh = val5;
		obj.bones = array6;
		obj.rootBone = body.rootBone;
		((Renderer)obj).localBounds = ((Renderer)body).localBounds;
		return obj;
		Vector3 FromBody(Vector3 v)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_001d: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			return right * v.x + up * v.y + forward * v.z;
		}
		Vector3 Rest(string b)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Matrix4x4 inverse = ((Matrix4x4)(ref bodyBinds[index[b]])).inverse;
			return ((Matrix4x4)(ref inverse)).MultiplyPoint3x4(Vector3.zero);
		}
		static float Tall(Dictionary<string, Vector3> d)
		{
			//IL_0006: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			return d["spine.004"].y - (d["foot.L"].y + d["foot.R"].y) * 0.5f;
		}
		Vector3 ToBody(Vector3 v)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: 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_000e: 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_001a: 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)
			return new Vector3(Vector3.Dot(v, right), Vector3.Dot(v, up), Vector3.Dot(v, forward));
		}
	}

	private void Blend(ref Vector3 p, ref Vector3 n, Segment[] segments, int vertex, int bone, float weight)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//IL_0037: 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_004b: 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_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)
		if (!(weight <= 0f))
		{
			p += segments[bone].Point(positions[vertex]) * weight;
			n += segments[bone].Turn * normals[vertex] * weight;
		}
	}
}
internal class ThirdPerson : MonoBehaviour
{
	private enum View
	{
		Off,
		Behind,
		Front
	}

	private static View view;

	private Camera moved;

	private Vector3 savedPosition;

	private Quaternion savedRotation;

	internal static bool Active { get; private set; }

	private static PlayerControllerB Local
	{
		get
		{
			if (!((Object)(object)GameNetworkManager.Instance != (Object)null))
			{
				return null;
			}
			return GameNetworkManager.Instance.localPlayerController;
		}
	}

	internal static void Next()
	{
		view = (View)((int)(view + 1) % 3);
	}

	private void OnEnable()
	{
		RenderPipelineManager.beginContextRendering += Begin;
		RenderPipelineManager.endContextRendering += End;
	}

	private void OnDisable()
	{
		RenderPipelineManager.beginContextRendering -= Begin;
		RenderPipelineManager.endContextRendering -= End;
		Restore();
	}

	private void Update()
	{
		PlayerControllerB local = Local;
		if ((Object)(object)local == (Object)null)
		{
			view = View.Off;
		}
		Active = view != View.Off && (Object)(object)local != (Object)null && !local.isPlayerDead && !local.inTerminalMenu && (Object)(object)local.gameplayCamera != (Object)null && Look.For(local).Wearing;
	}

	private void Begin(ScriptableRenderContext context, List<Camera> cameras)
	{
		//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_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_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//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_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: 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_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: 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_0106: 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_00ca: 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_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		if (!Active || (Object)(object)moved != (Object)null)
		{
			return;
		}
		PlayerControllerB local = Local;
		if (!((Object)(object)local == (Object)null) && !((Object)(object)local.gameplayCamera == (Object)null) && cameras.Contains(local.gameplayCamera))
		{
			moved = local.gameplayCamera;
			Transform transform = ((Component)moved).transform;
			savedPosition = transform.position;
			savedRotation = transform.rotation;
			Vector3 val = Vector3.ProjectOnPlane(((Component)local).transform.forward, Vector3.up);
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			Vector3 val2 = savedPosition;
			Vector3 val3 = ((view == View.Front) ? normalized : (-transform.forward));
			float num = 2.4f;
			RaycastHit val4 = default(RaycastHit);
			if ((Object)(object)StartOfRound.Instance != (Object)null && Physics.SphereCast(val2, 0.15f, val3, ref val4, num, StartOfRound.Instance.collidersAndRoomMask, (QueryTriggerInteraction)1))
			{
				num = Mathf.Max(0.5f, ((RaycastHit)(ref val4)).distance - 0.1f);
			}
			transform.position = val2 + val3 * num;
			if (view == View.Front)
			{
				transform.rotation = Quaternion.LookRotation(val2 + Vector3.down * 0.5f - transform.position);
			}
		}
	}

	private void End(ScriptableRenderContext context, List<Camera> cameras)
	{
		Restore();
	}

	private void Restore()
	{
		//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)
		if ((Object)(object)moved != (Object)null)
		{
			((Component)moved).transform.position = savedPosition;
			((Component)moved).transform.rotation = savedRotation;
		}
		moved = null;
	}
}