Decompiled source of MurphysWings v1.4.6

plugins/MurphysWings/MurphysWings.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[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("MurphysWings")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MurphysWings")]
[assembly: AssemblyTitle("MurphysWings")]
[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 MurphysWings
{
	internal sealed class GameToolsBridge
	{
		internal const string PluginId = "zichen.gametools";

		private readonly Func<bool> wingsEnabled;

		private readonly Func<int> colorIndex;

		private readonly Func<bool> windowOpen;

		private readonly ConfigEntry<bool> thirdPerson;

		private readonly Func<bool> cosmeticsEnabled;

		private readonly Action saveGameToolsConfig;

		private readonly ManualLogSource log;

		private bool localApiFailed;

		private bool cameraApiFailed;

		internal bool IsMenuOpen
		{
			get
			{
				if (!localApiFailed && windowOpen != null)
				{
					return windowOpen();
				}
				return false;
			}
		}

		internal bool HasWingSync
		{
			get
			{
				if (wingsEnabled != null && colorIndex != null)
				{
					return !localApiFailed;
				}
				return false;
			}
		}

		internal bool HasCameraControl
		{
			get
			{
				if (thirdPerson != null)
				{
					return !cameraApiFailed;
				}
				return false;
			}
		}

		internal bool ThirdPersonEnabled
		{
			get
			{
				if (HasCameraControl)
				{
					return thirdPerson.Value;
				}
				return false;
			}
		}

		internal bool VisualsEnabled => CanToggleCamera();

		internal GameToolsBridge(ManualLogSource log)
		{
			this.log = log;
			if (!Chainloader.PluginInfos.TryGetValue("zichen.gametools", out var value) || !Object.op_Implicit((Object)(object)value.Instance))
			{
				return;
			}
			Type type = ((object)value.Instance).GetType();
			try
			{
				wingsEnabled = Bind<bool>(type, "IsWingsAlwaysShowEnabled");
				colorIndex = Bind<int>(type, "GetWingsColorIndex");
				if (type.GetMethod("IsWindowOpen", BindingFlags.Static | BindingFlags.Public, null, Type.EmptyTypes, null) != null)
				{
					windowOpen = Bind<bool>(type, "IsWindowOpen");
				}
				log.LogInfo((object)$"GameTools {value.Metadata.Version} wing settings connected.");
			}
			catch (Exception ex)
			{
				localApiFailed = true;
				log.LogWarning((object)("GameTools wing API unavailable. Using room properties online. " + ex.Message));
			}
			try
			{
				thirdPerson = (type.GetField("_cfgThirdPersonEnabled", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null) as ConfigEntry<bool>) ?? throw new MissingFieldException(type.FullName, "_cfgThirdPersonEnabled");
				cosmeticsEnabled = Bind<bool>(type, "IsCosmeticsEnabled");
				MethodInfo method = type.GetMethod("SaveRuntimeConfig", BindingFlags.Static | BindingFlags.Public, null, Type.EmptyTypes, null);
				if (method == null || method.ReturnType != typeof(void))
				{
					throw new MissingMethodException(type.FullName, "SaveRuntimeConfig");
				}
				saveGameToolsConfig = (Action)Delegate.CreateDelegate(typeof(Action), method);
			}
			catch (Exception ex2)
			{
				DisableCameraControl(ex2);
			}
		}

		internal bool CanToggleCamera()
		{
			if (!HasCameraControl)
			{
				return false;
			}
			try
			{
				return cosmeticsEnabled();
			}
			catch (Exception ex)
			{
				DisableCameraControl(ex);
				return false;
			}
		}

		internal void ToggleThirdPerson()
		{
			if (!CanToggleCamera())
			{
				return;
			}
			try
			{
				thirdPerson.Value = !thirdPerson.Value;
				saveGameToolsConfig();
			}
			catch (Exception ex)
			{
				DisableCameraControl(ex);
			}
		}

		private void DisableCameraControl(Exception ex)
		{
			cameraApiFailed = true;
			log.LogWarning((object)("GameTools camera control unavailable. " + ex.Message));
		}

		internal WingPalette LocalColor()
		{
			if (wingsEnabled != null && !localApiFailed)
			{
				try
				{
					return wingsEnabled() ? NormalizeColor(colorIndex()) : WingPalette.ModeDefault;
				}
				catch (Exception ex)
				{
					localApiFailed = true;
					log.LogWarning((object)("GameTools wing API stopped responding. Using room properties online. " + ex.Message));
				}
			}
			if (!PhotonNetwork.InRoom)
			{
				return WingPalette.ModeDefault;
			}
			return RemoteColor(PhotonNetwork.LocalPlayer);
		}

		internal static WingPalette RemoteColor(Player owner)
		{
			if (!PlayerFlag(owner, "GT_WingsAlwaysShow"))
			{
				return WingPalette.ModeDefault;
			}
			if (!owner.IsMasterClient && HostBlocksGuestWings())
			{
				return WingPalette.ModeDefault;
			}
			if (!((Dictionary<object, object>)(object)owner.CustomProperties).TryGetValue((object)"GT_WingsColorIndex", out object value) || !(value is int index))
			{
				return WingPalette.Blue;
			}
			return NormalizeColor(index);
		}

		internal static bool HostBlocksGuestWings()
		{
			if (PlayerFlag(PhotonNetwork.MasterClient, "GT_Active"))
			{
				Room currentRoom = PhotonNetwork.CurrentRoom;
				return Flag((currentRoom != null) ? ((RoomInfo)currentRoom).CustomProperties : null, "GT_ProhibitOthers");
			}
			return false;
		}

		internal static bool PlayerFlag(Player player, string key)
		{
			return Flag((player != null) ? player.CustomProperties : null, key);
		}

		private static WingPalette NormalizeColor(int index)
		{
			return index switch
			{
				1 => WingPalette.Pink, 
				3 => WingPalette.RedBlue, 
				_ => WingPalette.Blue, 
			};
		}

		private static bool Flag(Hashtable properties, string key)
		{
			bool flag = default(bool);
			int num;
			if (properties != null && ((Dictionary<object, object>)(object)properties).TryGetValue((object)key, out object value))
			{
				if (value is bool)
				{
					flag = (bool)value;
					num = 1;
				}
				else
				{
					num = 0;
				}
			}
			else
			{
				num = 0;
			}
			return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
		}

		private static Func<T> Bind<T>(Type type, string name)
		{
			MethodInfo method = type.GetMethod(name, BindingFlags.Static | BindingFlags.Public, null, Type.EmptyTypes, null);
			if (method == null || method.ReturnType != typeof(T))
			{
				throw new MissingMethodException(type.FullName, name);
			}
			return (Func<T>)Delegate.CreateDelegate(typeof(Func<T>), method);
		}
	}
	internal sealed class NativeWingCycle
	{
		private const string HostKey = "MurphysWings.NativeHost.v1";

		private const string RequestKey = "MurphysWings.NativeCycle.v1";

		private const uint MaxAge = 3000u;

		private Room room;

		private bool hostReady;

		private bool requested;

		private bool sentHost;

		private bool sentRequest;

		private float nextRefresh;

		internal string Status { get; private set; } = "Host needs GameTools and Murphys Wings 1.3.0.";

		internal bool LocalUsesNative => requested;

		internal void Tick(GameToolsBridge tools, bool selected, PlayerAvatar local, List<PlayerAvatar> players)
		{
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Expected O, but got Unknown
			Room val = (PhotonNetwork.InRoom ? PhotonNetwork.CurrentRoom : null);
			if (val != room)
			{
				room = val;
				sentHost = (sentRequest = false);
				nextRefresh = 0f;
			}
			Player localPlayer = PhotonNetwork.LocalPlayer;
			Player masterClient = PhotonNetwork.MasterClient;
			hostReady = room != null && localPlayer != null && masterClient != null && ((!PhotonNetwork.IsMasterClient) ? HasFreshLease(masterClient, "MurphysWings.NativeHost.v1") : (tools?.VisualsEnabled ?? false));
			int num;
			if (selected)
			{
				WingPalette? wingPalette = tools?.LocalColor();
				if (wingPalette.HasValue)
				{
					WingPalette valueOrDefault = wingPalette.GetValueOrDefault();
					num = ((valueOrDefault != WingPalette.ModeDefault) ? 1 : 0);
					goto IL_00ba;
				}
			}
			num = 0;
			goto IL_00ba;
			IL_00ba:
			bool flag = (byte)num != 0;
			bool flag2 = room != null && !PhotonNetwork.IsMasterClient && GameToolsBridge.HostBlocksGuestWings();
			Status = ((room == null) ? "Join a lobby to share the native cycle." : (flag2 ? "The host has restricted guest wings." : ((!hostReady) ? "Host needs GameTools and Murphys Wings 1.3.0." : (flag ? "Turn off GameTools Wings Always Active to share." : "Native lobby sharing ready."))));
			requested = selected && Object.op_Implicit((Object)(object)local) && hostReady && !flag2 && !flag;
			if (room == null || localPlayer == null || masterClient == null)
			{
				return;
			}
			bool flag3 = hostReady && PhotonNetwork.IsMasterClient;
			float unscaledTime = Time.unscaledTime;
			if (unscaledTime >= nextRefresh || sentHost != flag3 || sentRequest != requested)
			{
				Hashtable val2 = new Hashtable();
				object[] array = new object[3]
				{
					room.Name,
					masterClient.ActorNumber,
					PhotonNetwork.ServerTimestamp
				};
				if (flag3 || sentHost || ((Dictionary<object, object>)(object)localPlayer.CustomProperties).ContainsKey((object)"MurphysWings.NativeHost.v1"))
				{
					val2[(object)"MurphysWings.NativeHost.v1"] = (flag3 ? array : null);
				}
				if (requested || sentRequest || ((Dictionary<object, object>)(object)localPlayer.CustomProperties).ContainsKey((object)"MurphysWings.NativeCycle.v1"))
				{
					val2[(object)"MurphysWings.NativeCycle.v1"] = (requested ? array : null);
				}
				if (((Dictionary<object, object>)(object)val2).Count == 0 || localPlayer.SetCustomProperties(val2, (Hashtable)null, (WebFlags)null))
				{
					sentHost = flag3;
					sentRequest = requested;
				}
				nextRefresh = unscaledTime + 1f;
			}
			if (!flag3)
			{
				return;
			}
			bool flag4 = IsPink(PhotonNetwork.Time);
			if (requested)
			{
				local.OverrideTumbleWings(flag4, 0.35f);
			}
			if (players == null)
			{
				return;
			}
			foreach (PlayerAvatar player in players)
			{
				if (Object.op_Implicit((Object)(object)player) && (Object)(object)player != (Object)(object)local && Object.op_Implicit((Object)(object)player.photonView) && UsesNative(player.photonView.Owner))
				{
					player.OverrideTumbleWings(flag4, 0.35f);
				}
			}
		}

		internal bool UsesNative(Player owner)
		{
			if (hostReady && owner != null && (owner.IsMasterClient || !GameToolsBridge.HostBlocksGuestWings()) && !GameToolsBridge.PlayerFlag(owner, "GT_WingsAlwaysShow"))
			{
				return HasFreshLease(owner, "MurphysWings.NativeCycle.v1");
			}
			return false;
		}

		internal static bool IsPink(double clock)
		{
			return clock % 3.0 < 1.5;
		}

		private bool HasFreshLease(Player player, string key)
		{
			if (room != null && PhotonNetwork.MasterClient != null && ((Dictionary<object, object>)(object)player.CustomProperties).TryGetValue((object)key, out object value) && value is object[] array && array.Length == 3 && array[0] is string text && text == room.Name && array[1] is int num && num == PhotonNetwork.MasterClient.ActorNumber && array[2] is int stamp)
			{
				return IsFresh(PhotonNetwork.ServerTimestamp, stamp);
			}
			return false;
		}

		internal static bool IsFresh(int now, int stamp)
		{
			return (uint)(now - stamp) <= 3000u;
		}

		internal void Stop()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0047: Expected O, but got Unknown
			if (PhotonNetwork.InRoom && PhotonNetwork.LocalPlayer != null && (sentHost || sentRequest))
			{
				Player localPlayer = PhotonNetwork.LocalPlayer;
				Hashtable val = new Hashtable();
				((Dictionary<object, object>)val).Add((object)"MurphysWings.NativeHost.v1", (object)null);
				((Dictionary<object, object>)val).Add((object)"MurphysWings.NativeCycle.v1", (object)null);
				localPlayer.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
			}
		}
	}
	[BepInPlugin("murphyslavv.wings", "Murphys Wings", "1.4.6")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		private const string ModeProperty = "MurphysWings.Mode.v1";

		private const int Follow = 0;

		private const int Always = 1;

		private const int Off = 2;

		private static readonly FieldInfo Dead = FindAvatarField("deadSet");

		private static readonly FieldInfo Disabled = FindAvatarField("isDisabled");

		private static readonly List<InputKey> MenuInputExceptions = new List<InputKey> { (InputKey)18 };

		private readonly Dictionary<PlayerAvatar, WingVisual> visuals = new Dictionary<PlayerAvatar, WingVisual>();

		private readonly List<PlayerAvatar> stale = new List<PlayerAvatar>();

		private readonly NativeWingCycle nativeCycle = new NativeWingCycle();

		private ConfigEntry<WingMode> mode;

		private ConfigEntry<KeyboardShortcut> cycleKey;

		private ConfigEntry<KeyboardShortcut> menuKey;

		private ConfigEntry<WingPalette> localPalette;

		private ConfigEntry<bool> standaloneThirdPerson;

		private ConfigEntry<bool> replaceNative;

		private ConfigEntry<float> size;

		private GameToolsBridge gameTools;

		private WingColorMenu colorMenu;

		private StandaloneCamera standaloneCamera;

		private Mesh wingMesh;

		private Material wingMaterial;

		private int wingColorProperty;

		private bool visualInitializationFailed;

		private bool startupAttempted;

		private bool nativeSharingFailed;

		private float nextPublish;

		private float nextCleanup;

		private Room publishedRoom;

		private string hudText;

		private float hudUntil;

		private bool CanSync => gameTools?.HasWingSync ?? false;

		private WingMode EffectiveMode => WingColors.EffectiveMode(mode.Value, CanSync);

		private bool CanDrawWings
		{
			get
			{
				if (!visualInitializationFailed && Object.op_Implicit((Object)(object)wingMaterial))
				{
					return Object.op_Implicit((Object)(object)wingMesh);
				}
				return false;
			}
		}

		private void Awake()
		{
			//IL_003c: 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_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Expected O, but got Unknown
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			mode = ((BaseUnityPlugin)this).Config.Bind<WingMode>("Wings", "Mode", WingMode.FollowGameTools, "FollowGameTools (GameTools Sync), Always, or Off.");
			cycleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Wings", "CycleMode", new KeyboardShortcut((KeyCode)289, Array.Empty<KeyCode>()), "Cycle the local wing mode.");
			menuKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Wings", "ColorMenu", new KeyboardShortcut((KeyCode)291, Array.Empty<KeyCode>()), "Open the local color menu.");
			localPalette = ((BaseUnityPlugin)this).Config.Bind<WingPalette>("Colors", "LocalPalette", WingPalette.ModeDefault, "Override the color of your own wings on this client.");
			localPalette.Value = WingColors.SavedPalette(localPalette.Value);
			standaloneThirdPerson = ((BaseUnityPlugin)this).Config.Bind<bool>("Camera", "ThirdPerson", false, "Enable the built-in third-person camera when GameTools camera control is unavailable.");
			ConfigEntry<string> customHex = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "CustomRGB", "33D9FF", "Custom RGB color in hexadecimal.");
			colorMenu = new WingColorMenu(mode, localPalette, customHex, ((BaseUnityPlugin)this).Logger);
			replaceNative = ((BaseUnityPlugin)this).Config.Bind<bool>("Wings", "ReplaceNativeMeshes", true, "Hide stock tumble-wing meshes while Murphys Wings are visible on this client.");
			size = ((BaseUnityPlugin)this).Config.Bind<float>("Wings", "Size", 1f, new ConfigDescription("Local wing size multiplier.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.65f, 1.5f), Array.Empty<object>()));
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Wings color menu ready. Shortcut: {menuKey.Value}.");
		}

		private void Start()
		{
			EnsureInitialized();
		}

		private void EnsureInitialized()
		{
			if (!startupAttempted)
			{
				startupAttempted = true;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Wings startup: initializing custom renderer.");
				try
				{
					InitializeRenderer();
				}
				catch (Exception arg)
				{
					visualInitializationFailed = true;
					((BaseUnityPlugin)this).Logger.LogError((object)$"Wings startup: custom renderer failed. {arg}");
				}
				try
				{
					gameTools = CreateGameToolsBridge();
				}
				catch (Exception arg2)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)$"Wings startup: GameTools bridge unavailable. {arg2}");
				}
				try
				{
					standaloneCamera = CreateStandaloneCamera();
				}
				catch (Exception arg3)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)$"Wings startup: built-in camera unavailable. {arg3}");
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)$"Wings startup complete. Renderer ready: {CanDrawWings}.");
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private GameToolsBridge CreateGameToolsBridge()
		{
			return new GameToolsBridge(((BaseUnityPlugin)this).Logger);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private StandaloneCamera CreateStandaloneCamera()
		{
			return new StandaloneCamera(GetStandaloneCameraAvatar, ((BaseUnityPlugin)this).Logger);
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void InitializeRenderer()
		{
			wingMaterial = WingVisual.CreateMaterial(out wingColorProperty);
			if (!Object.op_Implicit((Object)(object)wingMaterial))
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Wings startup: no compatible shader found for custom wings.");
				return;
			}
			wingMesh = WingVisual.BuildMesh();
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Custom wing renderer ready. Shader: " + ((Object)wingMaterial.shader).name + "."));
		}

		private void UpdateNativeSharing(WingMode activeMode, WingPalette palette, PlayerAvatar local, List<PlayerAvatar> players)
		{
			if (nativeSharingFailed)
			{
				return;
			}
			try
			{
				nativeCycle.Tick(gameTools, activeMode != WingMode.Off && palette == WingPalette.NativeRgb, local, players);
			}
			catch (Exception arg)
			{
				nativeSharingFailed = true;
				((BaseUnityPlugin)this).Logger.LogWarning((object)$"Native wing sharing stopped. {arg}");
			}
		}

		private void OnEnable()
		{
			SceneManager.activeSceneChanged += OnSceneChanged;
		}

		private void OnSceneChanged(Scene previous, Scene current)
		{
			standaloneCamera?.Restore();
			ClearVisuals();
		}

		private void Update()
		{
			//IL_0072: 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)
			EnsureInitialized();
			if (standaloneThirdPerson.Value)
			{
				StandaloneCamera obj = standaloneCamera;
				if (obj != null && obj.CanEnable && !standaloneCamera.Available && Object.op_Implicit((Object)(object)GetStandaloneCameraAvatar()))
				{
					standaloneCamera.Install();
					if (!standaloneCamera.Available)
					{
						standaloneThirdPerson.Value = false;
					}
				}
			}
			if (Application.isFocused && MenuShortcutPressed(menuKey.Value))
			{
				if (colorMenu.IsOpen)
				{
					colorMenu.Close();
				}
				else
				{
					OpenColorMenu("keyboard");
				}
			}
			else if (colorMenu.IsOpen)
			{
				if (Object.op_Implicit((Object)(object)InputManager.instance) && Object.op_Implicit((Object)(object)SemiFunc.PlayerAvatarLocal()) && !ShowMenuLauncher())
				{
					GameToolsBridge gameToolsBridge = gameTools;
					if (gameToolsBridge == null || !gameToolsBridge.IsMenuOpen)
					{
						InputManager.instance.DisableControlsExcept(0.1f, MenuInputExceptions);
					}
				}
			}
			else
			{
				if (!CanDrawWings || !Object.op_Implicit((Object)(object)SemiFunc.PlayerAvatarLocal()) || ShowMenuLauncher())
				{
					return;
				}
				GameToolsBridge gameToolsBridge2 = gameTools;
				if (gameToolsBridge2 == null || !gameToolsBridge2.IsMenuOpen)
				{
					KeyboardShortcut value = cycleKey.Value;
					if (((KeyboardShortcut)(ref value)).IsDown() && SemiFunc.NoTextInputsActive())
					{
						ConfigEntry<WingMode> val = mode;
						val.Value = EffectiveMode switch
						{
							WingMode.FollowGameTools => WingMode.Always, 
							WingMode.Always => WingMode.Off, 
							_ => (!CanSync) ? WingMode.Always : WingMode.FollowGameTools, 
						};
						hudText = ((mode.Value == WingMode.FollowGameTools) ? "Wings • GameTools Sync" : $"Wings • {mode.Value}");
						hudUntil = Time.unscaledTime + 2.5f;
					}
				}
			}
		}

		private static bool MenuShortcutPressed(KeyboardShortcut shortcut)
		{
			//IL_0002: 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)
			if ((int)((KeyboardShortcut)(ref shortcut)).MainKey != 0 && UnityInput.Current.GetKeyDown(((KeyboardShortcut)(ref shortcut)).MainKey))
			{
				return ((KeyboardShortcut)(ref shortcut)).Modifiers.All((Func<KeyCode, bool>)UnityInput.Current.GetKey);
			}
			return false;
		}

		private static bool ShowMenuLauncher()
		{
			MenuManager instance = MenuManager.instance;
			if (Object.op_Implicit((Object)(object)instance))
			{
				if (!instance.PageCheck((MenuPageIndex)0))
				{
					return instance.PageCheck((MenuPageIndex)1);
				}
				return true;
			}
			return false;
		}

		private void OpenColorMenu(string source)
		{
			EnsureInitialized();
			colorMenu.Open();
			((BaseUnityPlugin)this).Logger.LogDebug((object)("Wings color menu opened from " + source + "."));
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"Wings status: renderer ready={CanDrawWings}, mode={EffectiveMode}, palette={colorMenu.SelectedPalette}.");
		}

		private void LateUpdate()
		{
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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)
			if (colorMenu.IsOpen && Application.isFocused)
			{
				colorMenu.FreeCursor();
			}
			float unscaledTime = Time.unscaledTime;
			PlayerAvatar val = SemiFunc.PlayerAvatarLocal();
			List<PlayerAvatar> list = (Object.op_Implicit((Object)(object)GameDirector.instance) ? GameDirector.instance.PlayerList : null);
			WingMode effectiveMode = EffectiveMode;
			WingPalette selectedPalette = colorMenu.SelectedPalette;
			UpdateNativeSharing(effectiveMode, selectedPalette, val, list);
			if (!CanDrawWings)
			{
				return;
			}
			PublishMode(unscaledTime);
			double clock = (PhotonNetwork.InRoom ? PhotonNetwork.Time : ((double)Time.time));
			Camera main = Camera.main;
			if (list != null)
			{
				foreach (PlayerAvatar item in list)
				{
					if (Object.op_Implicit((Object)(object)item) && !((Object)(object)item == (Object)(object)val))
					{
						Player owner = ((PhotonNetwork.InRoom && Object.op_Implicit((Object)(object)item.photonView)) ? item.photonView.Owner : null);
						WingPalette color = ((nativeSharingFailed || !nativeCycle.UsesNative(owner)) ? GetRemoteColor(owner) : WingPalette.ModeDefault);
						UpdateVisual(item, color, clock, main);
					}
				}
			}
			if (Object.op_Implicit((Object)(object)val))
			{
				WingPalette synced = ((effectiveMode == WingMode.FollowGameTools && selectedPalette == WingPalette.ModeDefault) ? gameTools.LocalColor() : WingPalette.ModeDefault);
				WingPalette wingPalette = WingColors.ResolveLocal(effectiveMode, selectedPalette, synced);
				if (!nativeSharingFailed && nativeCycle.LocalUsesNative)
				{
					wingPalette = WingPalette.ModeDefault;
				}
				PlayerAvatarVisuals playerAvatarVisuals = val.playerAvatarVisuals;
				if (wingPalette != WingPalette.ModeDefault && Object.op_Implicit((Object)(object)main) && Object.op_Implicit((Object)(object)playerAvatarVisuals))
				{
					Vector3 val2 = ((Component)main).transform.position - ((Component)playerAvatarVisuals).transform.position;
					if (((Vector3)(ref val2)).sqrMagnitude < 0.1225f)
					{
						wingPalette = WingPalette.ModeDefault;
					}
				}
				UpdateVisual(val, wingPalette, clock, main, colorMenu.CustomColor);
			}
			if (!(unscaledTime >= nextCleanup))
			{
				return;
			}
			nextCleanup = unscaledTime + 1f;
			foreach (KeyValuePair<PlayerAvatar, WingVisual> visual in visuals)
			{
				if (!Object.op_Implicit((Object)(object)visual.Key) || !visual.Value.IsAttachedTo(visual.Key.playerAvatarVisuals) || ((Object)(object)visual.Key != (Object)(object)val && (list == null || !list.Contains(visual.Key))))
				{
					stale.Add(visual.Key);
				}
			}
			foreach (PlayerAvatar item2 in stale)
			{
				visuals[item2].Dispose();
				visuals.Remove(item2);
			}
			stale.Clear();
		}

		private void OnGUI()
		{
			//IL_0159: 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)
			if (colorMenu != null && colorMenu.IsOpen)
			{
				bool flag = gameTools?.CanToggleCamera() ?? false;
				bool cameraAvailable = flag || (standaloneCamera?.CanEnable ?? false);
				bool thirdPerson = (flag ? gameTools.ThirdPersonEnabled : standaloneThirdPerson.Value);
				if (!colorMenu.Draw(PhotonNetwork.InRoom ? PhotonNetwork.Time : ((double)Time.time), gameTools, nativeCycle.Status, cameraAvailable, thirdPerson, CanSync, CanDrawWings))
				{
					return;
				}
				if (flag)
				{
					gameTools.ToggleThirdPerson();
					return;
				}
				standaloneThirdPerson.Value = !standaloneThirdPerson.Value;
				if (!standaloneThirdPerson.Value)
				{
					standaloneCamera.Restore();
				}
			}
			else if (colorMenu != null && ShowMenuLauncher())
			{
				if (GUI.Button(new Rect((float)Screen.width - 118f, 12f, 106f, 28f), "Wings"))
				{
					OpenColorMenu("menu button");
				}
			}
			else if (Time.unscaledTime < hudUntil)
			{
				GUI.Label(new Rect(18f, (float)Screen.height * 0.68f, 360f, 32f), hudText);
			}
		}

		private PlayerAvatar GetStandaloneCameraAvatar()
		{
			if (((Behaviour)this).isActiveAndEnabled && standaloneThirdPerson.Value)
			{
				GameToolsBridge gameToolsBridge = gameTools;
				if ((gameToolsBridge == null || !gameToolsBridge.CanToggleCamera()) && Object.op_Implicit((Object)(object)RunManager.instance) && !SemiFunc.MenuLevel())
				{
					PlayerAvatar val = SemiFunc.PlayerAvatarLocal();
					if (!Object.op_Implicit((Object)(object)val) || !((Behaviour)val).isActiveAndEnabled || IsSet(Dead, val) || IsSet(Disabled, val))
					{
						return null;
					}
					return val;
				}
			}
			return null;
		}

		private void PublishMode(float now)
		{
			//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_0083: Expected O, but got Unknown
			//IL_008a: Expected O, but got Unknown
			Room currentRoom = PhotonNetwork.CurrentRoom;
			if (!PhotonNetwork.InRoom || currentRoom == null || PhotonNetwork.LocalPlayer == null)
			{
				publishedRoom = null;
			}
			else if (currentRoom != publishedRoom || !(now < nextPublish))
			{
				publishedRoom = currentRoom;
				nextPublish = now + 0.5f;
				int num = EffectiveMode switch
				{
					WingMode.Off => 2, 
					WingMode.Always => 1, 
					_ => 0, 
				};
				Player localPlayer = PhotonNetwork.LocalPlayer;
				if (PublishedMode(localPlayer) != num)
				{
					Hashtable val = new Hashtable();
					((Dictionary<object, object>)val).Add((object)"MurphysWings.Mode.v1", (object)num);
					localPlayer.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
				}
			}
		}

		private static int PublishedMode(Player owner)
		{
			if (owner != null && ((Dictionary<object, object>)(object)owner.CustomProperties).TryGetValue((object)"MurphysWings.Mode.v1", out object value) && value is int)
			{
				return (int)value;
			}
			return 0;
		}

		private static WingPalette GetRemoteColor(Player owner)
		{
			return PublishedMode(owner) switch
			{
				1 => WingPalette.Alm, 
				2 => WingPalette.ModeDefault, 
				_ => GameToolsBridge.RemoteColor(owner), 
			};
		}

		private void UpdateVisual(PlayerAvatar avatar, WingPalette color, double clock, Camera camera, Color customColor = default(Color))
		{
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			if (!CanDrawWings)
			{
				return;
			}
			PlayerAvatarVisuals playerAvatarVisuals = avatar.playerAvatarVisuals;
			if (visuals.TryGetValue(avatar, out var value) && !value.IsAttachedTo(playerAvatarVisuals))
			{
				value.Dispose();
				visuals.Remove(avatar);
				value = null;
			}
			if (color == WingPalette.ModeDefault || !((Behaviour)avatar).isActiveAndEnabled || !Object.op_Implicit((Object)(object)playerAvatarVisuals) || !((Behaviour)playerAvatarVisuals).isActiveAndEnabled || !((Component)playerAvatarVisuals).gameObject.activeInHierarchy || IsSet(Dead, avatar) || IsSet(Disabled, avatar))
			{
				value?.Hide();
				return;
			}
			try
			{
				if (value == null)
				{
					value = new WingVisual(avatar, playerAvatarVisuals, wingMesh, wingMaterial, wingColorProperty);
					visuals.Add(avatar, value);
					if ((Object)(object)avatar == (Object)(object)SemiFunc.PlayerAvatarLocal())
					{
						((BaseUnityPlugin)this).Logger.LogInfo((object)$"Local wing model attached. Palette: {color}.");
					}
				}
				value.Show(color, customColor, size.Value, replaceNative.Value, clock, camera);
			}
			catch (Exception arg)
			{
				visualInitializationFailed = true;
				((BaseUnityPlugin)this).Logger.LogError((object)$"Custom wing renderer stopped after an error. {arg}");
				ClearVisuals();
			}
		}

		private static FieldInfo FindAvatarField(string name)
		{
			return typeof(PlayerAvatar).GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		}

		private static bool IsSet(FieldInfo field, PlayerAvatar avatar)
		{
			object obj = field?.GetValue(avatar);
			bool flag = default(bool);
			int num;
			if (obj is bool)
			{
				flag = (bool)obj;
				num = 1;
			}
			else
			{
				num = 0;
			}
			return (byte)((uint)num & (flag ? 1u : 0u)) != 0;
		}

		private void OnDisable()
		{
			//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_007c: Expected O, but got Unknown
			//IL_0083: Expected O, but got Unknown
			SceneManager.activeSceneChanged -= OnSceneChanged;
			standaloneCamera?.Restore();
			colorMenu?.Close();
			nativeCycle.Stop();
			ClearVisuals();
			Player localPlayer = PhotonNetwork.LocalPlayer;
			if (PhotonNetwork.InRoom && publishedRoom != null && localPlayer != null && PublishedMode(localPlayer) != 0)
			{
				Hashtable val = new Hashtable();
				((Dictionary<object, object>)val).Add((object)"MurphysWings.Mode.v1", (object)0);
				localPlayer.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
			}
			publishedRoom = null;
		}

		private void ClearVisuals()
		{
			foreach (WingVisual value in visuals.Values)
			{
				value.Dispose();
			}
			visuals.Clear();
			stale.Clear();
		}

		private void OnDestroy()
		{
			standaloneCamera?.Shutdown();
			colorMenu?.DestroyArtwork();
			Object.Destroy((Object)(object)wingMesh);
			Object.Destroy((Object)(object)wingMaterial);
		}
	}
	internal sealed class StandaloneCamera
	{
		private const string PatchId = "murphyslavv.wings.camera";

		private static StandaloneCamera current;

		private readonly Func<PlayerAvatar> getAvatar;

		private readonly ManualLogSource log;

		private readonly Harmony patches = new Harmony("murphyslavv.wings.camera");

		private MethodInfo update;

		private bool installAttempted;

		private readonly int collisionLayers = LayerMask.GetMask(new string[3] { "Default", "World", "Terrain" });

		private Transform displacedCamera;

		private Transform originalParent;

		private Vector3 originalPosition;

		private Vector3 appliedPosition;

		internal bool Available { get; private set; }

		internal bool CanEnable
		{
			get
			{
				if (!Available)
				{
					return !installAttempted;
				}
				return true;
			}
		}

		internal StandaloneCamera(Func<PlayerAvatar> getAvatar, ManualLogSource log)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			this.getAvatar = getAvatar;
			this.log = log;
		}

		internal void Install()
		{
			//IL_00a8: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			//IL_00e2: Expected O, but got Unknown
			if (installAttempted)
			{
				return;
			}
			installAttempted = true;
			try
			{
				update = AccessTools.DeclaredMethod(typeof(CameraPosition), "Update", (Type[])null, (Type[])null);
				if (update == null || AccessTools.DeclaredField(typeof(CameraPosition), "overridePositionActive")?.FieldType != typeof(bool))
				{
					throw new MissingMemberException("The game camera update or override flag could not be found.");
				}
				log.LogInfo((object)"Installing the built-in third-person camera hook.");
				patches.Patch((MethodBase)update, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(StandaloneCamera), "BeforeUpdate", (Type[])null, (Type[])null))
				{
					priority = 800
				}, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(StandaloneCamera), "AfterUpdate", (Type[])null, (Type[])null))
				{
					priority = 0
				}, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				current = this;
				Available = true;
				log.LogInfo((object)"Built-in third-person camera hook ready.");
			}
			catch (Exception ex)
			{
				Shutdown();
				log.LogWarning((object)("Built-in third person unavailable. " + ex.GetBaseException().Message));
			}
		}

		private static void BeforeUpdate(CameraPosition __instance)
		{
			if ((Object)(object)__instance == (Object)(object)CameraPosition.instance)
			{
				current?.Restore();
			}
		}

		private static void AfterUpdate(CameraPosition __instance, bool ___overridePositionActive)
		{
			if (current == null || (Object)(object)__instance != (Object)(object)CameraPosition.instance || ___overridePositionActive)
			{
				return;
			}
			try
			{
				current.Apply();
			}
			catch (Exception ex)
			{
				current.Restore();
				current.Available = false;
				current.log.LogWarning((object)("Built-in third person stopped. " + ex.GetBaseException().Message));
			}
		}

		private void Apply()
		{
			//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_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_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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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_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_0114: 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_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_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			if (!Available)
			{
				return;
			}
			PlayerAvatar val = getAvatar();
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val.playerAvatarVisuals) || (Object.op_Implicit((Object)(object)Map.Instance) && Map.Instance.Active))
			{
				return;
			}
			Camera main = Camera.main;
			if (Object.op_Implicit((Object)(object)main) && ((Behaviour)main).isActiveAndEnabled)
			{
				Transform transform = ((Component)main).transform;
				Vector3 position = transform.position;
				Vector3 val2 = -transform.forward * 2.2f + Vector3.up * 0.45f;
				float num = ((Vector3)(ref val2)).magnitude;
				Vector3 val3 = val2 / num;
				RaycastHit val4 = default(RaycastHit);
				if (Physics.SphereCast(position, 0.2f, val3, ref val4, num, collisionLayers, (QueryTriggerInteraction)1))
				{
					num = Mathf.Max(0f, ((RaycastHit)(ref val4)).distance - 0.05f);
				}
				if (!(num < 0.35f))
				{
					val.playerAvatarVisuals.ShowSelfOverride(0.15f);
					displacedCamera = transform;
					originalParent = transform.parent;
					originalPosition = transform.localPosition;
					transform.position = position + val3 * num;
					appliedPosition = transform.localPosition;
				}
			}
		}

		internal void Restore()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)displacedCamera) && (Object)(object)displacedCamera.parent == (Object)(object)originalParent && displacedCamera.localPosition == appliedPosition)
			{
				displacedCamera.localPosition = originalPosition;
			}
			displacedCamera = null;
		}

		internal void Shutdown()
		{
			Restore();
			if (current == this)
			{
				current = null;
			}
			try
			{
				if (update != null)
				{
					patches.Unpatch((MethodBase)update, (HarmonyPatchType)0, "murphyslavv.wings.camera");
				}
			}
			catch (Exception ex)
			{
				log.LogWarning((object)("Built-in camera patch cleanup failed. " + ex.GetBaseException().Message));
			}
			Available = false;
		}
	}
	internal sealed class WingColorMenu
	{
		private const float Width = 368f;

		private const float HeaderHeight = 62f;

		private const float ContentHeight = 409f;

		private const float Height = 471f;

		private const float WordmarkWidth = 278f;

		private const int TextSize = 10;

		private static readonly Color Accent = new Color(1f, 0.3f, 0.66f);

		private static readonly GUIContent[] Modes = (GUIContent[])(object)new GUIContent[3]
		{
			new GUIContent("GameTools Sync"),
			new GUIContent("Always"),
			new GUIContent("Off")
		};

		private static readonly (WingPalette Palette, string Name)[] Presets = new(WingPalette, string)[9]
		{
			(WingPalette.Pink, "Pink"),
			(WingPalette.Blue, "Blue"),
			(WingPalette.Crimson, "Crimson"),
			(WingPalette.Lime, "Lime"),
			(WingPalette.Violet, "Violet"),
			(WingPalette.Gold, "Gold"),
			(WingPalette.White, "White"),
			(WingPalette.RedBlue, "Red / Blue"),
			(WingPalette.Alm, "ALM")
		};

		private readonly ConfigEntry<WingMode> mode;

		private readonly ConfigEntry<WingPalette> palette;

		private readonly ConfigEntry<string> customHex;

		private readonly Texture2D wordmark;

		private GUIStyle labelStyle;

		private GUIStyle creditStyle;

		private GUIStyle buttonStyle;

		private CursorLockMode previousLock;

		private bool previousCursorVisible;

		private bool customEdited;

		private bool nativeRgbSelected;

		private int activeMouseControl;

		internal bool IsOpen { get; private set; }

		internal Color CustomColor { get; private set; }

		internal WingPalette SelectedPalette
		{
			get
			{
				if (!nativeRgbSelected)
				{
					return palette.Value;
				}
				return WingPalette.NativeRgb;
			}
		}

		internal WingColorMenu(ConfigEntry<WingMode> mode, ConfigEntry<WingPalette> palette, ConfigEntry<string> customHex, ManualLogSource log)
		{
			//IL_005f: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			this.mode = mode;
			this.palette = palette;
			this.customHex = customHex;
			wordmark = LoadWordmark(log);
			Color val = default(Color);
			CustomColor = (ColorUtility.TryParseHtmlString("#" + customHex.Value.TrimStart('#'), ref val) ? new Color(val.r, val.g, val.b) : new Color(0.2f, 0.8509804f, 1f));
		}

		private void SelectPalette(WingPalette selection)
		{
			nativeRgbSelected = false;
			palette.Value = selection;
		}

		private static Texture2D LoadWordmark(ManualLogSource log)
		{
			//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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			Texture2D val = null;
			try
			{
				using Stream stream = typeof(WingColorMenu).Assembly.GetManifestResourceStream("MurphysWings.MurphysLavvWordmark.png");
				if (stream == null)
				{
					throw new InvalidDataException("Missing embedded wordmark.");
				}
				using MemoryStream memoryStream = new MemoryStream();
				stream.CopyTo(memoryStream);
				val = new Texture2D(2, 2, (TextureFormat)4, false)
				{
					name = "MurphysLavv Menu wordmark",
					wrapMode = (TextureWrapMode)1
				};
				if (!ImageConversion.LoadImage(val, memoryStream.ToArray(), true))
				{
					throw new InvalidDataException("Invalid wordmark PNG.");
				}
				return val;
			}
			catch (Exception ex)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					Object.Destroy((Object)(object)val);
				}
				log.LogWarning((object)("Could not load the Wings menu wordmark. " + ex.Message));
				return null;
			}
		}

		internal void DestroyArtwork()
		{
			if (Object.op_Implicit((Object)(object)wordmark))
			{
				Object.Destroy((Object)(object)wordmark);
			}
		}

		internal void Open()
		{
			//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)
			if (!IsOpen)
			{
				previousLock = Cursor.lockState;
				previousCursorVisible = Cursor.visible;
				IsOpen = true;
				FreeCursor();
			}
		}

		internal void Close(bool restoreCursor = true)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			if (IsOpen)
			{
				IsOpen = false;
				if (activeMouseControl != 0 && GUIUtility.hotControl == activeMouseControl)
				{
					GUIUtility.hotControl = 0;
				}
				activeMouseControl = 0;
				if (restoreCursor)
				{
					Cursor.lockState = previousLock;
					Cursor.visible = previousCursorVisible;
				}
				SaveCustomColor();
			}
		}

		internal void FreeCursor()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Cursor.lockState != 0)
			{
				Cursor.lockState = (CursorLockMode)0;
			}
			if (!Cursor.visible)
			{
				Cursor.visible = true;
			}
		}

		internal bool Draw(double clock, GameToolsBridge gameTools, string nativeStatus, bool cameraAvailable, bool thirdPerson, bool canSync, bool wingRendererAvailable)
		{
			//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_0025: Expected O, but got Unknown
			//IL_0034: 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_0045: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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_0101: 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_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: 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_02f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0489: Unknown result type (might be due to invalid IL or missing references)
			//IL_048f: 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_04b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0506: Unknown result type (might be due to invalid IL or missing references)
			//IL_0521: 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_0579: Invalid comparison between Unknown and I4
			//IL_0548: Unknown result type (might be due to invalid IL or missing references)
			//IL_054b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0596: 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_062e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0650: Unknown result type (might be due to invalid IL or missing references)
			if (labelStyle == null)
			{
				labelStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 10
				};
			}
			if (creditStyle == null)
			{
				creditStyle = new GUIStyle(labelStyle)
				{
					alignment = (TextAnchor)5
				};
			}
			if (buttonStyle == null)
			{
				buttonStyle = new GUIStyle(GUI.skin.button)
				{
					name = "MurphysWingsButton",
					fontSize = 10
				};
			}
			float num = Mathf.Min(new float[3]
			{
				1f,
				((float)Screen.width - 24f) / 368f,
				((float)Screen.height - 24f) / 471f
			});
			Rect val = new Rect(0f, 0f, 368f, 471f);
			Matrix4x4 matrix = GUI.matrix;
			int depth = GUI.depth;
			int hotControl = GUIUtility.hotControl;
			GUI.matrix = Matrix4x4.TRS(new Vector3((float)Screen.width - 368f * num - 12f, 12f, 0f), Quaternion.identity, new Vector3(num, num, 1f));
			GUI.depth = -30;
			GUI.BeginGroup(val);
			Fill(val, new Color(0.055f, 0.06f, 0.1f, 0.98f));
			Fill(new Rect(0f, 0f, 184f, 3f), Accent);
			Fill(new Rect(184f, 0f, 184f, 3f), new Color(0.2f, 0.69f, 1f));
			if (Object.op_Implicit((Object)(object)wordmark))
			{
				GUI.DrawTexture(new Rect(45f, 5f, 278f, 62f), (Texture)(object)wordmark, (ScaleMode)2, true);
			}
			else
			{
				GUI.Label(new Rect(16f, 11f, 300f, 50f), "MurphysLavv Menu", labelStyle);
			}
			GUI.BeginGroup(new Rect(0f, 62f, 368f, 409f));
			GUI.Label(new Rect(123f, 10f, 156f, 24f), "Created by Murphy.Dev", creditStyle);
			bool flag = GUI.Button(new Rect(287f, 10f, 65f, 24f), "Close", buttonStyle);
			WingMode wingMode = WingColors.EffectiveMode(mode.Value, canSync);
			int num2 = GUI.Toolbar(new Rect(16f, 43f, 336f, 25f), (int)wingMode, Modes, buttonStyle);
			if (num2 >= 0 && num2 != (int)wingMode && (canSync || num2 != 0))
			{
				mode.Value = (WingMode)num2;
			}
			wingMode = WingColors.EffectiveMode(mode.Value, canSync);
			GUI.Label(new Rect(16f, 76f, 183f, 23f), "Local wing colors", labelStyle);
			if (ColorButton(new Rect(219f, 76f, 133f, 23f), "Mode default", SelectedPalette == WingPalette.ModeDefault))
			{
				SelectPalette(WingPalette.ModeDefault);
			}
			Rect rect = default(Rect);
			for (int i = 0; i < Presets.Length; i++)
			{
				(WingPalette, string) tuple = Presets[i];
				((Rect)(ref rect))..ctor((float)(16 + i % 3 * 114), (float)(107 + i / 3 * 28), 108f, 25f);
				if (ColorButton(rect, tuple.Item2, SelectedPalette == tuple.Item1))
				{
					SelectPalette(tuple.Item1);
				}
				(Color, Color) tuple2 = WingColors.Resolve(tuple.Item1, CustomColor, clock);
				Fill(new Rect(((Rect)(ref rect)).x + 5f, ((Rect)(ref rect)).y + 5f, 4f, 15f), tuple2.Item1);
				Fill(new Rect(((Rect)(ref rect)).x + 9f, ((Rect)(ref rect)).y + 5f, 4f, 15f), tuple2.Item2);
			}
			if (ColorButton(new Rect(16f, 199f, 98f, 24f), "Custom", SelectedPalette == WingPalette.Custom))
			{
				SelectPalette(WingPalette.Custom);
			}
			Fill(new Rect(125f, 202f, 34f, 18f), CustomColor);
			GUI.Label(new Rect(168f, 200f, 97f, 22f), "#" + ColorUtility.ToHtmlStringRGB(CustomColor), labelStyle);
			bool changed = GUI.changed;
			GUI.changed = false;
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(Channel(233f, "R", CustomColor.r), Channel(255f, "G", CustomColor.g), Channel(277f, "B", CustomColor.b));
			bool changed2 = GUI.changed;
			GUI.changed = changed || changed2;
			if (changed2 && val2 != CustomColor)
			{
				CustomColor = val2;
				customEdited = true;
				SelectPalette(WingPalette.Custom);
			}
			if ((int)Event.current.rawType == 1)
			{
				SaveCustomColor();
			}
			if (ColorButton(new Rect(16f, 354f, 145f, 24f), "Native RGB", nativeRgbSelected))
			{
				nativeRgbSelected = !nativeRgbSelected;
			}
			WingPalette synced = ((wingMode == WingMode.FollowGameTools) ? gameTools.LocalColor() : WingPalette.ModeDefault);
			DrawActivePalette(clock, wingMode, WingColors.ResolveLocal(wingMode, SelectedPalette, synced));
			bool result = DrawCameraControl(cameraAvailable, thirdPerson);
			string text = ((nativeRgbSelected && wingMode != WingMode.Off) ? nativeStatus : ((!wingRendererAvailable) ? "Custom wing renderer unavailable. See BepInEx log." : ((!canSync) ? "Standalone wings. GameTools Sync is unavailable." : "Local colors are private.")));
			GUI.Label(new Rect(16f, 382f, 336f, 21f), text, labelStyle);
			GUI.EndGroup();
			GUI.EndGroup();
			GUI.depth = depth;
			GUI.matrix = matrix;
			if (hotControl != GUIUtility.hotControl)
			{
				activeMouseControl = GUIUtility.hotControl;
			}
			if (flag)
			{
				Close();
			}
			return result;
		}

		private bool DrawCameraControl(bool available, bool enabled)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			bool enabled2 = GUI.enabled;
			GUI.enabled = enabled2 && available;
			bool flag = ColorButton(new Rect(16f, 326f, 145f, 24f), enabled ? "Third person: On" : "Third person: Off", enabled);
			GUI.enabled = enabled2;
			if (!available)
			{
				GUI.Label(new Rect(171f, 326f, 181f, 24f), "Camera control unavailable.", labelStyle);
			}
			return flag && available;
		}

		private void DrawActivePalette(double clock, WingMode activeMode, WingPalette active)
		{
			//IL_0028: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			string text;
			switch (active)
			{
			case WingPalette.ModeDefault:
			{
				string text2 = ((activeMode == WingMode.Off) ? "Wings are off. Select Always or GameTools Sync." : "Waiting for GameTools wings. Pick a local color to show yours.");
				GUI.Label(new Rect(16f, 303f, 336f, 21f), text2, labelStyle);
				return;
			}
			case WingPalette.NativeRgb:
				text = "Native RGB";
				break;
			case WingPalette.GameToolsRedBlue:
				text = "Red / Blue";
				break;
			default:
				text = active.ToString();
				break;
			}
			string text3 = text;
			(WingPalette, string)[] presets = Presets;
			for (int i = 0; i < presets.Length; i++)
			{
				(WingPalette, string) tuple = presets[i];
				if (tuple.Item1 == active)
				{
					text3 = tuple.Item2;
					break;
				}
			}
			(Color, Color) tuple2 = WingColors.Resolve(active, CustomColor, clock);
			Fill(new Rect(17f, 308f, 10f, 12f), tuple2.Item1);
			Fill(new Rect(27f, 308f, 10f, 12f), tuple2.Item2);
			GUI.Label(new Rect(44f, 303f, 308f, 21f), "Active palette: " + text3, labelStyle);
		}

		private void SaveCustomColor()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (customEdited)
			{
				customHex.Value = ColorUtility.ToHtmlStringRGB(CustomColor);
				customEdited = false;
			}
		}

		private float Channel(float y, string name, float value)
		{
			//IL_0016: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			GUI.Label(new Rect(16f, y - 2f, 22f, 22f), name, labelStyle);
			float num = GUI.HorizontalSlider(new Rect(38f, y + 5f, 270f, 18f), value, 0f, 1f);
			GUI.Label(new Rect(320f, y - 2f, 33f, 22f), Mathf.RoundToInt(num * 255f).ToString(), labelStyle);
			return Mathf.Round(num * 255f) / 255f;
		}

		private bool ColorButton(Rect rect, string label, bool selected)
		{
			//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)
			//IL_0013: 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_0009: Unknown result type (might be due to invalid IL or missing references)
			Color backgroundColor = GUI.backgroundColor;
			if (selected)
			{
				GUI.backgroundColor = Accent;
			}
			bool result = GUI.Button(rect, label, buttonStyle);
			GUI.backgroundColor = backgroundColor;
			return result;
		}

		private static void Fill(Rect rect, Color color)
		{
			//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)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Color color2 = GUI.color;
			GUI.color = color;
			GUI.DrawTexture(rect, (Texture)(object)Texture2D.whiteTexture);
			GUI.color = color2;
		}
	}
	public enum WingMode
	{
		FollowGameTools,
		Always,
		Off
	}
	public enum WingPalette
	{
		ModeDefault,
		Pink,
		Blue,
		RedBlue,
		Alm,
		Crimson,
		Lime,
		Violet,
		Gold,
		White,
		Custom,
		NativeRgb,
		GameToolsRedBlue
	}
	internal static class WingColors
	{
		private static readonly Color Pink = new Color(1f, 0.06f, 0.53f);

		private static readonly Color Blue = new Color(0.04f, 0.64f, 1f);

		private static readonly Color Red = new Color(1f, 0.09f, 0.2f);

		internal static WingMode EffectiveMode(WingMode mode, bool canSync)
		{
			if (mode != WingMode.FollowGameTools || canSync)
			{
				return mode;
			}
			return WingMode.Always;
		}

		internal static WingPalette SavedPalette(WingPalette palette)
		{
			return palette switch
			{
				WingPalette.NativeRgb => WingPalette.ModeDefault, 
				WingPalette.GameToolsRedBlue => WingPalette.RedBlue, 
				_ => palette, 
			};
		}

		internal static WingPalette ResolveLocal(WingMode mode, WingPalette local, WingPalette synced)
		{
			if (mode == WingMode.Off)
			{
				return WingPalette.ModeDefault;
			}
			if (local != WingPalette.ModeDefault)
			{
				return local;
			}
			if (mode != WingMode.Always)
			{
				return synced;
			}
			return WingPalette.Alm;
		}

		internal static (Color Right, Color Left) Resolve(WingPalette palette, Color custom, double clock)
		{
			//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_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_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_00db: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_00e1: 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_00d3: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			Color val;
			switch (palette)
			{
			case WingPalette.Alm:
				return (Right: Pink, Left: Blue);
			case WingPalette.RedBlue:
			case WingPalette.GameToolsRedBlue:
				return (Right: Red, Left: Blue);
			case WingPalette.Pink:
				val = Pink;
				break;
			case WingPalette.Crimson:
				val = Red;
				break;
			case WingPalette.Lime:
				val = new Color(0.45f, 1f, 0.1f);
				break;
			case WingPalette.Violet:
				val = new Color(0.66f, 0.26f, 1f);
				break;
			case WingPalette.Gold:
				val = new Color(1f, 0.72f, 0.14f);
				break;
			case WingPalette.White:
				val = Color.white;
				break;
			case WingPalette.Custom:
				val = custom;
				break;
			case WingPalette.NativeRgb:
				val = (NativeWingCycle.IsPink(clock) ? Pink : Blue);
				break;
			default:
				val = Blue;
				break;
			}
			Color val2 = val;
			return (Right: val2, Left: val2);
		}
	}
	internal sealed class WingVisual
	{
		private readonly int colorProperty;

		private readonly PlayerAvatar avatar;

		private readonly PlayerAvatarVisuals body;

		private readonly Transform root;

		private readonly MeshRenderer right;

		private readonly MeshRenderer left;

		private readonly MaterialPropertyBlock block = new MaterialPropertyBlock();

		private static readonly int NativeBaseColor = Shader.PropertyToID("_BaseColor");

		private static readonly int NativeRimColor = Shader.PropertyToID("_FresnelColor");

		private ItemUpgradePlayerTumbleWingsLogic native;

		private MeshRenderer nativeLeft;

		private MeshRenderer nativeRight;

		private Transform stockRoot;

		private Transform stockLeftPivot;

		private Transform stockRightPivot;

		private MeshRenderer stockLeft;

		private MeshRenderer stockRight;

		private bool nativeLeftWasHidden;

		private bool nativeRightWasHidden;

		private bool hidingNative;

		private float nextNativeLookup;

		internal WingVisual(PlayerAvatar avatar, PlayerAvatarVisuals body, Mesh mesh, Material material, int colorProperty)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			this.avatar = avatar;
			this.body = body;
			this.colorProperty = colorProperty;
			GameObject val = new GameObject("Murphys Wings");
			root = val.transform;
			try
			{
				root.SetParent(((Component)body).transform, false);
				Material[] materials = (Material[])(object)new Material[2] { material, material };
				right = AddSide(root, "Right", mesh, materials, 1f);
				left = AddSide(root, "Left", mesh, materials, -1f);
			}
			catch
			{
				Object.Destroy((Object)(object)val);
				throw;
			}
		}

		internal static Material CreateMaterial(out int colorProperty)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			string[] array = ((!((Object)(object)GraphicsSettings.currentRenderPipeline != (Object)null)) ? new string[3] { "Unlit/Color", "Sprites/Default", "Universal Render Pipeline/Unlit" } : new string[3] { "Universal Render Pipeline/Unlit", "Unlit/Color", "Sprites/Default" });
			foreach (string text in array)
			{
				Shader val = Shader.Find(text);
				if (Object.op_Implicit((Object)(object)val) && val.isSupported)
				{
					Material val2 = new Material(val)
					{
						name = "Murphys Wings Unlit"
					};
					colorProperty = Shader.PropertyToID((text == "Universal Render Pipeline/Unlit") ? "_BaseColor" : "_Color");
					if (val2.HasProperty(colorProperty))
					{
						return val2;
					}
					Object.Destroy((Object)(object)val2);
				}
			}
			colorProperty = 0;
			return null;
		}

		internal bool IsAttachedTo(PlayerAvatarVisuals model)
		{
			if (Object.op_Implicit((Object)(object)model) && Object.op_Implicit((Object)(object)root))
			{
				return (Object)(object)model == (Object)(object)body;
			}
			return false;
		}

		internal void Show(WingPalette palette, Color customColor, float size, bool replaceNative, double clock, Camera camera)
		{
			//IL_011e: 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_0178: 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_018f: 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_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			if ((!Object.op_Implicit((Object)(object)native) || !Object.op_Implicit((Object)(object)stockRoot)) && Time.unscaledTime >= nextNativeLookup)
			{
				nextNativeLookup = Time.unscaledTime + 1f;
				RestoreNative();
				native = avatar.upgradeTumbleWingsLogic;
				if (!Object.op_Implicit((Object)(object)native))
				{
					native = ((Component)avatar).GetComponentInChildren<ItemUpgradePlayerTumbleWingsLogic>(true);
				}
				nativeLeft = ((Object.op_Implicit((Object)(object)native) && Object.op_Implicit((Object)(object)native.transformWingLeft)) ? ((Component)native.transformWingLeft).GetComponentInChildren<MeshRenderer>(true) : null);
				nativeRight = ((Object.op_Implicit((Object)(object)native) && Object.op_Implicit((Object)(object)native.transformWingRight)) ? ((Component)native.transformWingRight).GetComponentInChildren<MeshRenderer>(true) : null);
				RefreshStockShape();
			}
			if (Object.op_Implicit((Object)(object)native) && Object.op_Implicit((Object)(object)native.transformWings))
			{
				Transform transformWings = native.transformWings;
				root.SetPositionAndRotation(transformWings.position, transformWings.rotation);
			}
			else
			{
				Transform val = (Object.op_Implicit((Object)(object)body.meshParent) ? body.meshParent.transform : ((Component)body).transform);
				root.SetPositionAndRotation(val.TransformPoint(0f, 0.52f, -0.25f), val.rotation);
			}
			root.localScale = Vector3.one * size;
			((Component)root).gameObject.SetActive(true);
			if (replaceNative)
			{
				HideNative();
			}
			else
			{
				RestoreNative();
			}
			(Color, Color) tuple = WingColors.Resolve(palette, customColor, clock);
			int num = (Object.op_Implicit((Object)(object)nativeLeft) ? ((Component)nativeLeft).gameObject.layer : ((Component)body).gameObject.layer);
			if (Object.op_Implicit((Object)(object)camera) && (camera.cullingMask & (1 << num)) == 0 && (camera.cullingMask & 1) != 0)
			{
				num = 0;
			}
			if (Object.op_Implicit((Object)(object)stockRoot))
			{
				float num2 = 34f - 54f * (float)Math.Sin(clock * 40.0);
				stockRightPivot.localRotation = Quaternion.Euler(0f, num2, 0f);
				stockLeftPivot.localRotation = Quaternion.Euler(0f, 0f - num2, 0f);
				PaintStock(stockRight, tuple.Item1, num);
				PaintStock(stockLeft, tuple.Item2, num);
			}
			else
			{
				float num3 = (float)Math.Sin(clock * Math.PI * 2.0 * 1.12);
				((Component)right).transform.localRotation = Quaternion.Euler(0f, 18f + 14f * num3, 3f * num3);
				((Component)left).transform.localRotation = Quaternion.Euler(0f, -18f - 14f * num3, -3f * num3);
				Paint(right, tuple.Item1, num);
				Paint(left, tuple.Item2, num);
			}
		}

		private void RefreshStockShape()
		{
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Expected O, but got Unknown
			if (Object.op_Implicit((Object)(object)stockRoot))
			{
				((Component)stockRoot).gameObject.SetActive(false);
				Object.Destroy((Object)(object)((Component)stockRoot).gameObject);
				stockRoot = null;
			}
			((Renderer)right).enabled = true;
			((Renderer)left).enabled = true;
			if (!Object.op_Implicit((Object)(object)native) || !Object.op_Implicit((Object)(object)native.transformWings) || !Object.op_Implicit((Object)(object)nativeLeft) || !Object.op_Implicit((Object)(object)nativeRight))
			{
				return;
			}
			Transform transformWings = native.transformWings;
			if ((Object)(object)native.transformWingLeft == (Object)(object)transformWings || (Object)(object)native.transformWingRight == (Object)(object)transformWings || !native.transformWingLeft.IsChildOf(transformWings) || !native.transformWingRight.IsChildOf(transformWings) || !TryReadStockMesh(nativeLeft, out var mesh, out var materials) || !TryReadStockMesh(nativeRight, out var mesh2, out var materials2))
			{
				return;
			}
			GameObject val = new GameObject("Stock wing meshes");
			val.SetActive(false);
			val.transform.SetParent(root, false);
			try
			{
				stockLeft = CopyStockSide(((Component)nativeLeft).transform, native.transformWingLeft, transformWings, val.transform, mesh, materials, out stockLeftPivot);
				stockRight = CopyStockSide(((Component)nativeRight).transform, native.transformWingRight, transformWings, val.transform, mesh2, materials2, out stockRightPivot);
				stockRoot = val.transform;
				((Renderer)right).enabled = false;
				((Renderer)left).enabled = false;
				val.SetActive(true);
			}
			catch
			{
				Object.Destroy((Object)(object)val);
				throw;
			}
		}

		private static bool TryReadStockMesh(MeshRenderer renderer, out Mesh mesh, out Material[] materials)
		{
			MeshFilter component = ((Component)renderer).GetComponent<MeshFilter>();
			mesh = (Object.op_Implicit((Object)(object)component) ? component.sharedMesh : null);
			materials = ((Renderer)renderer).sharedMaterials;
			if (Object.op_Implicit((Object)(object)mesh) && materials.Length != 0)
			{
				return Array.TrueForAll(materials, (Material material) => Object.op_Implicit((Object)(object)material) && Object.op_Implicit((Object)(object)material.shader) && material.shader.isSupported && material.HasProperty(NativeBaseColor) && material.HasProperty(NativeRimColor));
			}
			return false;
		}

		private static MeshRenderer CopyStockSide(Transform source, Transform pivot, Transform sourceRoot, Transform destination, Mesh mesh, Material[] materials, out Transform copiedPivot)
		{
			//IL_0034: 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_0055: 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)
			Stack<Transform> stack = new Stack<Transform>();
			Transform val = source;
			while ((Object)(object)val != (Object)(object)sourceRoot)
			{
				stack.Push(val);
				val = val.parent;
			}
			copiedPivot = null;
			while (stack.Count > 0)
			{
				Transform val2 = stack.Pop();
				Transform transform = new GameObject(((Object)val2).name).transform;
				transform.SetParent(destination, false);
				transform.localPosition = val2.localPosition;
				transform.localRotation = val2.localRotation;
				transform.localScale = val2.localScale;
				if ((Object)(object)val2 == (Object)(object)pivot)
				{
					copiedPivot = transform;
				}
				destination = transform;
			}
			((Component)destination).gameObject.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer obj = ((Component)destination).gameObject.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterials = materials;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			return obj;
		}

		private void PaintStock(MeshRenderer renderer, Color color, int layer)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			((Component)renderer).gameObject.layer = layer;
			block.Clear();
			block.SetColor(NativeBaseColor, Color.Lerp(Color.black, color, 0.55f));
			block.SetColor(NativeRimColor, color);
			((Renderer)renderer).SetPropertyBlock(block);
		}

		internal void Hide()
		{
			if (Object.op_Implicit((Object)(object)root) && ((Component)root).gameObject.activeSelf)
			{
				((Component)root).gameObject.SetActive(false);
			}
			RestoreNative();
		}

		internal void Dispose()
		{
			Hide();
			if (Object.op_Implicit((Object)(object)root))
			{
				Object.Destroy((Object)(object)((Component)root).gameObject);
			}
		}

		private void HideNative()
		{
			if (!hidingNative && (Object.op_Implicit((Object)(object)nativeLeft) || Object.op_Implicit((Object)(object)nativeRight)))
			{
				if (Object.op_Implicit((Object)(object)nativeLeft))
				{
					nativeLeftWasHidden = ((Renderer)nativeLeft).forceRenderingOff;
					((Renderer)nativeLeft).forceRenderingOff = true;
				}
				if (Object.op_Implicit((Object)(object)nativeRight))
				{
					nativeRightWasHidden = ((Renderer)nativeRight).forceRenderingOff;
					((Renderer)nativeRight).forceRenderingOff = true;
				}
				hidingNative = true;
			}
		}

		private void RestoreNative()
		{
			if (hidingNative)
			{
				if (Object.op_Implicit((Object)(object)nativeLeft))
				{
					((Renderer)nativeLeft).forceRenderingOff = nativeLeftWasHidden;
				}
				if (Object.op_Implicit((Object)(object)nativeRight))
				{
					((Renderer)nativeRight).forceRenderingOff = nativeRightWasHidden;
				}
				hidingNative = false;
			}
		}

		private static MeshRenderer AddSide(Transform parent, string name, Mesh mesh, Material[] materials, float sign)
		{
			//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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_0058: 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)
			GameObject val = new GameObject(name)
			{
				layer = ((Component)parent).gameObject.layer
			};
			val.transform.SetParent(parent, false);
			val.transform.localPosition = new Vector3(sign * 0.12f, 0f, 0f);
			val.transform.localScale = new Vector3(sign, 1f, 1f);
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			MeshRenderer obj = val.AddComponent<MeshRenderer>();
			((Renderer)obj).sharedMaterials = materials;
			((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)obj).receiveShadows = false;
			return obj;
		}

		private void Paint(MeshRenderer renderer, Color color, int layer)
		{
			//IL_0039: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			((Component)renderer).gameObject.layer = layer;
			((Renderer)renderer).shadowCastingMode = (ShadowCastingMode)0;
			block.Clear();
			block.SetColor(colorProperty, Color.Lerp(new Color(0.035f, 0.035f, 0.055f), color, 0.28f));
			((Renderer)renderer).SetPropertyBlock(block, 0);
			block.SetColor(colorProperty, Color.Lerp(color, Color.white, 0.21f));
			((Renderer)renderer).SetPropertyBlock(block, 1);
		}

		internal static Mesh BuildMesh()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_008e: 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_00c3: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: 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_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Expected O, but got Unknown
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = new List<Vector3>();
			List<int> list2 = new List<int>();
			List<int> list3 = new List<int>();
			AddBlade(list, list2, list3, new Vector3(0.02f, 0.03f, 0f), new Vector3(1.12f, 0.63f, -0.12f), 0.17f);
			AddBlade(list, list2, list3, new Vector3(0.08f, -0.03f, -0.03f), new Vector3(1.07f, 0.27f, -0.22f), 0.15f);
			AddBlade(list, list2, list3, new Vector3(0.1f, -0.09f, -0.045f), new Vector3(0.98f, -0.01f, -0.3f), 0.14f);
			AddBlade(list, list2, list3, new Vector3(0.07f, -0.15f, -0.055f), new Vector3(0.81f, -0.26f, -0.34f), 0.13f);
			AddBlade(list, list2, list3, new Vector3(0.03f, -0.19f, -0.07f), new Vector3(0.61f, -0.44f, -0.34f), 0.12f);
			AddBlade(list, list2, list3, new Vector3(0.01f, -0.23f, -0.075f), new Vector3(0.39f, -0.52f, -0.3f), 0.105f);
			Mesh val = new Mesh
			{
				name = "Murphys Wings blade"
			};
			val.SetVertices(list);
			Color32[] array = (Color32[])(object)new Color32[list.Count];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue);
			}
			val.colors32 = array;
			val.uv = (Vector2[])(object)new Vector2[list.Count];
			val.subMeshCount = 2;
			val.SetTriangles(list2, 0);
			val.SetTriangles(list3, 1);
			val.RecalculateBounds();
			return val;
		}

		private static void AddBlade(List<Vector3> vertices, List<int> metal, List<int> trim, Vector3 start, Vector3 tip, float width)
		{
			//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_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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_0020: 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_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_0031: 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_0039: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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)
			//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_006d: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_008e: 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_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_00aa: 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_00ac: 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_00b8: 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_00c3: 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_00cd: 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_00cf: 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_00da: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: 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_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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: 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_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_0123: 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_0126: 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)
			//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_013e: 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_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = tip - start;
			Vector3 val2 = new Vector3(0f - val.y, val.x, 0f);
			Vector3 val3 = ((Vector3)(ref val2)).normalized * width;
			Vector3 val4 = Vector3.Lerp(start, tip, 0.42f) + val3 * 0.54f;
			Vector3 val5 = Vector3.Lerp(start, tip, 0.29f) - val3 * 0.46f;
			Vector3 val6 = Vector3.Lerp(start, tip, 0.41f) + Vector3.forward * 0.029f;
			Vector3 c = val6 - Vector3.forward * 0.058f;
			Triangle(vertices, metal, start, val5, val6);
			Triangle(vertices, metal, val5, tip, val6);
			Triangle(vertices, metal, tip, val4, val6);
			Triangle(vertices, metal, val4, start, val6);
			Triangle(vertices, metal, start, val4, c);
			Triangle(vertices, metal, val4, tip, c);
			Triangle(vertices, metal, tip, val5, c);
			Triangle(vertices, metal, val5, start, c);
			Vector3 a = Vector3.Lerp(start, val4, 0.5f);
			Vector3 b = Vector3.Lerp(val4, tip, 0.84f);
			Triangle(vertices, trim, a, val4, val4 - val3 * 0.11f);
			Triangle(vertices, trim, val4, b, val4 - val3 * 0.11f);
		}

		private static void Triangle(List<Vector3> vertices, List<int> faces, Vector3 a, Vector3 b, Vector3 c)
		{
			//IL_0008: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			int count = vertices.Count;
			vertices.Add(a);
			vertices.Add(b);
			vertices.Add(c);
			faces.Add(count);
			faces.Add(count + 1);
			faces.Add(count + 2);
			faces.Add(count);
			faces.Add(count + 2);
			faces.Add(count + 1);
		}
	}
}