Decompiled source of CDEV BeRightBack v0.1.0

plugins/CDEV.BeRightBack/CDEV.BeRightBack.dll

Decompiled 5 days 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.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GUIFramework;
using HarmonyLib;
using MagicaCloth2;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.TextCore.LowLevel;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: IgnoresAccessChecksTo("gui_framework")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("CDEV.BeRightBack")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+efb24945142928ac03192750576c1d4fe797e026")]
[assembly: AssemblyProduct("CDEV.BeRightBack")]
[assembly: AssemblyTitle("CDEV.BeRightBack")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CDEV.BeRightBack
{
	[HarmonyPatch]
	internal sealed class BrbScreen : MonoBehaviour
	{
		private const float FadeIn = 0.5f;

		private const float FlyIn = 1.4f;

		private const float GestureSeconds = 4f;

		private const float SwayPeriod = 40f;

		private const float AnimatorSettle = 1.5f;

		private static BrbScreen _instance;

		private bool _open;

		private Player _player;

		private Preset _preset;

		private readonly PauseMotion _motion = new PauseMotion();

		private float _motionRestoreAt = -1f;

		private bool _hudWasHidden;

		private int _openedFrame;

		private float _openedAt;

		private DateTime _openedTime;

		private float _yaw;

		private Vector3 _camFromPos;

		private Quaternion _camFromRot;

		private bool _camFromSet;

		private string _lastEmote;

		private int _nextIndex;

		private float _nextEmoteAt;

		private Overlay _overlay;

		private readonly SceneLight _light = new SceneLight();

		private static readonly HashSet<GameObject> _hiddenTexts = new HashSet<GameObject>();

		internal static bool IsOpen
		{
			get
			{
				if ((Object)(object)_instance != (Object)null)
				{
					return _instance._open;
				}
				return false;
			}
		}

		internal static bool CanOpen()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null && (Object)(object)Menu.instance != (Object)null && !((Character)localPlayer).IsDead() && !((Character)localPlayer).InCutscene())
			{
				return !IsOpen;
			}
			return false;
		}

		internal static void Open(Preset preset)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			try
			{
				if (CanOpen() && preset != null)
				{
					if ((Object)(object)_instance == (Object)null)
					{
						GameObject val = new GameObject("CDEV_BeRightBack");
						Object.DontDestroyOnLoad((Object)(object)val);
						_instance = val.AddComponent<BrbScreen>();
					}
					_instance.Begin(Player.m_localPlayer, preset);
				}
			}
			catch (Exception ex)
			{
				BeRightBackPlugin.Log.LogError((object)("Be right back screen not opened: " + ex));
				Close(immediate: true);
			}
		}

		internal static void Close(bool immediate)
		{
			if (!((Object)(object)_instance == (Object)null))
			{
				try
				{
					_instance.End(immediate);
				}
				catch (Exception ex)
				{
					BeRightBackPlugin.Log.LogError((object)("Be right back screen not closed cleanly: " + ex));
				}
				if (immediate)
				{
					Object.Destroy((Object)(object)((Component)_instance).gameObject);
					_instance = null;
				}
			}
		}

		private void Begin(Player player, Preset preset)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			_player = player;
			_preset = preset;
			_open = true;
			_openedFrame = Time.frameCount;
			_openedAt = Time.unscaledTime;
			_openedTime = DateTime.Now;
			Stage.Hold(player, ((Object)(object)GameCamera.instance != (Object)null) ? LayerMask.op_Implicit(GameCamera.instance.m_blockCameraMask) : (-1));
			_yaw = Stage.Yaw;
			_camFromSet = false;
			_lastEmote = null;
			_nextIndex = 0;
			_nextEmoteAt = 0f;
			MenuHold.Hold();
			Hud instance = Hud.instance;
			if ((Object)(object)instance != (Object)null)
			{
				_hudWasHidden = instance.m_userHidden;
				instance.m_userHidden = true;
				instance.SetVisible(false);
			}
			_motionRestoreAt = -1f;
			_motion.Begin(player);
			_overlay?.Destroy();
			_overlay = new Overlay(preset, ModConfig.CinemaBars.Value, Game.IsPaused() ? Texts.Hint : (Texts.Hint + "\n" + Texts.Server));
			UpdateOverlay();
		}

		private void End(bool immediate)
		{
			if (!_open)
			{
				if (immediate)
				{
					RestoreMotion();
				}
				return;
			}
			_open = false;
			if ((Object)(object)_player != (Object)null)
			{
				((Character)_player).StopEmote();
				_player.UpdateEmote();
			}
			Props.Mug(_player, on: false);
			Hud instance = Hud.instance;
			if ((Object)(object)instance != (Object)null)
			{
				instance.m_userHidden = _hudWasHidden;
				instance.SetVisible(!_hudWasHidden);
			}
			MenuHold.Release();
			Stage.Release();
			_overlay?.Destroy();
			_overlay = null;
			_light.Destroy();
			ShowChatTexts();
			if (immediate)
			{
				RestoreMotion();
			}
			else
			{
				_motionRestoreAt = Time.unscaledTime + 1.5f;
			}
		}

		private void RestoreMotion()
		{
			_motion.Restore();
			_motionRestoreAt = -1f;
		}

		private void OnDestroy()
		{
			_light.Destroy();
			RestoreMotion();
			_overlay?.Destroy();
			_overlay = null;
		}

		private void Update()
		{
			if (_motionRestoreAt > 0f && Time.unscaledTime >= _motionRestoreAt)
			{
				RestoreMotion();
			}
			if (!_open)
			{
				return;
			}
			if ((Object)(object)_player == (Object)null || (Object)(object)Menu.instance == (Object)null || (Object)(object)Player.m_localPlayer != (Object)(object)_player || ((Character)_player).IsDead())
			{
				End(immediate: true);
				return;
			}
			if (Time.frameCount > _openedFrame && (ZInput.GetKeyDown((KeyCode)27, true) || ZInput.GetButtonDown("JoyButtonB") || ZInput.GetButtonDown("JoyMenu")))
			{
				End(immediate: false);
				return;
			}
			Hud instance = Hud.instance;
			if ((Object)(object)instance != (Object)null && !instance.m_userHidden)
			{
				instance.m_userHidden = true;
			}
			if (Time.unscaledTime >= _nextEmoteAt)
			{
				NextEmote();
			}
			UpdateOverlay();
		}

		private void NextEmote()
		{
			List<string> list = new List<string>(_preset.emotes);
			if (list.Count == 0)
			{
				_nextEmoteAt = float.MaxValue;
				return;
			}
			string text;
			if (_preset.shuffle)
			{
				if (list.Count > 1)
				{
					list.Remove(_lastEmote);
				}
				text = list[Random.Range(0, list.Count)];
			}
			else
			{
				text = list[_nextIndex % list.Count];
				_nextIndex = (_nextIndex + 1) % list.Count;
			}
			Props.Mug(_player, on: false);
			if (_player.StartEmote(text, Emotes.OneShot(text)))
			{
				if (text == "toast")
				{
					Props.Mug(_player, on: true);
				}
				_player.UpdateEmote();
				_lastEmote = text;
				float value = ModConfig.DanceSecondsMin.Value;
				float num = Mathf.Max(value, ModConfig.DanceSecondsMax.Value);
				_nextEmoteAt = Time.unscaledTime + (Emotes.IsLoop(text) ? Random.Range(value, num) : 4f);
			}
			else
			{
				_nextEmoteAt = Time.unscaledTime + 2f;
			}
		}

		[HarmonyPatch(typeof(GameCamera), "LateUpdate")]
		[HarmonyPostfix]
		private static void GameCamera_LateUpdate_Postfix(GameCamera __instance)
		{
			if (!IsOpen)
			{
				return;
			}
			try
			{
				_instance.PlaceCamera(__instance);
			}
			catch (Exception ex)
			{
				BeRightBackPlugin.Log.LogError((object)("Be right back camera failed: " + ex));
				Close(immediate: false);
			}
		}

		private void PlaceCamera(GameCamera camera)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Transform transform = ((Component)camera).transform;
			if (!_camFromSet)
			{
				_camFromPos = transform.position;
				_camFromRot = transform.rotation;
				_camFromSet = true;
			}
			float num = Time.unscaledTime - _openedAt;
			float yaw = _yaw + ModConfig.CameraSway.Value * Mathf.Sin(num * 2f * (float)Math.PI / 40f);
			Pose(_player, _preset, yaw, LayerMask.op_Implicit(camera.m_blockCameraMask), out var pos, out var rot);
			float num2 = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(num / 1.4f));
			transform.position = Vector3.Lerp(_camFromPos, pos, num2);
			transform.rotation = Quaternion.Slerp(_camFromRot, rot, num2);
			Stage.LookTarget = pos;
			_light.Update(_preset.light, _player, transform.position);
			ZCursor.Hide();
		}

		internal static void Pose(Player player, Preset preset, float yaw, int blockMask, out Vector3 pos, out Quaternion rot)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0070: 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_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: 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_00df: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)player).transform.position + Vector3.up * 1.1f;
			Vector3 val2 = Quaternion.Euler(-10f, yaw, 0f) * Vector3.forward;
			float value = ModConfig.CameraDistance.Value;
			float num = Stage.CameraRoom(val, val2, value, blockMask);
			float num2 = ((num < value) ? Mathf.Max(0.8f, num - 0.1f) : value);
			pos = val + val2 * num2;
			float num3 = ((preset.Row == 2) ? 0.45f : ((preset.Row == 0) ? (-0.15f) : 0.1f));
			float num4 = ((preset.Column == 0) ? (-0.75f) : ((preset.Column == 2) ? 0.75f : 0f));
			Vector3 val3 = Vector3.Cross(Vector3.up, -val2);
			Vector3 normalized = ((Vector3)(ref val3)).normalized;
			rot = Quaternion.LookRotation(val - Vector3.up * num3 + normalized * num4 - pos);
		}

		[HarmonyPatch(typeof(Chat), "LateUpdate")]
		[HarmonyPostfix]
		private static void Chat_LateUpdate_Postfix(Chat __instance)
		{
			if (!IsOpen)
			{
				return;
			}
			try
			{
				foreach (WorldTextInstance worldText in __instance.m_worldTexts)
				{
					Hide(worldText.m_gui);
				}
				foreach (NpcText npcText in __instance.m_npcTexts)
				{
					Hide(npcText.m_gui);
				}
				if ((Object)(object)((Terminal)__instance).m_chatWindow != (Object)null)
				{
					Hide(((Component)((Terminal)__instance).m_chatWindow).gameObject);
				}
			}
			catch (Exception ex)
			{
				BeRightBackPlugin.Log.LogWarning((object)("Chat texts not hidden: " + ex.Message));
			}
		}

		private static void Hide(GameObject go)
		{
			if (!((Object)(object)go == (Object)null) && go.activeSelf)
			{
				go.SetActive(false);
				_hiddenTexts.Add(go);
			}
		}

		private static void ShowChatTexts()
		{
			foreach (GameObject hiddenText in _hiddenTexts)
			{
				if ((Object)(object)hiddenText != (Object)null)
				{
					hiddenText.SetActive(true);
				}
			}
			_hiddenTexts.Clear();
		}

		private void UpdateOverlay()
		{
			if (_overlay != null)
			{
				TimeSpan timeSpan = DateTime.Now - _openedTime;
				string time = ((timeSpan.TotalHours >= 1.0) ? $"{(int)timeSpan.TotalHours}:{timeSpan.Minutes:00}:{timeSpan.Seconds:00}" : $"{timeSpan.Minutes:00}:{timeSpan.Seconds:00}");
				_overlay.Update(Time.unscaledTime - _openedAt, Texts.Away(time));
			}
		}
	}
	internal static class Launcher
	{
		internal static void OnEntry()
		{
			if (BrbScreen.CanOpen() && !PresetWindow.IsOpen)
			{
				PresetWindow.Show();
			}
		}

		internal static void Shutdown()
		{
			PresetWindow.CloseNow();
			UiKit.Dispose();
		}
	}
	[HarmonyPatch]
	internal static class MenuEntry
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__OnEntry;
		}

		private const string EntryName = "CDEV_BeRightBack";

		private static Button _entry;

		private static TMP_Text _label;

		internal static Button Button => _entry;

		[HarmonyPatch(typeof(Menu), "Start")]
		[HarmonyPostfix]
		private static void Menu_Start_Postfix(Menu __instance)
		{
			Add(__instance);
		}

		internal static void Add(Menu menu)
		{
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			//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_0136: Expected O, but got Unknown
			try
			{
				if (!((Object)(object)menu == (Object)null) && !((Object)(object)menu.menuEntriesParent == (Object)null) && !((Object)(object)menu.m_settingsButton == (Object)null) && (!((Object)(object)_entry != (Object)null) || !((Object)(object)((Component)_entry).transform.parent == (Object)(object)menu.menuEntriesParent)))
				{
					Button settingsButton = menu.m_settingsButton;
					GameObject val = Object.Instantiate<GameObject>(((Component)settingsButton).gameObject, ((Component)settingsButton).transform.parent, false);
					((Object)val).name = "CDEV_BeRightBack";
					Transform val2 = (((Object)(object)menu.m_continueButton != (Object)null && (Object)(object)((Component)menu.m_continueButton).transform.parent == (Object)(object)((Component)settingsButton).transform.parent) ? ((Component)menu.m_continueButton).transform : ((Component)settingsButton).transform);
					val.transform.SetSiblingIndex(val2.GetSiblingIndex() + 1);
					Localize[] componentsInChildren = val.GetComponentsInChildren<Localize>(true);
					foreach (Localize val3 in componentsInChildren)
					{
						Object.DestroyImmediate((Object)(object)val3);
					}
					Button component = val.GetComponent<Button>();
					component.onClick = new ButtonClickedEvent();
					ButtonClickedEvent onClick = component.onClick;
					object obj = <>O.<0>__OnEntry;
					if (obj == null)
					{
						UnityAction val4 = Launcher.OnEntry;
						<>O.<0>__OnEntry = val4;
						obj = (object)val4;
					}
					((UnityEvent)onClick).AddListener((UnityAction)obj);
					_entry = component;
					_label = val.GetComponentInChildren<TMP_Text>(true);
					Relabel();
					menu.m_rebuildLayout = true;
				}
			}
			catch (Exception ex)
			{
				BeRightBackPlugin.Log.LogError((object)("Pause menu entry not added: " + ex));
			}
		}

		internal static void Remove()
		{
			if (!((Object)(object)_entry == (Object)null))
			{
				GameObject gameObject = ((Component)_entry).gameObject;
				gameObject.SetActive(false);
				((Object)gameObject).name = "CDEV_Unloaded";
				Object.Destroy((Object)(object)gameObject);
				_entry = null;
				_label = null;
				if ((Object)(object)Menu.instance != (Object)null)
				{
					Menu.instance.m_rebuildLayout = true;
				}
			}
		}

		[HarmonyPatch(typeof(Menu), "Show")]
		[HarmonyPostfix]
		private static void Menu_Show_Postfix()
		{
			Relabel();
		}

		private static void Relabel()
		{
			if (!((Object)(object)_label == (Object)null))
			{
				string entry = Texts.Entry;
				if (_label.text != entry)
				{
					_label.text = entry;
				}
			}
		}

		[HarmonyPatch(typeof(Menu), "UpdateNavigation")]
		[HarmonyPostfix]
		private static void Menu_UpdateNavigation_Postfix(Menu __instance)
		{
			//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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Invalid comparison between Unknown and I4
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Button continueButton = __instance.m_continueButton;
				if ((Object)(object)_entry == (Object)null || (Object)(object)continueButton == (Object)null || !((Component)_entry).gameObject.activeSelf)
				{
					return;
				}
				Navigation navigation = ((Selectable)continueButton).navigation;
				if ((int)((Navigation)(ref navigation)).mode != 4)
				{
					return;
				}
				Selectable selectOnDown = ((Navigation)(ref navigation)).selectOnDown;
				if (!((Object)(object)selectOnDown == (Object)(object)_entry))
				{
					Button entry = _entry;
					Navigation navigation2 = default(Navigation);
					((Navigation)(ref navigation2)).mode = (Mode)4;
					((Navigation)(ref navigation2)).selectOnUp = (Selectable)(object)continueButton;
					((Navigation)(ref navigation2)).selectOnDown = selectOnDown;
					((Selectable)entry).navigation = navigation2;
					((Navigation)(ref navigation)).selectOnDown = (Selectable)(object)_entry;
					((Selectable)continueButton).navigation = navigation;
					if ((Object)(object)selectOnDown != (Object)null)
					{
						Navigation navigation3 = selectOnDown.navigation;
						((Navigation)(ref navigation3)).selectOnUp = (Selectable)(object)_entry;
						selectOnDown.navigation = navigation3;
					}
				}
			}
			catch (Exception ex)
			{
				BeRightBackPlugin.Log.LogWarning((object)("Pause menu navigation not linked: " + ex.Message));
			}
		}
	}
	[HarmonyPatch]
	internal static class MenuHold
	{
		private static int _holds;

		internal static bool Active => _holds > 0;

		internal static void Hold()
		{
			if (_holds++ == 0 && (Object)(object)Menu.instance != (Object)null)
			{
				((Component)Menu.instance.m_root).gameObject.SetActive(false);
			}
		}

		internal static void Release()
		{
			if (_holds == 0 || --_holds > 0)
			{
				return;
			}
			Menu instance = Menu.instance;
			if (!((Object)(object)instance == (Object)null))
			{
				instance.m_shownFrames = 0;
				((Component)instance.m_root).gameObject.SetActive(true);
				ShowCursor();
				Button button = MenuEntry.Button;
				if ((Object)(object)button != (Object)null && ZInput.IsGamepadActive() && (Object)(object)EventSystem.current != (Object)null)
				{
					EventSystem.current.SetSelectedGameObject(((Component)button).gameObject);
				}
			}
		}

		internal static void ShowCursor()
		{
			ZCursor.LockState = (CursorLockMode)(!ZInput.IsMouseActive());
			ZCursor.Show();
		}

		internal static void ReleaseAll()
		{
			if (_holds != 0)
			{
				_holds = 1;
				Release();
			}
		}

		[HarmonyPatch(typeof(Menu), "Update")]
		[HarmonyPrefix]
		private static bool Menu_Update_Prefix()
		{
			return !Active;
		}

		[HarmonyPatch(typeof(Menu), "IsActive")]
		[HarmonyPostfix]
		private static void Menu_IsActive_Postfix(ref bool __result)
		{
			if (Active)
			{
				__result = true;
			}
		}

		[HarmonyPatch(typeof(Menu), "OnDestroy")]
		[HarmonyPostfix]
		private static void Menu_OnDestroy_Postfix()
		{
			_holds = 0;
		}
	}
	internal static class ModConfig
	{
		internal static ConfigEntry<bool> CinemaBars;

		internal static ConfigEntry<float> DanceSecondsMin;

		internal static ConfigEntry<float> DanceSecondsMax;

		internal static ConfigEntry<float> CameraDistance;

		internal static ConfigEntry<float> CameraSway;

		internal static void Bind(ConfigFile config)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			CinemaBars = config.Bind<bool>("Screen", "CinemaBars", true, "Dark shading at the top and bottom of the screen.");
			DanceSecondsMin = config.Bind<float>("Dances", "DanceSecondsMin", 8f, new ConfigDescription("Shortest time one dance or pose lasts, in seconds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 120f), Array.Empty<object>()));
			DanceSecondsMax = config.Bind<float>("Dances", "DanceSecondsMax", 15f, new ConfigDescription("Longest time one dance or pose lasts, in seconds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 120f), Array.Empty<object>()));
			CameraDistance = config.Bind<float>("Camera", "Distance", 3f, new ConfigDescription("Distance from the camera to the character, in metres.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1.5f, 10f), Array.Empty<object>()));
			CameraSway = config.Bind<float>("Camera", "Sway", 35f, new ConfigDescription("How far the camera swings to each side of the character, in degrees. 0 = still.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 180f), Array.Empty<object>()));
		}
	}
	internal sealed class Overlay
	{
		private const float HintSeconds = 6f;

		private const float LineWidth = 250f;

		private static readonly Color Gold = new Color(0.93f, 0.76f, 0.45f);

		private readonly GameObject _root;

		private Transform _parent;

		private readonly CanvasGroup _group;

		private readonly RectTransform _title;

		private readonly TMP_Text _titleText;

		private readonly float _titleY;

		private readonly TMP_Text _timer;

		private readonly TMP_Text _hint;

		private readonly RectTransform _lineLeft;

		private readonly RectTransform _lineRight;

		private readonly RectTransform _diamond;

		private readonly Material _titleMaterial;

		private readonly Material _smallMaterial;

		private readonly Texture2D _vertical;

		private readonly Texture2D _horizontal;

		private string _timerShown;

		internal RectTransform Root
		{
			get
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Expected O, but got Unknown
				if (!((Object)(object)_root != (Object)null))
				{
					return null;
				}
				return (RectTransform)_root.transform;
			}
		}

		internal Overlay(Preset preset, bool shades, string hint, RectTransform host = null)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			//IL_00f4: 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_00fd: 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_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: 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_013f: 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_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Expected O, but got Unknown
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Expected O, but got Unknown
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: 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_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0442: Unknown result type (might be due to invalid IL or missing references)
			//IL_0456: Unknown result type (might be due to invalid IL or missing references)
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_047e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0483: Unknown result type (might be due to invalid IL or missing references)
			//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0524: Unknown result type (might be due to invalid IL or missing references)
			//IL_0533: Unknown result type (might be due to invalid IL or missing references)
			//IL_053f: Unknown result type (might be due to invalid IL or missing references)
			//IL_054e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0572: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_065e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0663: Unknown result type (might be due to invalid IL or missing references)
			//IL_0685: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d0: Unknown result type (might be due to invalid IL or missing references)
			int row = preset.Row;
			int column = preset.Column;
			bool timer = preset.timer;
			_root = new GameObject(((Object)(object)host == (Object)null) ? "CDEV_BeRightBack_Screen" : "Preview", new Type[1] { typeof(RectTransform) });
			Vector2 val4 = default(Vector2);
			if ((Object)(object)host == (Object)null)
			{
				Object.DontDestroyOnLoad((Object)(object)_root);
				Canvas val = _root.AddComponent<Canvas>();
				val.renderMode = (RenderMode)0;
				val.sortingOrder = 10000;
				CanvasScaler val2 = _root.AddComponent<CanvasScaler>();
				val2.uiScaleMode = (ScaleMode)1;
				val2.referenceResolution = new Vector2(1920f, 1080f);
				val2.matchWidthOrHeight = 0.5f;
			}
			else
			{
				RectTransform val3 = (RectTransform)_root.transform;
				((Transform)val3).SetParent((Transform)(object)host, false);
				((Vector2)(ref val4))..ctor(0.5f, 0.5f);
				val3.pivot = val4;
				val3.anchorMin = (val3.anchorMax = val4);
				val3.sizeDelta = new Vector2(1920f, 1080f);
				Vector3 one = Vector3.one;
				Rect rect = host.rect;
				((Transform)val3).localScale = one * (((Rect)(ref rect)).height / 1080f);
			}
			_group = _root.AddComponent<CanvasGroup>();
			_group.alpha = 0f;
			_group.blocksRaycasts = false;
			_group.interactable = false;
			_vertical = Gradient(1, 128, (float x, float y) => Mathf.SmoothStep(0f, 1f, 1f - y));
			_horizontal = Gradient(128, 1, (float x, float y) => Mathf.SmoothStep(0f, 1f, x));
			_parent = _root.transform;
			if (shades)
			{
				Shade("Bottom", top: false, row switch
				{
					1 => 260f, 
					2 => 380f, 
					_ => 170f, 
				}, row switch
				{
					1 => 0.7f, 
					2 => 0.92f, 
					_ => 0.5f, 
				});
				Shade("Top", top: true, row switch
				{
					1 => 260f, 
					0 => 380f, 
					_ => 170f, 
				}, row switch
				{
					1 => 0.7f, 
					0 => 0.92f, 
					_ => 0.6f, 
				});
			}
			GameObject val6 = new GameObject("Block", new Type[1] { typeof(RectTransform) });
			val6.transform.SetParent(_root.transform, false);
			RectTransform val7 = (RectTransform)val6.transform;
			Vector2 val8 = default(Vector2);
			((Vector2)(ref val8))..ctor((float)column * 0.5f, 1f - (float)row * 0.5f);
			val4 = (val7.pivot = val8);
			val7.anchorMin = (val7.anchorMax = val4);
			val7.anchoredPosition = new Vector2(column switch
			{
				2 => -90f, 
				0 => 90f, 
				_ => 0f, 
			}, row switch
			{
				2 => 30f, 
				0 => -60f, 
				_ => 0f, 
			});
			((Transform)val7).localScale = Vector3.one * Mathf.Clamp(preset.size, 0.5f, 2f);
			_parent = (Transform)(object)val7;
			TMP_FontAsset val11 = Font("Valheim-AveriaSerifLibre");
			TMP_FontAsset font = Font("Valheim-AveriaSansLibre") ?? val11;
			_titleMaterial = Shadowed(val11, 0.9f, 0.6f);
			_smallMaterial = Shadowed(font, 0.8f, 0.5f);
			_titleY = (timer ? 122f : 82f);
			TMP_Text val12 = Text("Title", val11, _titleMaterial, 86f, Color.white, new Vector2(0.5f, 0f), new Vector2(0f, _titleY));
			val12.text = preset.Title;
			val12.fontStyle = (FontStyles)1;
			val12.characterSpacing = 3f;
			val12.enableVertexGradient = true;
			val12.colorGradient = new VertexGradient(new Color(1f, 0.95f, 0.8f), new Color(1f, 0.95f, 0.8f), new Color(0.9f, 0.68f, 0.36f), new Color(0.9f, 0.68f, 0.36f));
			_titleText = val12;
			_title = val12.rectTransform;
			float num = Mathf.Max(val12.GetPreferredValues(preset.Title).x + 20f, 540f);
			val7.sizeDelta = new Vector2(num, timer ? 180f : 140f);
			float num2 = (timer ? 64f : 24f);
			_lineLeft = Line("LineLeft", num2, left: true);
			_lineRight = Line("LineRight", num2, left: false);
			_diamond = Image("Diamond", null, Gold, new Vector2(0.5f, 0f), new Vector2(0f, num2), new Vector2(10f, 10f));
			((Transform)_diamond).localRotation = Quaternion.Euler(0f, 0f, 45f);
			_timer = Text("Timer", font, _smallMaterial, 27f, new Color(0.88f, 0.85f, 0.8f, 0.85f), new Vector2(0.5f, 0f), new Vector2(0f, 20f));
			_timer.characterSpacing = 2f;
			((Component)_timer).gameObject.SetActive(timer);
			_parent = _root.transform;
			bool flag = row == 0;
			bool flag2 = column == 2;
			Vector2 val13 = default(Vector2);
			((Vector2)(ref val13))..ctor(flag2 ? 0f : 1f, flag ? 0f : 1f);
			_hint = Text("Hint", font, _smallMaterial, 21f, new Color(1f, 1f, 1f, 0.75f), val13, new Vector2(flag2 ? 36f : (-36f), flag ? 34f : (-34f)));
			_hint.alignment = (TextAlignmentOptions)((!flag) ? (flag2 ? 257 : 260) : (flag2 ? 1025 : 1028));
			_hint.rectTransform.pivot = val13;
			_hint.text = hint ?? "";
			((Component)_hint).gameObject.SetActive(hint != null);
		}

		internal void Update(float t, string away)
		{
			//IL_0063: 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_00bd: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_root == (Object)null))
			{
				_group.alpha = Mathf.Clamp01(t / 0.6f);
				float num = EaseOut(Mathf.Clamp01(t / 0.9f));
				_titleText.alpha = num;
				_title.anchoredPosition = new Vector2(0f, _titleY - 18f * (1f - num));
				float num2 = 250f * EaseOut(Mathf.Clamp01((t - 0.3f) / 1.1f));
				_lineLeft.sizeDelta = new Vector2(num2, 2f);
				_lineRight.sizeDelta = new Vector2(num2, 2f);
				((Transform)_diamond).localScale = Vector3.one * EaseOut(Mathf.Clamp01((t - 0.2f) / 0.5f));
				if (((Component)_timer).gameObject.activeSelf && away != _timerShown)
				{
					_timerShown = away;
					_timer.text = away;
				}
				Color color = ((Graphic)_hint).color;
				color.a = 0.75f * Mathf.Clamp01((6f - t) / 1.5f);
				((Graphic)_hint).color = color;
			}
		}

		internal void Destroy()
		{
			if ((Object)(object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)_root);
			}
			if ((Object)(object)_titleMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)_titleMaterial);
			}
			if ((Object)(object)_smallMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)_smallMaterial);
			}
			if ((Object)(object)_vertical != (Object)null)
			{
				Object.Destroy((Object)(object)_vertical);
			}
			if ((Object)(object)_horizontal != (Object)null)
			{
				Object.Destroy((Object)(object)_horizontal);
			}
		}

		private static float EaseOut(float x)
		{
			return 1f - (1f - x) * (1f - x) * (1f - x);
		}

		private void Shade(string name, bool top, float height, float alpha)
		{
			//IL_0019: 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_0042: 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_0081: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = Image(name, _vertical, new Color(0f, 0f, 0f, alpha), new Vector2(0.5f, top ? 1f : 0f), Vector2.zero, new Vector2(0f, height));
			val.anchorMin = new Vector2(0f, top ? 1f : 0f);
			val.anchorMax = new Vector2(1f, top ? 1f : 0f);
			val.pivot = new Vector2(0.5f, top ? 1f : 0f);
			if (top)
			{
				((Component)val).GetComponent<RawImage>().uvRect = new Rect(0f, 1f, 1f, -1f);
			}
		}

		private RectTransform Line(string name, float y, bool left)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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)
			RectTransform val = Image(name, _horizontal, new Color(Gold.r, Gold.g, Gold.b, 0.75f), new Vector2(0.5f, 0f), new Vector2(left ? (-14f) : 14f, y), new Vector2(0f, 2f));
			val.pivot = new Vector2(left ? 1f : 0f, 0.5f);
			if (!left)
			{
				((Component)val).GetComponent<RawImage>().uvRect = new Rect(1f, 0f, -1f, 1f);
			}
			return val;
		}

		private RectTransform Image(string name, Texture2D texture, Color color, Vector2 anchor, Vector2 position, Vector2 size)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_005f: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(_parent, false);
			RectTransform val2 = (RectTransform)val.transform;
			Vector2 anchorMin = (val2.anchorMax = anchor);
			val2.anchorMin = anchorMin;
			val2.pivot = new Vector2(0.5f, 0.5f);
			val2.sizeDelta = size;
			val2.anchoredPosition = position;
			Graphic val5;
			if ((Object)(object)texture != (Object)null)
			{
				RawImage val4 = val.AddComponent<RawImage>();
				val4.texture = (Texture)(object)texture;
				val5 = (Graphic)(object)val4;
			}
			else
			{
				val5 = (Graphic)(object)val.AddComponent<Image>();
			}
			val5.color = color;
			val5.raycastTarget = false;
			return val2;
		}

		private TMP_Text Text(string name, TMP_FontAsset font, Material material, float size, Color color, Vector2 anchor, Vector2 position)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(_parent, false);
			RectTransform val2 = (RectTransform)val.transform;
			Vector2 anchorMin = (val2.anchorMax = anchor);
			val2.anchorMin = anchorMin;
			val2.pivot = new Vector2(anchor.x, 0.5f);
			val2.sizeDelta = new Vector2(1600f, size * 1.6f);
			val2.anchoredPosition = position;
			TextMeshProUGUI val4 = val.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)font != (Object)null)
			{
				((TMP_Text)val4).font = font;
			}
			if ((Object)(object)material != (Object)null)
			{
				((TMP_Text)val4).fontSharedMaterial = material;
			}
			((TMP_Text)val4).fontSize = size;
			((Graphic)val4).color = color;
			((TMP_Text)val4).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val4).textWrappingMode = (TextWrappingModes)0;
			((Graphic)val4).raycastTarget = false;
			return (TMP_Text)(object)val4;
		}

		internal static TMP_FontAsset Font(string name)
		{
			TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
			foreach (TMP_FontAsset val in array)
			{
				if (((Object)val).name == name)
				{
					return val;
				}
			}
			if (!name.Contains("Serif"))
			{
				return null;
			}
			return TMP_Settings.defaultFontAsset;
		}

		private static Material Shadowed(TMP_FontAsset font, float alpha, float softness)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)font == (Object)null || (Object)(object)((TMP_Asset)font).material == (Object)null)
			{
				return null;
			}
			Material val = new Material(((TMP_Asset)font).material)
			{
				name = ((Object)font).name + " BRB Shadow"
			};
			val.EnableKeyword("UNDERLAY_ON");
			val.SetColor("_UnderlayColor", new Color(0f, 0f, 0f, alpha));
			val.SetFloat("_UnderlayOffsetX", 0.2f);
			val.SetFloat("_UnderlayOffsetY", -0.3f);
			val.SetFloat("_UnderlayDilate", 0.3f);
			val.SetFloat("_UnderlaySoftness", softness);
			return val;
		}

		private static Texture2D Gradient(int w, int h, Func<float, float, float> alpha)
		{
			//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_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(w, h, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)1
			};
			for (int i = 0; i < h; i++)
			{
				for (int j = 0; j < w; j++)
				{
					val.SetPixel(j, i, new Color(1f, 1f, 1f, alpha((w > 1) ? ((float)j / ((float)w - 1f)) : 0f, (h > 1) ? ((float)i / ((float)h - 1f)) : 0f)));
				}
			}
			val.Apply(false, true);
			return val;
		}
	}
	internal sealed class PauseMotion
	{
		private readonly List<(Animator animator, AnimatorUpdateMode mode)> _animators = new List<(Animator, AnimatorUpdateMode)>();

		private readonly List<(MagicaCloth cloth, ClothUpdateMode mode)> _cloths = new List<(MagicaCloth, ClothUpdateMode)>();

		internal void Begin(Player player)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Invalid comparison between Unknown and I4
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			Restore();
			Unscale(((Character)player).m_animator);
			Raven[] array = Object.FindObjectsByType<Raven>((FindObjectsSortMode)0);
			foreach (Raven val in array)
			{
				Unscale(val.m_animator);
			}
			try
			{
				MagicaCloth[] componentsInChildren = ((Component)player).GetComponentsInChildren<MagicaCloth>(true);
				foreach (MagicaCloth val2 in componentsInChildren)
				{
					ClothSerializeData serializeData = val2.SerializeData;
					if (serializeData != null && (int)serializeData.updateMode != 2)
					{
						_cloths.Add((val2, serializeData.updateMode));
						serializeData.updateMode = (ClothUpdateMode)2;
						val2.SetParameterChange();
					}
				}
			}
			catch (Exception ex)
			{
				BeRightBackPlugin.Log.LogWarning((object)("Cloth not switched to unscaled time: " + ex.Message));
			}
		}

		private void Unscale(Animator animator)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Invalid comparison between Unknown and I4
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)animator == (Object)null) && (int)animator.updateMode != 2)
			{
				_animators.Add((animator, animator.updateMode));
				animator.updateMode = (AnimatorUpdateMode)2;
			}
		}

		internal void Restore()
		{
			//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_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_002c: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			foreach (var (val, updateMode) in _animators)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.updateMode = updateMode;
				}
			}
			_animators.Clear();
			foreach (var (val2, updateMode2) in _cloths)
			{
				try
				{
					if (!((Object)(object)val2 == (Object)null))
					{
						val2.SerializeData.updateMode = updateMode2;
						val2.SetParameterChange();
					}
				}
				catch (Exception ex)
				{
					BeRightBackPlugin.Log.LogWarning((object)("Cloth update mode not restored: " + ex.Message));
				}
			}
			_cloths.Clear();
		}
	}
	[BepInPlugin("cdev.berightback", "CDEV.BeRightBack", "0.1.0")]
	[BepInProcess("valheim.exe")]
	public sealed class BeRightBackPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			ModConfig.Bind(((BaseUnityPlugin)this).Config);
			_harmony = new Harmony("cdev.berightback");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			if ((Object)(object)Menu.instance != (Object)null)
			{
				MenuEntry.Add(Menu.instance);
			}
		}

		private void OnDestroy()
		{
			BrbScreen.Close(immediate: true);
			Launcher.Shutdown();
			MenuHold.ReleaseAll();
			Stage.ReleaseAll();
			MenuEntry.Remove();
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	[Serializable]
	public sealed class Preset
	{
		public string name = "";

		public string text = "";

		public List<string> emotes = new List<string>();

		public int position = 7;

		public float size = 1f;

		public bool timer = true;

		public bool shuffle = true;

		public bool light = true;

		internal bool BuiltIn;

		internal int Row => Mathf.Clamp(position, 0, 8) / 3;

		internal int Column => Mathf.Clamp(position, 0, 8) % 3;

		internal string Title
		{
			get
			{
				if (!string.IsNullOrWhiteSpace(text))
				{
					return text.Trim();
				}
				return Texts.DefaultTitle;
			}
		}

		internal void Clean()
		{
			name = name ?? "";
			text = text ?? "";
			emotes = emotes ?? new List<string>();
			emotes.RemoveAll((string e) => !Emotes.IsKnown(e));
			position = Mathf.Clamp(position, 0, 8);
			size = Mathf.Clamp((size <= 0f) ? 1f : size, 0.5f, 2f);
		}

		internal Preset Copy(string newName)
		{
			return new Preset
			{
				name = newName,
				text = text,
				emotes = new List<string>(emotes),
				position = position,
				size = size,
				timer = timer,
				shuffle = shuffle,
				light = light
			};
		}
	}
	[Serializable]
	public sealed class PresetFile
	{
		public int version = 2;

		public int selected;

		public List<Preset> presets = new List<Preset>();

		internal void Clean()
		{
			presets = presets ?? new List<Preset>();
			presets.RemoveAll((Preset p) => p?.BuiltIn ?? true);
			foreach (Preset preset in presets)
			{
				preset.Clean();
			}
			selected = Mathf.Clamp(selected, 0, 3 + presets.Count - 1);
		}
	}
	internal static class Store
	{
		internal const int BuiltInCount = 3;

		private static string Path => System.IO.Path.Combine(Paths.ConfigPath, "cdev.berightback.presets.json");

		internal static PresetFile Load()
		{
			PresetFile presetFile = null;
			try
			{
				if (File.Exists(Path))
				{
					presetFile = JsonConvert.DeserializeObject<PresetFile>(File.ReadAllText(Path));
				}
			}
			catch (Exception ex)
			{
				BeRightBackPlugin.Log.LogWarning((object)("Presets not read, only the built-in ones are there: " + ex.Message));
			}
			presetFile = presetFile ?? new PresetFile();
			presetFile.Clean();
			return presetFile;
		}

		internal static void Save(PresetFile file)
		{
			try
			{
				file.Clean();
				File.WriteAllText(Path, JsonConvert.SerializeObject((object)file, (Formatting)1));
			}
			catch (Exception ex)
			{
				BeRightBackPlugin.Log.LogError((object)("Presets not saved: " + ex.Message));
			}
		}

		internal static List<Preset> BuiltIns()
		{
			return new List<Preset>
			{
				new Preset
				{
					BuiltIn = true,
					name = Texts.Get("title"),
					text = Texts.Get("title"),
					emotes = new List<string>
					{
						"dance", "headbang", "vibe", "cheer", "flex", "laugh", "wave", "blowkiss", "loveyou", "thumbsup",
						"challenge", "bow"
					},
					position = 7
				},
				new Preset
				{
					BuiltIn = true,
					name = Texts.Get("preset.toilet"),
					text = Texts.Get("preset.toilet"),
					emotes = new List<string> { "wave", "shrug", "nonono", "point", "comehere", "cower", "laugh" },
					position = 1
				},
				new Preset
				{
					BuiltIn = true,
					name = Texts.Get("preset.coffee"),
					text = Texts.Get("preset.coffee"),
					emotes = new List<string> { "sit", "relax", "rest", "toast" },
					position = 7
				}
			};
		}

		internal static List<Preset> All(PresetFile file)
		{
			List<Preset> list = BuiltIns();
			list.AddRange(file.presets);
			return list;
		}
	}
	internal static class Emotes
	{
		internal static readonly string[] All = new string[25]
		{
			"dance", "headbang", "vibe", "sit", "relax", "rest", "kneel", "laugh", "cry", "despair",
			"comehere", "wave", "cheer", "flex", "thumbsup", "blowkiss", "loveyou", "bow", "challenge", "roar",
			"point", "shrug", "nonono", "toast", "cower"
		};

		private static readonly HashSet<string> Loops = new HashSet<string>
		{
			"dance", "headbang", "vibe", "sit", "relax", "rest", "kneel", "laugh", "cry", "despair",
			"comehere"
		};

		private static readonly HashSet<string> Ground = new HashSet<string> { "sit", "relax", "rest", "kneel", "despair" };

		internal static bool IsKnown(string name)
		{
			if (name != null)
			{
				return Array.IndexOf(All, name) >= 0;
			}
			return false;
		}

		internal static bool IsLoop(string name)
		{
			return Loops.Contains(name);
		}

		internal static bool IsGround(string name)
		{
			if (name != null)
			{
				return Ground.Contains(name);
			}
			return false;
		}

		internal unsafe static bool OneShot(string name)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			if (!Enum.TryParse<Emotes>(name, ignoreCase: true, out Emotes result))
			{
				return true;
			}
			return ((Emote)Attribute.GetCustomAttribute(typeof(Emotes).GetField(((object)(*(Emotes*)(&result))/*cast due to .constrained prefix*/).ToString()), typeof(Emote)))?.OneShot ?? true;
		}
	}
	internal sealed class PresetWindow : MonoBehaviour
	{
		private sealed class OrderPlate : MonoBehaviour, IBeginDragHandler, IEventSystemHandler, IDragHandler, IEndDragHandler
		{
			internal PresetWindow Window;

			internal UiKit.Control Control;

			internal int Index;

			internal Vector2 Slot;

			public void OnBeginDrag(PointerEventData e)
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				if ((int)e.button == 0)
				{
					UiKit.Guard(delegate
					{
						Window.BeginDrag(this, e);
					});
				}
			}

			public void OnDrag(PointerEventData e)
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				if ((int)e.button == 0)
				{
					UiKit.Guard(delegate
					{
						Window.Drag(this, e);
					});
				}
			}

			public void OnEndDrag(PointerEventData e)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				if ((int)e.button == 0)
				{
					UiKit.Guard(delegate
					{
						Window.EndDrag(this);
					});
				}
			}

			private void OnDisable()
			{
				if ((Object)(object)Window != (Object)null && (Object)(object)Window._held == (Object)(object)this)
				{
					Window._held = null;
				}
			}
		}

		private const float W = 1120f;

		private const float Pad = 28f;

		private const float Side = 236f;

		private const float X0 = 290f;

		private const float R = 1092f;

		private const float Top = 132f;

		private const float SaveDelay = 0.4f;

		private static PresetWindow _instance;

		private PresetFile _file;

		private float _saveAt = -1f;

		private int _openedFrame;

		private RectTransform _panel;

		private RectTransform _list;

		private float _listRows;

		private TextMeshProUGUI _mineCaption;

		private TextMeshProUGUI _mineEmpty;

		private const float RowStep = 50f;

		private const float SectionGap = 40f;

		private TMP_InputField _name;

		private TMP_InputField _text;

		private UiKit.CheckBox _timer;

		private TextMeshProUGUI _count;

		private TextMeshProUGUI _sizeValue;

		private TextMeshProUGUI _warn;

		private Slider _size;

		private readonly Dictionary<string, UiKit.Control> _chips = new Dictionary<string, UiKit.Control>();

		private readonly UiKit.Control[] _cells = new UiKit.Control[9];

		private readonly List<UiKit.Control> _items = new List<UiKit.Control>();

		private UiKit.Control _new;

		private UiKit.Control _start;

		private RectTransform _previewHost;

		private Overlay _preview;

		private readonly SceneLight _previewLight = new SceneLight();

		private UiKit.CheckBox _lightCheck;

		private Camera _previewCamera;

		private RenderTexture _previewTexture;

		private RawImage _previewShot;

		private RectTransform _order;

		private RectTransform _orderContent;

		private ScrollRect _orderScroll;

		private UiKit.CheckBox _shuffle;

		private readonly List<OrderPlate> _plates = new List<OrderPlate>();

		private List<Preset> _all = new List<Preset>();

		private UiKit.Control _allButton;

		private UiKit.Control _noneButton;

		private OrderPlate _held;

		private int _dropOn = -1;

		private float _grab;

		internal static bool IsOpen => (Object)(object)_instance != (Object)null;

		private Preset Current => _all[Mathf.Clamp(_file.selected, 0, _all.Count - 1)];

		private bool ReadOnly => Current.BuiltIn;

		private static float RowY(int i)
		{
			if (i >= 3)
			{
				return 190f + (float)(i - 3) * 50f;
			}
			return (float)i * 50f;
		}

		internal static void Show()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_instance != (Object)null)
			{
				return;
			}
			GameObject val = new GameObject("CDEV_BeRightBack_Presets", new Type[1] { typeof(RectTransform) });
			Canvas val2 = (((Object)(object)Menu.instance != (Object)null) ? ((Component)Menu.instance).GetComponentInParent<Canvas>(true) : null);
			if ((Object)(object)val2 != (Object)null)
			{
				val.transform.SetParent(((Component)val2.rootCanvas).transform, false);
				UiKit.Stretch((RectTransform)val.transform);
				val.transform.SetAsLastSibling();
				val.AddComponent<CanvasGroup>().ignoreParentGroups = true;
			}
			else
			{
				Object.DontDestroyOnLoad((Object)(object)val);
			}
			try
			{
				_instance = val.AddComponent<PresetWindow>();
				_instance._file = Store.Load();
				_instance._all = Store.All(_instance._file);
				MenuHold.Hold();
				Stage.Hold(Player.m_localPlayer, ((Object)(object)GameCamera.instance != (Object)null) ? LayerMask.op_Implicit(GameCamera.instance.m_blockCameraMask) : (-1));
				_instance.Build();
				_instance.RefreshAll();
				if (ZInput.IsGamepadActive() && (Object)(object)EventSystem.current != (Object)null)
				{
					EventSystem.current.SetSelectedGameObject(((Component)_instance._start.Button).gameObject);
				}
			}
			catch (Exception ex)
			{
				BeRightBackPlugin.Log.LogError((object)("Presets window not opened: " + ex));
				CloseNow();
			}
		}

		internal static void CloseNow()
		{
			if (!((Object)(object)_instance == (Object)null))
			{
				PresetWindow instance = _instance;
				_instance = null;
				if (instance._saveAt > 0f)
				{
					Store.Save(instance._file);
				}
				instance.DropPreview();
				Object.Destroy((Object)(object)((Component)instance).gameObject);
				MenuHold.Release();
				Stage.Release();
			}
		}

		private void StartPreset()
		{
			Preset current = Current;
			if (current != null && current.emotes.Count != 0)
			{
				Store.Save(_file);
				_saveAt = -1f;
				BrbScreen.Open(current);
				CloseNow();
			}
		}

		private void Update()
		{
			if ((Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)Menu.instance == (Object)null)
			{
				CloseNow();
				return;
			}
			MenuHold.ShowCursor();
			if (Time.frameCount > _openedFrame && (ZInput.GetKeyDown((KeyCode)27, true) || ZInput.GetButtonDown("JoyButtonB")))
			{
				CloseNow();
			}
			else if (_saveAt > 0f && Time.unscaledTime >= _saveAt)
			{
				_saveAt = -1f;
				Store.Save(_file);
			}
		}

		private void OnDestroy()
		{
			DropPreview();
		}

		private void DropPreview()
		{
			_previewLight.Destroy();
			_preview?.Destroy();
			_preview = null;
			if ((Object)(object)_previewCamera != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_previewCamera).gameObject);
			}
			_previewCamera = null;
			if ((Object)(object)_previewTexture != (Object)null)
			{
				_previewTexture.Release();
				Object.Destroy((Object)(object)_previewTexture);
			}
			_previewTexture = null;
		}

		private void Changed()
		{
			_saveAt = Time.unscaledTime + 0.4f;
			RefreshPreset();
		}

		private void Build()
		{
			//IL_00b0: 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_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: 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_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_045c: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0533: Unknown result type (might be due to invalid IL or missing references)
			//IL_058e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0595: Unknown result type (might be due to invalid IL or missing references)
			//IL_0597: Unknown result type (might be due to invalid IL or missing references)
			//IL_0598: Unknown result type (might be due to invalid IL or missing references)
			//IL_059f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0758: Unknown result type (might be due to invalid IL or missing references)
			//IL_082b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0880: Unknown result type (might be due to invalid IL or missing references)
			//IL_0926: Unknown result type (might be due to invalid IL or missing references)
			//IL_09d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_09e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad9: Unknown result type (might be due to invalid IL or missing references)
			_openedFrame = Time.frameCount;
			if ((Object)(object)((Component)this).transform.parent == (Object)null)
			{
				Canvas val = ((Component)this).gameObject.AddComponent<Canvas>();
				val.renderMode = (RenderMode)0;
				val.sortingOrder = 9000;
				CanvasScaler val2 = ((Component)this).gameObject.AddComponent<CanvasScaler>();
				val2.uiScaleMode = (ScaleMode)1;
				val2.referenceResolution = new Vector2(1920f, 1080f);
				val2.matchWidthOrHeight = 0.5f;
				((Component)this).gameObject.AddComponent<GraphicRaycaster>();
			}
			UiKit.Rect("Dim", ((Component)this).transform).Stretch().Fill(new Color(0f, 0f, 0f, 0.55f), 0f, raycast: true);
			_panel = UiKit.Rect("Window", ((Component)this).transform);
			RectTransform panel = _panel;
			RectTransform panel2 = _panel;
			RectTransform panel3 = _panel;
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, 0.5f);
			panel3.pivot = val3;
			Vector2 anchorMin = (panel2.anchorMax = val3);
			panel.anchorMin = anchorMin;
			UiKit.WoodPanel(_panel);
			UiKit.Title(_panel, Texts.Get("window.title"), 58f);
			UiKit.Caption((Transform)(object)_panel, Texts.Get("name"), 290f, 132f);
			_name = UiKit.Input((Transform)(object)_panel, 290f, 156f, 320f, 42f, "", delegate(string v)
			{
				if (!ReadOnly)
				{
					Current.name = v;
					RefreshList();
					_saveAt = Time.unscaledTime + 0.4f;
				}
			});
			UiKit.Caption((Transform)(object)_panel, Texts.Get("text"), 626f, 132f);
			_text = UiKit.Input((Transform)(object)_panel, 626f, 156f, 466f, 42f, Texts.DefaultTitle, delegate(string v)
			{
				if (!ReadOnly)
				{
					Current.text = v;
					Changed();
				}
			});
			_timer = UiKit.Check((Transform)(object)_panel, Texts.Get("timer"), 290f, 212f, delegate(bool v)
			{
				if (!ReadOnly)
				{
					Current.timer = v;
					Changed();
				}
			});
			_lightCheck = UiKit.Check((Transform)(object)_panel, Texts.Get("light"), 626f, 212f, delegate(bool v)
			{
				if (!ReadOnly)
				{
					Current.light = v;
					Changed();
				}
			});
			float num = 266f;
			TextMeshProUGUI val5 = UiKit.Caption((Transform)(object)_panel, Texts.Get("emotes"), 290f, num + 6f);
			float x = ((TMP_Text)val5).GetPreferredValues(((TMP_Text)val5).text.ToUpperInvariant()).x;
			RectTransform val6 = UiKit.Rect("Count", (Transform)(object)_panel).Place(290f + x + 12f, num + 4f, 36f, 24f);
			val6.Fill(UiKit.AccentDeep, 12f);
			_count = UiKit.Label((Transform)(object)val6, "0", 15f, UiKit.AccentHover, UiKit.BodyMedium, (TextAlignmentOptions)514);
			((TMP_Text)_count).rectTransform.Stretch();
			_noneButton = UiKit.Button((Transform)(object)_panel, Texts.Get("none"), 962f, num - 2f, 130f, 36f, delegate
			{
				if (!ReadOnly)
				{
					Current.emotes.Clear();
					Changed();
				}
			}, primary: false, 16f);
			_allButton = UiKit.Button((Transform)(object)_panel, Texts.Get("all"), 824f, num - 2f, 130f, 36f, delegate
			{
				if (!ReadOnly)
				{
					Current.emotes.Clear();
					Current.emotes.AddRange(Emotes.All);
					Changed();
				}
			}, primary: false, 16f);
			string arg = Mathf.RoundToInt(ModConfig.DanceSecondsMin.Value) + "-" + Mathf.RoundToInt(Mathf.Max(ModConfig.DanceSecondsMin.Value, ModConfig.DanceSecondsMax.Value));
			num = Chips(Texts.Get("emotes.long", arg), loops: true, num + 44f);
			num = Chips(Texts.Get("emotes.short"), loops: false, num + 12f);
			num += 18f;
			TextMeshProUGUI val7 = UiKit.Caption((Transform)(object)_panel, Texts.Get("order"), 290f, num + 6f);
			float x2 = ((TMP_Text)val7).GetPreferredValues(((TMP_Text)val7).text.ToUpperInvariant()).x;
			TextMeshProUGUI val8 = UiKit.Label((Transform)(object)_panel, Texts.Get("order.hint"), 14f, UiKit.Dim, null, (TextAlignmentOptions)4097);
			((TMP_Text)val8).rectTransform.Place(290f + x2 + 14f, num + 4f, 802f - x2 - 14f - 250f, 24f);
			_shuffle = UiKit.Check((Transform)(object)_panel, Texts.Get("shuffle"), 862f, num, delegate(bool v)
			{
				if (!ReadOnly)
				{
					Current.shuffle = v;
					Changed();
				}
			});
			_order = UiKit.Rect("Order", (Transform)(object)_panel).Place(290f, num + 34f, 802f, 36f);
			_order.Fill(UiKit.Clear, 0f, raycast: true);
			((Component)_order).gameObject.AddComponent<RectMask2D>();
			_orderContent = UiKit.Rect("Content", (Transform)(object)_order);
			RectTransform orderContent = _orderContent;
			RectTransform orderContent2 = _orderContent;
			RectTransform orderContent3 = _orderContent;
			((Vector2)(ref val3))..ctor(0f, 1f);
			orderContent3.pivot = val3;
			anchorMin = (orderContent2.anchorMax = val3);
			orderContent.anchorMin = anchorMin;
			_orderScroll = ((Component)_order).gameObject.AddComponent<ScrollRect>();
			_orderScroll.horizontal = true;
			_orderScroll.vertical = false;
			_orderScroll.movementType = (MovementType)2;
			_orderScroll.scrollSensitivity = 30f;
			_orderScroll.viewport = _order;
			_orderScroll.content = _orderContent;
			num += 70f;
			float num2 = num + 24f;
			UiKit.Caption((Transform)(object)_panel, Texts.Get("position"), 290f, num2);
			RectTransform val10 = UiKit.Rect("Grid", (Transform)(object)_panel).Place(290f, num2 + 26f, 160f, 124f);
			UiKit.LeatherPane(val10);
			for (int num3 = 0; num3 < 9; num3++)
			{
				int position = num3;
				_cells[num3] = UiKit.Cell((Transform)(object)val10, 8f + (float)(num3 % 3) * 49f, 8f + (float)(num3 / 3) * 37f, 46f, 34f, delegate
				{
					if (!ReadOnly)
					{
						Current.position = position;
						Changed();
					}
				});
			}
			UiKit.Caption((Transform)(object)_panel, Texts.Get("size"), 480f, num2);
			_size = UiKit.Slider((Transform)(object)_panel, 480f, num2 + 32f, 160f, 50f, 200f, delegate(float v)
			{
				if (!ReadOnly)
				{
					Current.size = v / 100f;
					Changed();
				}
			});
			_sizeValue = UiKit.Label((Transform)(object)_panel, "", 18f, UiKit.AccentHover, UiKit.BodyMedium, (TextAlignmentOptions)4100);
			((TMP_Text)_sizeValue).rectTransform.Place(646f, num2 + 32f, 64f, 30f);
			UiKit.Caption((Transform)(object)_panel, Texts.Get("preview"), 740f, num2);
			RectTransform val11 = UiKit.Rect("PreviewFrame", (Transform)(object)_panel).Place(740f, num2 + 26f, 352f, 198f);
			UiKit.LeatherPane(val11);
			_previewHost = UiKit.Rect("Preview", (Transform)(object)val11).Stretch(4f);
			_previewHost.Fill(new Color(0.11f, 0.12f, 0.14f, 1f));
			((Component)_previewHost).gameObject.AddComponent<RectMask2D>();
			float num4 = num2 + 26f + 198f + 26f;
			float num5 = num4 + 46f + 16f;
			_panel.sizeDelta = new Vector2(1120f, num5);
			_start = UiKit.Button((Transform)(object)_panel, Texts.Get("start"), 882f, num4, 210f, 46f, StartPreset, primary: true);
			UiKit.Button((Transform)(object)_panel, Texts.Get("cancel"), 658f, num4, 210f, 46f, CloseNow);
			_warn = UiKit.Label((Transform)(object)_panel, Texts.Get("need.emote"), 15f, UiKit.Bad, UiKit.BodyMedium, (TextAlignmentOptions)257);
			((TMP_Text)_warn).rectTransform.Place(290f, num2 + 164f, 426f, 60f);
			((TMP_Text)_warn).enableAutoSizing = true;
			((TMP_Text)_warn).fontSizeMin = 11f;
			((TMP_Text)_warn).fontSizeMax = 15f;
			((TMP_Text)_warn).textWrappingMode = (TextWrappingModes)1;
			UiKit.Rect("SideRule", (Transform)(object)_panel).Place(276f, 132f, 1f, num4 + 46f - 132f).Fill(UiKit.Accent.WithAlpha(0.25f));
			UiKit.Caption((Transform)(object)_panel, Texts.Get("presets.builtin"), 28f, 132f);
			float num6 = num4;
			_list = UiKit.Rect("List", (Transform)(object)_panel).Place(28f, 158f, 236f, num6 - 12f - 132f - 26f);
			_listRows = 3f + Mathf.Floor((num6 - 12f - 132f - 26f - 150f - 40f) / 50f);
			_mineCaption = UiKit.Caption((Transform)(object)_list, Texts.Get("presets.mine"), 0f, 160f, 236f);
			_mineEmpty = UiKit.Label((Transform)(object)_list, Texts.Get("presets.empty", Texts.Get("new")), 14f, UiKit.Dim, UiKit.Body, (TextAlignmentOptions)257);
			((TMP_Text)_mineEmpty).rectTransform.Place(0f, 190f, 236f, 44f);
			((TMP_Text)_mineEmpty).textWrappingMode = (TextWrappingModes)1;
			_new = UiKit.Button((Transform)(object)_panel, Texts.Get("new"), 28f, num6, 236f, 46f, NewPreset);
			UiKit.ApplyLight(((Component)this).transform);
		}

		private float Chips(string caption, bool loops, float y)
		{
			//IL_000c: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = UiKit.Label((Transform)(object)_panel, caption, 15f, UiKit.Dim, null, (TextAlignmentOptions)4097);
			((TMP_Text)val).rectTransform.Place(290f, y, 802f, 20f);
			y += 26f;
			float num = 290f;
			TextMeshProUGUI val2 = UiKit.Label((Transform)(object)_panel, "", 15f, Color.clear, null, (TextAlignmentOptions)4097);
			string[] all = Emotes.All;
			foreach (string text in all)
			{
				if (Emotes.IsLoop(text) == loops)
				{
					string text2 = Texts.Get("emote." + text);
					float num2 = Mathf.Ceil(((TMP_Text)val2).GetPreferredValues(text2, 1000f, 32f).x) + 30f;
					if (num + num2 > 1092f)
					{
						num = 290f;
						y += 38f;
					}
					string emote = text;
					_chips[text] = UiKit.Chip((Transform)(object)_panel, text2, num, y, num2, 32f, delegate
					{
						ToggleEmote(emote);
					});
					num += num2 + 6f;
				}
			}
			Object.Destroy((Object)(object)((Component)val2).gameObject);
			return y + 32f;
		}

		private void ToggleEmote(string id)
		{
			if (!ReadOnly)
			{
				List<string> emotes = Current.emotes;
				if (!emotes.Remove(id))
				{
					emotes.Add(id);
				}
				Changed();
			}
		}

		private void NewPreset()
		{
			_file.presets.Add(new Preset
			{
				name = Texts.Get("preset.default", (_file.presets.Count + 1).ToString()),
				emotes = new List<string> { "dance", "headbang", "vibe" }
			});
			_all = Store.All(_file);
			_file.selected = _all.Count - 1;
			_saveAt = Time.unscaledTime + 0.4f;
			RefreshAll();
			((Selectable)_name).Select();
			_name.ActivateInputField();
		}

		private void CopyPreset(int index)
		{
			Preset preset = _all[index];
			int num = ((!preset.BuiltIn) ? (_file.presets.IndexOf(preset) + 1) : 0);
			_file.presets.Insert(num, preset.Copy(preset.name + " 2"));
			_all = Store.All(_file);
			_file.selected = 3 + num;
			_saveAt = Time.unscaledTime + 0.4f;
			RefreshAll();
		}

		private void DeletePreset(int index)
		{
			if (!_all[index].BuiltIn)
			{
				_file.presets.Remove(_all[index]);
				_all = Store.All(_file);
				if (_file.selected > index || _file.selected >= _all.Count)
				{
					_file.selected--;
				}
				_file.selected = Mathf.Clamp(_file.selected, 0, _all.Count - 1);
				_saveAt = Time.unscaledTime + 0.4f;
				RefreshAll();
			}
		}

		private void RefreshAll()
		{
			RefreshList();
			RefreshPreset();
		}

		private void RefreshList()
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			if (_items.Count != _all.Count)
			{
				foreach (UiKit.Control item in _items)
				{
					Object.Destroy((Object)(object)((Component)item.Button).gameObject);
				}
				_items.Clear();
				for (int i = 0; i < _all.Count; i++)
				{
					int index = i;
					UiKit.Control control = UiKit.Row((Transform)(object)_list, "", 0f, RowY(i), 236f, 44f, delegate
					{
						_file.selected = index;
						_saveAt = Time.unscaledTime + 0.4f;
						RefreshAll();
					});
					bool builtIn = _all[i].BuiltIn;
					((TMP_Text)control.Label).rectTransform.offsetMax = new Vector2(builtIn ? (-40f) : (-72f), 0f);
					if (!builtIn)
					{
						UiKit.RowAction(control, 0, "×", null, delegate
						{
							DeletePreset(index);
						}, ((Component)this).transform, Texts.Get("delete"), Texts.Get("delete.tip"));
					}
					UiKit.Control control2 = UiKit.RowAction(control, (!builtIn) ? 1 : 0, null, UiKit.CopyIcon, delegate
					{
						CopyPreset(index);
					}, ((Component)this).transform, Texts.Get("copy"), Texts.Get("copy.tip"));
					((Component)control2.Button).gameObject.SetActive((float)_all.Count < _listRows);
					_items.Add(control);
				}
				UiKit.ApplyLight((Transform)(object)_list);
			}
			for (int num = 0; num < _items.Count; num++)
			{
				Preset preset = _all[num];
				_items[num].Text = (string.IsNullOrWhiteSpace(preset.name) ? Texts.Get("preset.default", (num + 1).ToString()) : preset.name);
				_items[num].On = num == _file.selected;
				_items[num].Refresh();
			}
			((Component)_mineEmpty).gameObject.SetActive(_all.Count == 3);
			((Selectable)_new.Button).interactable = (float)_all.Count < _listRows;
			_new.Refresh();
		}

		private void RefreshPreset()
		{
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			Preset current = Current;
			bool flag = !current.BuiltIn;
			TMP_InputField name = _name;
			bool interactable = (((Selectable)_text).interactable = flag);
			((Selectable)name).interactable = interactable;
			((Selectable)_size).interactable = flag;
			UiKit.Control[] array = new UiKit.Control[5] { _allButton, _noneButton, _timer.Control, _shuffle.Control, _lightCheck.Control };
			foreach (UiKit.Control control in array)
			{
				((Selectable)control.Button).interactable = flag;
				control.Refresh();
			}
			foreach (UiKit.Control value in _chips.Values)
			{
				((Selectable)value.Button).interactable = flag;
			}
			UiKit.Control[] cells = _cells;
			foreach (UiKit.Control control2 in cells)
			{
				((Selectable)control2.Button).interactable = flag;
			}
			if (!_name.isFocused)
			{
				_name.SetTextWithoutNotify(current.name);
			}
			if (!_text.isFocused)
			{
				_text.SetTextWithoutNotify(current.text);
			}
			_timer.Set(current.timer);
			_lightCheck.Set(current.light);
			_size.SetValueWithoutNotify(Mathf.Round(current.size * 100f));
			((TMP_Text)_sizeValue).text = Mathf.RoundToInt(current.size * 100f) + "%";
			foreach (KeyValuePair<string, UiKit.Control> chip in _chips)
			{
				chip.Value.On = current.emotes.Contains(chip.Key);
				chip.Value.Refresh();
			}
			((TMP_Text)_count).text = current.emotes.Count.ToString();
			for (int k = 0; k < 9; k++)
			{
				_cells[k].On = k == current.position;
				_cells[k].Refresh();
			}
			((Component)_warn).gameObject.SetActive(current.BuiltIn || current.emotes.Count == 0);
			((TMP_Text)_warn).text = (current.BuiltIn ? Texts.Get("builtin.hint") : Texts.Get("need.emote"));
			((Graphic)_warn).color = (current.BuiltIn ? UiKit.Dim : UiKit.Bad);
			((Selectable)_start.Button).interactable = current.emotes.Count > 0;
			_start.Refresh();
			RefreshOrder(current);
			RefreshPreview(current);
		}

		private void RefreshPreview(Preset p)
		{
			//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_0071: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0147: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			Camera val = (((Object)(object)GameCamera.instance != (Object)null) ? GameCamera.instance.m_camera : Camera.main);
			if ((Object)(object)localPlayer != (Object)null && (Object)(object)val != (Object)null)
			{
				if ((Object)(object)_previewCamera == (Object)null)
				{
					_previewTexture = new RenderTexture(704, 396, 24, (RenderTextureFormat)0)
					{
						name = "CDEV_BeRightBack_Preview"
					};
					GameObject val2 = new GameObject("CDEV_BeRightBack_PreviewCamera");
					_previewCamera = val2.AddComponent<Camera>();
					_previewCamera.CopyFrom(val);
					_previewCamera.targetTexture = _previewTexture;
					_previewShot = ((Component)UiKit.Rect("World", (Transform)(object)_previewHost).Stretch()).gameObject.AddComponent<RawImage>();
					_previewShot.texture = (Texture)(object)_previewTexture;
					((Graphic)_previewShot).raycastTarget = false;
				}
				BrbScreen.Pose(localPlayer, p, Stage.Yaw, ((Object)(object)GameCamera.instance != (Object)null) ? LayerMask.op_Implicit(GameCamera.instance.m_blockCameraMask) : (-1), out var pos, out var rot);
				((Component)_previewCamera).transform.SetPositionAndRotation(pos, rot);
				Stage.LookTarget = pos;
				_previewLight.Update(p.light, localPlayer, pos);
				((Component)_previewShot).transform.SetAsFirstSibling();
			}
			_preview?.Destroy();
			_preview = new Overlay(p, ModConfig.CinemaBars.Value, null, _previewHost);
			_preview.Update(10f, Texts.Away("04:12"));
		}

		private void RefreshOrder(Preset p)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_019c: Unknown result type (might be due to invalid IL or missing references)
			_shuffle.Set(p.shuffle);
			foreach (OrderPlate plate in _plates)
			{
				if ((Object)(object)plate != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)plate).gameObject);
				}
			}
			_plates.Clear();
			TextMeshProUGUI val = UiKit.Label((Transform)(object)_panel, "", 15f, Color.clear, null, (TextAlignmentOptions)4097);
			float num = 0f;
			for (int i = 0; i < p.emotes.Count; i++)
			{
				string text = i + 1 + "  " + Texts.Get("emote." + p.emotes[i]);
				float num2 = Mathf.Ceil(((TMP_Text)val).GetPreferredValues(text, 1000f, 34f).x) + 30f;
				UiKit.Control control = UiKit.Chip((Transform)(object)_orderContent, text, num, 1f, num2, 34f, null);
				OrderPlate orderPlate = ((Component)control.Button).gameObject.AddComponent<OrderPlate>();
				orderPlate.Window = this;
				orderPlate.Control = control;
				orderPlate.Index = i;
				orderPlate.Slot = new Vector2(num, num2);
				_plates.Add(orderPlate);
				num += num2 + 6f;
			}
			Object.Destroy((Object)(object)((Component)val).gameObject);
			_orderContent.sizeDelta = new Vector2(Mathf.Max(0f, num - 6f), 36f);
			UiKit.ApplyLight((Transform)(object)_orderContent);
		}

		private void BeginDrag(OrderPlate plate, PointerEventData e)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_held != (Object)null) && !ReadOnly)
			{
				_held = plate;
				_dropOn = -1;
				((Component)plate).transform.SetAsLastSibling();
				CanvasGroup val = ((Component)plate).gameObject.GetComponent<CanvasGroup>() ?? ((Component)plate).gameObject.AddComponent<CanvasGroup>();
				val.blocksRaycasts = false;
				val.alpha = 0.85f;
				Vector2 val2 = default(Vector2);
				RectTransformUtility.ScreenPointToLocalPointInRectangle(_orderContent, e.position, e.pressEventCamera, ref val2);
				_grab = ((RectTransform)((Component)plate).transform).anchoredPosition.x - val2.x;
			}
		}

		private void Drag(OrderPlate plate, PointerEventData e)
		{
			//IL_0016: 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_0037: Expected O, but got Unknown
			//IL_0038: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: 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_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			if ((Object)(object)_held != (Object)(object)plate || !RectTransformUtility.ScreenPointToLocalPointInRectangle(_orderContent, e.position, e.pressEventCamera, ref val))
			{
				return;
			}
			RectTransform val2 = (RectTransform)((Component)plate).transform;
			val2.anchoredPosition = new Vector2(val.x + _grab, val2.anchoredPosition.y);
			int num = -1;
			foreach (OrderPlate plate2 in _plates)
			{
				if ((Object)(object)plate2 != (Object)(object)plate && val.x >= plate2.Slot.x && val.x <= plate2.Slot.x + plate2.Slot.y)
				{
					num = plate2.Index;
				}
			}
			if (num != _dropOn)
			{
				if (_dropOn >= 0 && _dropOn < _plates.Count)
				{
					_plates[_dropOn].Control.On = false;
					_plates[_dropOn].Control.Refresh();
				}
				_dropOn = num;
				if (_dropOn >= 0)
				{
					_plates[_dropOn].Control.On = true;
					_plates[_dropOn].Control.Refresh();
				}
			}
			Vector2 val3 = default(Vector2);
			RectTransformUtility.ScreenPointToLocalPointInRectangle(_order, e.position, e.pressEventCamera, ref val3);
			float num2 = Time.unscaledDeltaTime * 600f;
			Rect rect = _orderContent.rect;
			float width = ((Rect)(ref rect)).width;
			rect = _order.rect;
			float num3 = num2 / Mathf.Max(1f, width - ((Rect)(ref rect)).width);
			float x = val3.x;
			rect = _order.rect;
			if (x > ((Rect)(ref rect)).xMax - 40f)
			{
				_orderScroll.horizontalNormalizedPosition = Mathf.Clamp01(_orderScroll.horizontalNormalizedPosition + num3);
				return;
			}
			float x2 = val3.x;
			rect = _order.rect;
			if (x2 < ((Rect)(ref rect)).xMin + 40f)
			{
				_orderScroll.horizontalNormalizedPosition = Mathf.Clamp01(_orderScroll.horizontalNormalizedPosition - num3);
			}
		}

		private void EndDrag(OrderPlate plate)
		{
			if (!((Object)(object)_held != (Object)(object)plate))
			{
				_held = null;
				int index = plate.Index;
				int dropOn = _dropOn;
				_dropOn = -1;
				List<string> emotes = Current.emotes;
				if (dropOn >= 0 && dropOn < emotes.Count && index >= 0 && index < emotes.Count && dropOn != index)
				{
					string value = emotes[index];
					emotes[index] = emotes[dropOn];
					emotes[dropOn] = value;
				}
				Changed();
			}
		}
	}
	internal static class Props
	{
		private static readonly int TankardHash = StringExtensionMethods.GetStableHashCode("Tankard");

		private static VisEquipment _vis;

		private static int _right;

		private static int _quality;

		internal static void Mug(Player player, bool on)
		{
			VisEquipment val = (((Object)(object)player != (Object)null) ? ((Humanoid)player).m_visEquipment : null);
			if (on)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)_vis != (Object)null))
				{
					_vis = val;
					_right = val.m_rightItem;
					_quality = val.m_rightItemQuality;
					val.SetRightItem(TankardHash, 1);
				}
			}
			else if ((Object)(object)_vis != (Object)null)
			{
				_vis.SetRightItem(_right, _quality);
				_vis = null;
			}
		}
	}
	internal sealed class SceneLight
	{
		private Light _light;

		internal void Update(bool on, Player player, Vector3 cameraPosition)
		{
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: 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_00ff: 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_010a: 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_0119: 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_0056: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			float num = ((on && (Object)(object)player != (Object)null) ? Strength(player) : 0f);
			if (num <= 0f)
			{
				if ((Object)(object)_light != (Object)null)
				{
					((Behaviour)_light).enabled = false;
				}
				return;
			}
			if ((Object)(object)_light == (Object)null)
			{
				GameObject val = new GameObject("CDEV_BeRightBack_Light");
				_light = val.AddComponent<Light>();
				_light.type = (LightType)2;
				_light.color = new Color(1f, 0.92f, 0.8f);
				_light.range = 9f;
				_light.shadows = (LightShadows)0;
				_light.renderMode = (LightRenderMode)1;
			}
			((Behaviour)_light).enabled = true;
			_light.intensity = 1.7f * num;
			Vector3 val2 = ((Component)player).transform.position + Vector3.up * 1.2f;
			((Component)_light).transform.position = Vector3.Lerp(val2, cameraPosition, 0.6f) + Vector3.up * 0.8f;
		}

		internal void Destroy()
		{
			if ((Object)(object)_light != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_light).gameObject);
			}
			_light = null;
		}

		private static float Strength(Player player)
		{
			if (((Character)player).InInterior())
			{
				return 1f;
			}
			if ((Object)(object)EnvMan.instance != (Object)null && !EnvMan.IsDaylight())
			{
				return 1f;
			}
			if (((Character)player).IsUnderRoof() || player.InShelter())
			{
				return 0.7f;
			}
			return 0f;
		}
	}
	[HarmonyPatch]
	internal static class Stage
	{
		private const int Directions = 24;

		private const float Radius = 0.25f;

		private static int _holds;

		private static Player _player;

		private static Quaternion _rotation;

		private static Vector3 _lookDir;

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

		private static readonly HashSet<Collider> Ignored = new HashSet<Collider>();

		internal static Vector3? LookTarget;

		internal static float Yaw { get; private set; }

		internal static bool Active => _holds > 0;

		[HarmonyPatch(typeof(Game), "UpdatePause")]
		[HarmonyPostfix]
		private static void Game_UpdatePause_Postfix()
		{
			//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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_0077: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: 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_012e: 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_015e: 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_016c: 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)
			if (_holds == 0 || (Object)(object)_player == (Object)null || (Object)(object)((Character)_player).m_eye == (Object)null)
			{
				return;
			}
			try
			{
				Vector3 position = ((Character)_player).m_eye.position;
				Vector3 val = (Vector3)(((??)LookTarget) ?? (position + Quaternion.Euler(0f, Yaw, 0f) * Vector3.forward));
				Vector3 val2 = val - position;
				if (!(((Vector3)(ref val2)).sqrMagnitude < 0.0001f))
				{
					((Vector3)(ref val2)).Normalize();
					string name = (((Object)(object)((Character)_player).m_nview != (Object)null && ((Character)_player).m_nview.IsValid()) ? ((Character)_player).m_nview.GetZDO().GetString(ZDOVars.s_emote, "") : "");
					bool flag = Emotes.IsGround(name);
					Vector3 val3 = default(Vector3);
					((Vector3)(ref val3))..ctor(val2.x, 0f, val2.z);
					if (!flag && ((Vector3)(ref val3)).sqrMagnitude > 0.0001f)
					{
						((Component)_player).transform.rotation = Quaternion.RotateTowards(((Component)_player).transform.rotation, Quaternion.LookRotation(val3), 240f * Time.unscaledDeltaTime);
					}
					Vector3 val4 = (flag ? ((Component)_player).transform.forward : val2);
					((Character)_player).m_eye.rotation = Quaternion.LookRotation(val4);
					((Character)_player).SetLookDir(val4, 0f);
				}
			}
			catch (Exception ex)
			{
				BeRightBackPlugin.Log.LogWarning((object)("Look at the camera failed: " + ex.Message));
				LookTarget = null;
			}
		}

		internal static void Hold(Player player, int blockMask)
		{
			//IL_0065: 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_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_0036: Unknown result type (might be due to invalid IL or missing references)
			if (_holds++ > 0 || (Object)(object)player == (Object)null)
			{
				return;
			}
			_player = player;
			_rotation = ((Component)player).transform.rotation;
			_lookDir = ((Character)player).GetLookDir();
			try
			{
				Choose(player, blockMask);
			}
			catch (Exception ex)
			{
				BeRightBackPlugin.Log.LogWarning((object)("Could not set the scene up for the camera: " + ex.Message));
				Yaw = ((Component)player).transform.eulerAngles.y;
			}
		}

		internal static void Release()
		{
			if (_holds != 0 && --_holds <= 0)
			{
				Restore();
			}
		}

		internal static void ReleaseAll()
		{
			if (_holds != 0)
			{
				_holds = 0;
				Restore();
			}
		}

		private static void Restore()
		{
			//IL_0074: 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)
			foreach (Renderer hiddenRenderer in HiddenRenderers)
			{
				if ((Object)(object)hiddenRenderer != (Object)null)
				{
					hiddenRenderer.enabled = true;
				}
			}
			HiddenRenderers.Clear();
			Ignored.Clear();
			LookTarget = null;
			if ((Object)(object)_player != (Object)null)
			{
				((Component)_player).transform.rotation = _rotation;
				((Character)_player).SetLookDir(_lookDir, 0f);
			}
			_player = null;
		}

		private static void Choose(Player player, int mask)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_00c0: 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_00fe: 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_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: 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_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: 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 target = ((Component)player).transform.position + Vector3.up * 1.1f;
			float value = ModConfig.CameraDistance.Value;
			float num = Mathf.Min(ModConfig.CameraSway.Value, 60f) * 0.6f;
			float y = ((Component)player).transform.eulerAngles.y;
			float num2 = y;
			float num3 = -1f;
			float num4 = float.MinValue;
			float num5 = y;
			float num6 = -1f;
			float num7 = float.MinValue;
			for (int i = 0; i < 24; i++)
			{
				float num8 = y + (float)i * 360f / 24f;
				float num9 = 0.05f * (1f - Mathf.Abs(Mathf.DeltaAngle(num8, y)) / 180f);
				float num10 = Mathf.Min(Room(target, num8, mask, value, throughPieces: false), Mathf.Min(Room(target, num8 - num, mask, value, throughPieces: false), Room(target, num8 + num, mask, value, throughPieces: false)));
				if (num10 + num9 > num4)
				{
					num4 = num10 + num9;
					num3 = num10;
					num2 = num8;
				}
				float num11 = Room(target, num8, mask, value, throughPieces: true);
				if (num11 + num9 > num7)
				{
					num7 = num11 + num9;
					num6 = num11;
					num5 = num8;
				}
			}
			if (num3 < value * 0.75f && num6 > num3 + 0.5f)
			{
				num2 = num5;
				HidePieces(target, num5, mask, value);
			}
			Yaw = num2;
			Quaternion val = Quaternion.Euler(0f, num2, 0f);
			((Component)player).transform.rotation = val;
			((Character)player).SetLookDir(val * Vector3.forward, 0f);
		}

		private static float Room(Vector3 target, float yaw, int mask, float max, bool throughPieces)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Vector3 val = Quaternion.Euler(-10f, yaw, 0f) * Vector3.forward;
			float num = max;
			RaycastHit[] array = Physics.SphereCastAll(target, 0.25f, val, max, mask);
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val2 = array[i];
				if (!((Object)(object)((RaycastHit)(ref val2)).collider == (Object)null) && !Ignored.Contains(((RaycastHit)(ref val2)).collider) && (!throughPieces || !((Object)(object)Hideable(((RaycastHit)(ref val2)).collider) != (Object)null)) && ((RaycastHit)(ref val2)).distance < num)
				{
					num = ((RaycastHit)(ref val2)).distance;
				}
			}
			return num;
		}

		private static Piece Hideable(Collider c)
		{
			Piece componentInParent = ((Component)c).GetComponentInParent<Piece>();
			if (!((Object)(object)componentInParent != (Object)null) || !componentInParent.IsPlacedByPlayer())
			{
				return null;
			}
			return componentInParent;
		}

		private static void HidePieces(Vector3 target, float yaw, int mask, float max)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Quaternion.Euler(-10f, yaw, 0f) * Vector3.forward;
			HashSet<Piece> hashSet = new HashSet<Piece>();
			RaycastHit[] array = Physics.SphereCastAll(target, 0.25f, val, max + 0.5f, mask);
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val2 = array[i];
				Piece val3 = (((Object)(object)((RaycastHit)(ref val2)).collider != (Object)null) ? Hideable(((RaycastHit)(ref val2)).collider) : null);
				if ((Object)(object)val3 != (Object)null)
				{
					hashSet.Add(val3);
				}