Decompiled source of CWPlus v1.2.0

CWPlus.dll

Decompiled 21 hours 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CurvedUI;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using UnityEngine.UI.ProceduralImage;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("CWPlus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CWPlus")]
[assembly: AssemblyTitle("CWPlus")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CWPlus
{
	[HarmonyPatch(typeof(VideoCamera), "Update")]
	internal static class VideoCamera_Update
	{
		private static readonly FieldRef<VideoCamera, GameObject> RecUI = AccessTools.FieldRefAccess<VideoCamera, GameObject>("m_recordingUI");

		private static readonly FieldRef<VideoCamera, VideoInfoEntry> Info = AccessTools.FieldRefAccess<VideoCamera, VideoInfoEntry>("m_recorderInfoEntry");

		private static readonly Dictionary<VideoCamera, TextMeshProUGUI> Texts = new Dictionary<VideoCamera, TextMeshProUGUI>();

		private static void Postfix(VideoCamera __instance)
		{
			if (!Cfg.CameraOn.Value)
			{
				return;
			}
			try
			{
				GameObject val = RecUI.Invoke(__instance);
				if ((Object)(object)val == (Object)null || !val.activeInHierarchy)
				{
					return;
				}
				VideoInfoEntry val2 = Info.Invoke(__instance);
				if (val2 == null)
				{
					return;
				}
				if (!Texts.TryGetValue(__instance, out var value) || (Object)(object)value == (Object)null)
				{
					value = Create(val);
					Texts[__instance] = value;
					if ((Object)(object)value == (Object)null)
					{
						return;
					}
				}
				int num = Mathf.CeilToInt(Mathf.Max(0f, val2.timeLeft));
				string text = num / 60 + ":" + (num % 60).ToString("00");
				if (((TMP_Text)value).text != text)
				{
					((TMP_Text)value).text = text;
				}
			}
			catch (Exception e)
			{
				SafeLog.Once("Camera", e);
			}
		}

		private static TextMeshProUGUI Create(GameObject rec)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI componentInChildren = rec.GetComponentInChildren<TextMeshProUGUI>(true);
			GameObject val;
			TextMeshProUGUI component;
			Rect rect;
			if ((Object)(object)componentInChildren != (Object)null)
			{
				((TMP_Text)componentInChildren).ForceMeshUpdate(false, false);
				Bounds textBounds = ((TMP_Text)componentInChildren).textBounds;
				val = Object.Instantiate<GameObject>(((Component)componentInChildren).gameObject, ((TMP_Text)componentInChildren).transform.parent, false);
				((Object)val).name = "CWPlus_FilmLeft";
				component = val.GetComponent<TextMeshProUGUI>();
				RectTransform rectTransform = ((TMP_Text)component).rectTransform;
				rectTransform.pivot = new Vector2(0f, 0.5f);
				rect = ((TMP_Text)componentInChildren).rectTransform.rect;
				float num = Mathf.Max(200f, ((Rect)(ref rect)).width * 2f);
				rect = ((TMP_Text)componentInChildren).rectTransform.rect;
				rectTransform.sizeDelta = new Vector2(num, ((Rect)(ref rect)).height);
				float num2 = ((TMP_Text)componentInChildren).fontSize * 0.5f;
				((Transform)rectTransform).position = ((TMP_Text)componentInChildren).transform.TransformPoint(new Vector3(((Bounds)(ref textBounds)).max.x + num2, ((Bounds)(ref textBounds)).center.y, 0f));
			}
			else
			{
				TextMeshProUGUI componentInChildren2 = ((Component)rec.transform.root).GetComponentInChildren<TextMeshProUGUI>(true);
				Transform transform = rec.transform;
				RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				if ((Object)(object)componentInChildren2 == (Object)null || (Object)(object)val2 == (Object)null)
				{
					return null;
				}
				val = Object.Instantiate<GameObject>(((Component)componentInChildren2).gameObject, rec.transform.parent, false);
				((Object)val).name = "CWPlus_FilmLeft";
				component = val.GetComponent<TextMeshProUGUI>();
				RectTransform rectTransform2 = ((TMP_Text)component).rectTransform;
				((Transform)rectTransform2).localRotation = ((Transform)val2).localRotation;
				((Transform)rectTransform2).localScale = Vector3.one;
				rectTransform2.pivot = new Vector2(0f, 0.5f);
				rect = val2.rect;
				float num3 = ((Rect)(ref rect)).height * 6f;
				rect = val2.rect;
				rectTransform2.sizeDelta = new Vector2(num3, ((Rect)(ref rect)).height);
				TextMeshProUGUI obj = component;
				rect = val2.rect;
				((TMP_Text)obj).fontSize = ((Rect)(ref rect)).height * 0.8f;
				Rect rect2 = val2.rect;
				((Transform)rectTransform2).position = rec.transform.TransformPoint(new Vector3(((Rect)(ref rect2)).xMax + ((Rect)(ref rect2)).height * 0.3f, ((Rect)(ref rect2)).center.y, 0f));
			}
			AspectRatioUISetter[] componentsInChildren = val.GetComponentsInChildren<AspectRatioUISetter>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			for (int num4 = val.transform.childCount - 1; num4 >= 0; num4--)
			{
				Object.DestroyImmediate((Object)(object)((Component)val.transform.GetChild(num4)).gameObject);
			}
			((TMP_Text)component).alignment = (TextAlignmentOptions)4097;
			((TMP_Text)component).enableWordWrapping = false;
			((TMP_Text)component).enableAutoSizing = false;
			((Graphic)component).raycastTarget = false;
			val.SetActive(true);
			return component;
		}
	}
	internal static class EmoteWheel
	{
		public const int PerPage = 8;

		public static readonly List<Item> Learned = new List<Item>();

		public static bool Open;

		public static int Selected = -1;

		public static int Page;

		public static Vector2 Cursor;

		private static bool _loaded;

		private static bool _holding;

		private static float _holdStart;

		private static Item _last;

		private const float DeadZone = 40f;

		private const float MaxCursor = 200f;

		private const float QuickTap = 0.2f;

		private static string FilePath => Path.Combine(Paths.ConfigPath, "enzo.cwplus.emotes.txt");

		public static int PageCount => Mathf.Max(1, (Learned.Count + 8 - 1) / 8);

		public static int PageItemCount => Mathf.Clamp(Learned.Count - Page * 8, 0, 8);

		public static void Tick(PlayerInput input, Player player)
		{
			//IL_00d4: 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_0041: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			bool emoteIsPressed = input.emoteIsPressed;
			if (!_holding)
			{
				if (!emoteIsPressed || player.data.dead || player.data.emoteTime > 0f)
				{
					return;
				}
				_holding = true;
				_holdStart = Time.unscaledTime;
				Cursor = Vector2.zero;
				Selected = -1;
				RefreshLearned(player);
				if (Page >= PageCount)
				{
					Page = 0;
				}
				Open = Learned.Count > 0;
			}
			input.emoteIsPressed = false;
			input.emoteWasPressed = false;
			if (emoteIsPressed)
			{
				if (Open)
				{
					if (PageCount > 1 && Input.GetKeyDown(Cfg.EmotePageKey.Value))
					{
						Page = (Page + 1) % PageCount;
						Cursor = Vector2.zero;
					}
					Mouse current = Mouse.current;
					Cursor += ((current != null) ? ((InputControl<Vector2>)(object)((Pointer)current).delta).ReadValue() : (input.lookInput * 20f));
					if (((Vector2)(ref Cursor)).magnitude > 200f)
					{
						Cursor = ((Vector2)(ref Cursor)).normalized * 200f;
					}
					input.lookInput = Vector2.zero;
					Selected = ComputeSelected();
				}
				return;
			}
			_holding = false;
			bool flag = Time.unscaledTime - _holdStart < 0.2f;
			int num = Page * 8 + Selected;
			if (Open && Selected >= 0 && num < Learned.Count)
			{
				Play(player, Learned[num]);
			}
			else if (flag)
			{
				Item val = _last;
				PlayerInventory val2 = default(PlayerInventory);
				if ((Object)(object)val == (Object)null && player.TryGetInventory(ref val2))
				{
					val = val2.emote;
				}
				if ((Object)(object)val != (Object)null)
				{
					Play(player, val);
				}
			}
			Open = false;
			Selected = -1;
		}

		public static void Reset()
		{
			_holding = false;
			Open = false;
			Selected = -1;
		}

		private static int ComputeSelected()
		{
			int pageItemCount = PageItemCount;
			if (pageItemCount == 0 || ((Vector2)(ref Cursor)).magnitude < 40f)
			{
				return -1;
			}
			float num = Mathf.Atan2(Cursor.y, Cursor.x) * 57.29578f;
			return Mathf.RoundToInt((90f - num + 360f) % 360f / (360f / (float)pageItemCount)) % pageItemCount;
		}

		private static void Play(Player player, Item emote)
		{
			if (!((Object)(object)emote == (Object)null) && emote.emoteInfo != null && !((Object)(object)player.refs.emotes == (Object)null) && !(player.data.emoteTime > 0f))
			{
				_last = emote;
				player.refs.emotes.PlayEmote(emote);
			}
		}

		public static void RefreshLearned(Player player)
		{
			Load();
			PlayerInventory val = default(PlayerInventory);
			if (player.TryGetInventory(ref val) && (Object)(object)val.emote != (Object)null)
			{
				Add(val.emote);
			}
		}

		public static void Add(Item item)
		{
			Load();
			if (!((Object)(object)item == (Object)null) && item.emoteInfo != null && !Learned.Contains(item))
			{
				Learned.Add(item);
				Save();
			}
		}

		private static void Load()
		{
			if (_loaded)
			{
				return;
			}
			_loaded = true;
			try
			{
				if (!File.Exists(FilePath))
				{
					return;
				}
				string[] array = File.ReadAllLines(FilePath);
				Item val = default(Item);
				for (int i = 0; i < array.Length; i++)
				{
					if (Guid.TryParse(array[i].Trim(), out var result) && ItemDatabase.TryGetItemFromPersistentID(result, ref val) && (Object)(object)val != (Object)null && val.emoteInfo != null && !Learned.Contains(val))
					{
						Learned.Add(val);
					}
				}
			}
			catch (Exception e)
			{
				SafeLog.Once("EmoteLoad", e);
			}
		}

		private static void Save()
		{
			try
			{
				List<string> list = new List<string>();
				foreach (Item item in Learned)
				{
					if (!string.IsNullOrEmpty(item.persistentID))
					{
						list.Add(item.persistentID);
					}
				}
				File.WriteAllLines(FilePath, list);
			}
			catch (Exception e)
			{
				SafeLog.Once("EmoteSave", e);
			}
		}
	}
	[HarmonyPatch(typeof(PlayerInput), "SampeInput")]
	internal static class PlayerInput_SampeInput
	{
		private static void Postfix(PlayerInput __instance, Player player)
		{
			if (!Cfg.EmotesOn.Value || (Object)(object)player == (Object)null || (Object)(object)player != (Object)(object)Player.localPlayer)
			{
				return;
			}
			try
			{
				EmoteWheel.Tick(__instance, player);
			}
			catch (Exception e)
			{
				SafeLog.Once("EmoteTick", e);
			}
		}
	}
	[HarmonyPatch(typeof(PlayerEmotes), "RPC_DoBookEquipEffect")]
	internal static class PlayerEmotes_RPC_DoBookEquipEffect
	{
		private static void Postfix(int viewID, byte itemId)
		{
			if (!Cfg.EmotesOn.Value)
			{
				return;
			}
			try
			{
				Player localPlayer = Player.localPlayer;
				Item item = default(Item);
				if (!((Object)(object)localPlayer == (Object)null) && !((Object)(object)localPlayer.refs.view == (Object)null) && localPlayer.refs.view.ViewID == viewID && ItemDatabase.TryGetItemFromID(itemId, ref item))
				{
					EmoteWheel.Add(item);
				}
			}
			catch (Exception e)
			{
				SafeLog.Once("EmoteLearn", e);
			}
		}
	}
	[HarmonyPatch(typeof(HotbarUI), "Set")]
	internal static class HotbarUI_Set
	{
		private class State
		{
			public HotbarSlotUI[] Extra;

			public bool HasBase;

			public Vector3 Base0;

			public Vector3 Step;

			public int ResW;

			public int ResH;
		}

		private static readonly Dictionary<HotbarUI, State> States = new Dictionary<HotbarUI, State>();

		internal static readonly Dictionary<HotbarSlotUI, string> Labels = new Dictionary<HotbarSlotUI, string>();

		private static void Postfix(HotbarUI __instance, Player player)
		{
			try
			{
				Run(__instance, player);
			}
			catch (Exception e)
			{
				SafeLog.Once("Hotbar", e);
			}
		}

		private static void Run(HotbarUI ui, Player player)
		{
			if (ui.slots == null || ui.slots.Length < 2 || (Object)(object)ui.slots[0] == (Object)null || (Object)(object)ui.slots[1] == (Object)null)
			{
				return;
			}
			if (!States.TryGetValue(ui, out var value))
			{
				value = new State();
				States[ui] = value;
			}
			if (Cfg.InventoryOn.Value)
			{
				if (value.Extra == null || (Object)(object)value.Extra[0] == (Object)null || (Object)(object)value.Extra[1] == (Object)null)
				{
					value.Extra = CreateExtras(ui);
				}
				if (value.Extra != null)
				{
					Position(ui, value);
				}
			}
			PlayerInventory val = default(PlayerInventory);
			if (!player.TryGetInventory(ref val))
			{
				return;
			}
			int selectedItemSlot = player.data.selectedItemSlot;
			if (value.Extra != null && Cfg.InventoryOn.Value)
			{
				InventorySlot val2 = default(InventorySlot);
				for (int i = 0; i < 2; i++)
				{
					int num = Inv.NormalSlots[3 + i];
					if (val.TryGetSlot(num, ref val2))
					{
						value.Extra[i].SetData(val2, num == selectedItemSlot);
					}
				}
			}
			if (!Cfg.BatteryOn.Value)
			{
				return;
			}
			for (int j = 0; j < ui.slots.Length; j++)
			{
				BatteryBar.UpdateFor(ui.slots[j], val, j);
			}
			if (value.Extra != null && Cfg.InventoryOn.Value)
			{
				for (int k = 0; k < 2; k++)
				{
					BatteryBar.UpdateFor(value.Extra[k], val, Inv.NormalSlots[3 + k]);
				}
			}
		}

		private static HotbarSlotUI[] CreateExtras(HotbarUI ui)
		{
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			HotbarSlotUI[] array = (HotbarSlotUI[])(object)new HotbarSlotUI[2];
			GameObject gameObject = ((Component)ui.slots[0]).gameObject;
			for (int i = 0; i < 2; i++)
			{
				bool activeSelf = gameObject.activeSelf;
				gameObject.SetActive(false);
				GameObject val = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent);
				gameObject.SetActive(activeSelf);
				((Object)val).name = "CWPlus_Slot" + (4 + i);
				AspectRatioUISetter[] componentsInChildren = val.GetComponentsInChildren<AspectRatioUISetter>(true);
				for (int j = 0; j < componentsInChildren.Length; j++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren[j]);
				}
				Transform val2 = val.transform.Find("CWPlus_Battery");
				if ((Object)(object)val2 != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)((Component)val2).gameObject);
				}
				HotbarSlotUI component = val.GetComponent<HotbarSlotUI>();
				Labels[component] = Inv.KeyLabel((i == 0) ? Cfg.KeySlot4.Value : Cfg.KeySlot5.Value);
				val.SetActive(true);
				array[i] = component;
			}
			Plugin.Log.LogInfo((object)"Cases 4 et 5 ajoutées à la barre d'inventaire");
			return array;
		}

		private static void Position(HotbarUI ui, State st)
		{
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: 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_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: 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)
			Transform transform = ((Component)ui.slots[0]).transform;
			Transform transform2 = ((Component)ui.slots[1]).transform;
			Transform parent = transform.parent;
			if ((Object)(object)parent == (Object)null || (Object)(object)transform2.parent != (Object)(object)parent)
			{
				return;
			}
			bool num = (Object)(object)((Component)parent).GetComponent<LayoutGroup>() != (Object)null;
			bool flag = st.ResW != Screen.width || st.ResH != Screen.height;
			st.ResW = Screen.width;
			st.ResH = Screen.height;
			if (num)
			{
				Transform parent2 = parent.parent;
				if (!((Object)(object)parent2 == (Object)null))
				{
					float num2 = ((Cfg.ShiftSlots.Value < 0f) ? 1f : Cfg.ShiftSlots.Value);
					bool flag2 = (Object)(object)((Component)parent).GetComponent<AspectRatioUISetter>() != (Object)null;
					if (!st.HasBase || (flag && flag2))
					{
						st.Base0 = parent.localPosition;
						st.Step = parent2.InverseTransformVector(transform2.position - transform.position);
						st.HasBase = true;
					}
					parent.localPosition = st.Base0 - st.Step * num2;
				}
				return;
			}
			float num3 = ((Cfg.ShiftSlots.Value < 0f) ? 2f : Cfg.ShiftSlots.Value);
			bool flag3 = (Object)(object)((Component)transform).GetComponent<AspectRatioUISetter>() != (Object)null;
			if (!st.HasBase || (flag && flag3))
			{
				st.Base0 = transform.localPosition;
				st.Step = transform2.localPosition - transform.localPosition;
				st.HasBase = true;
			}
			for (int i = 0; i < 3 && i < ui.slots.Length; i++)
			{
				if ((Object)(object)ui.slots[i] != (Object)null && (Object)(object)((Component)ui.slots[i]).transform.parent == (Object)(object)parent)
				{
					((Component)ui.slots[i]).transform.localPosition = st.Base0 + st.Step * ((float)i - num3);
				}
			}
			for (int j = 0; j < 2; j++)
			{
				((Component)st.Extra[j]).transform.localPosition = st.Base0 + st.Step * ((float)(3 + j) - num3);
			}
		}
	}
	[HarmonyPatch(typeof(HotbarSlotUI), "InputSchemeChanged")]
	internal static class HotbarSlotUI_InputSchemeChanged
	{
		private static bool Prefix(HotbarSlotUI __instance)
		{
			if (HotbarUI_Set.Labels.TryGetValue(__instance, out var value))
			{
				if ((Object)(object)__instance.m_keybind != (Object)null)
				{
					((TMP_Text)__instance.m_keybind).text = value;
				}
				return false;
			}
			return true;
		}
	}
	internal class BatteryBar
	{
		public const string ChildName = "CWPlus_Battery";

		private static readonly Dictionary<HotbarSlotUI, BatteryBar> Bars = new Dictionary<HotbarSlotUI, BatteryBar>();

		private static readonly Color Gold = new Color(0.95f, 0.72f, 0.3f, 1f);

		private static readonly Color Low = new Color(0.9f, 0.25f, 0.2f, 1f);

		private GameObject _root;

		private RectTransform _fill;

		private Image _fillImg;

		private float _last = -1f;

		public static void UpdateFor(HotbarSlotUI slotUI, PlayerInventory inv, int slotId)
		{
			//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_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_003b: 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_0120: 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)
			if ((Object)(object)slotUI == (Object)null)
			{
				return;
			}
			float num = -1f;
			InventorySlot val = default(InventorySlot);
			if (inv.TryGetSlot(slotId, ref val))
			{
				ItemDescriptor itemInSlot = val.ItemInSlot;
				BatteryEntry val2 = default(BatteryEntry);
				if ((Object)(object)itemInSlot.item != (Object)null && itemInSlot.data != null && itemInSlot.data.TryGetEntry<BatteryEntry>(ref val2))
				{
					num = val2.GetPercentage();
				}
			}
			Bars.TryGetValue(slotUI, out var value);
			if (value != null && (Object)(object)value._root == (Object)null)
			{
				value = null;
			}
			if (num < 0f)
			{
				if (value != null && value._root.activeSelf)
				{
					value._root.SetActive(false);
				}
				return;
			}
			if (value == null)
			{
				value = Create(slotUI);
				Bars[slotUI] = value;
			}
			if (!value._root.activeSelf)
			{
				value._root.SetActive(true);
			}
			float num2 = Mathf.Round(num * 100f) / 100f;
			if (!Mathf.Approximately(num2, value._last))
			{
				value._last = num2;
				value._fill.anchorMax = new Vector2(Mathf.Clamp01(num2), 1f);
				((Graphic)value._fillImg).color = ((num2 <= 0.2f) ? Low : Gold);
			}
		}

		private static BatteryBar Create(HotbarSlotUI slotUI)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Expected O, but got Unknown
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Expected O, but got Unknown
			//IL_011e: 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_014e: 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)
			Transform val = ((Component)slotUI).transform.Find("CWPlus_Battery");
			if ((Object)(object)val != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)((Component)val).gameObject);
			}
			BatteryBar batteryBar = new BatteryBar();
			batteryBar._root = new GameObject("CWPlus_Battery", new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)batteryBar._root.transform;
			((Transform)val2).SetParent(((Component)slotUI).transform, false);
			val2.anchorMin = new Vector2(0.12f, 0.07f);
			val2.anchorMax = new Vector2(0.88f, 0.14f);
			val2.offsetMin = Vector2.zero;
			val2.offsetMax = Vector2.zero;
			Image obj = batteryBar._root.AddComponent<Image>();
			((Graphic)obj).color = new Color(0f, 0f, 0f, 0.55f);
			((Graphic)obj).raycastTarget = false;
			GameObject val3 = new GameObject("Fill", new Type[1] { typeof(RectTransform) });
			batteryBar._fill = (RectTransform)val3.transform;
			((Transform)batteryBar._fill).SetParent((Transform)(object)val2, false);
			batteryBar._fill.anchorMin = Vector2.zero;
			batteryBar._fill.anchorMax = Vector2.one;
			batteryBar._fill.offsetMin = Vector2.zero;
			batteryBar._fill.offsetMax = Vector2.zero;
			batteryBar._fillImg = val3.AddComponent<Image>();
			((Graphic)batteryBar._fillImg).color = Gold;
			((Graphic)batteryBar._fillImg).raycastTarget = false;
			CurvedUISettings componentInParent = ((Component)slotUI).GetComponentInParent<CurvedUISettings>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				componentInParent.AddEffectToChildren();
			}
			return batteryBar;
		}
	}
	internal static class Inv
	{
		public static readonly int[] NormalSlots = new int[5] { 0, 1, 2, 4, 6 };

		public const int TotalSlots = 7;

		public static bool TryGetFreeNormalSlot(PlayerInventory inv, out InventorySlot slot)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			int[] normalSlots = NormalSlots;
			foreach (int num in normalSlots)
			{
				if (num < inv.slots.Length && inv.slots[num] != null && (Object)(object)inv.slots[num].ItemInSlot.item == (Object)null)
				{
					slot = inv.slots[num];
					return true;
				}
			}
			slot = null;
			return false;
		}

		public unsafe static string KeyLabel(KeyCode key)
		{
			return ((object)(*(KeyCode*)(&key))/*cast due to .constrained prefix*/).ToString().Replace("Alpha", "").Replace("Keypad", "");
		}
	}
	[HarmonyPatch(typeof(PlayerInventory), "Awake")]
	internal static class PlayerInventory_Awake
	{
		private static void Prefix(PlayerInventory __instance)
		{
			if (Cfg.InventoryOn.Value && (__instance.slots == null || __instance.slots.Length < 7))
			{
				__instance.slots = (InventorySlot[])(object)new InventorySlot[7];
			}
		}
	}
	[HarmonyPatch(typeof(PlayerInventory), "TryGetFeeSlot")]
	internal static class PlayerInventory_TryGetFeeSlot
	{
		private static bool Prefix(PlayerInventory __instance, ref InventorySlot slot, ref bool __result)
		{
			if (!Cfg.InventoryOn.Value)
			{
				return true;
			}
			__result = Inv.TryGetFreeNormalSlot(__instance, out slot);
			return false;
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal static class PlayerInventory_TryAddItem
	{
		private static bool Prefix(PlayerInventory __instance, ItemDescriptor item, ref InventorySlot slot, ref bool __result)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Invalid comparison between Unknown and I4
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if (!Cfg.InventoryOn.Value)
			{
				return true;
			}
			ItemType itemType = item.item.itemType;
			if ((int)itemType == 2 || (int)itemType == 3)
			{
				return true;
			}
			if (Inv.TryGetFreeNormalSlot(__instance, out slot))
			{
				slot.Add(item);
				__result = true;
			}
			else
			{
				slot = null;
				__result = false;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(PlayerItems), "Update")]
	internal static class PlayerItems_Update
	{
		private static readonly FieldRef<PlayerItems, Player> PlayerRef = AccessTools.FieldRefAccess<PlayerItems, Player>("player");

		private static void Postfix(PlayerItems __instance)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			if (Cfg.InventoryOn.Value)
			{
				Player val = PlayerRef.Invoke(__instance);
				if (!((Object)(object)val == (Object)null) && val.data.isLocal && val.data.physicsAreReady && !val.HasLockedInput() && GlobalInputHandler.CanTakeInput())
				{
					Check(val, Cfg.KeySlot4.Value, Inv.NormalSlots[3]);
					Check(val, Cfg.KeySlot5.Value, Inv.NormalSlots[4]);
				}
			}
		}

		private static void Check(Player player, KeyCode key, int slotId)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(key))
			{
				player.data.selectedItemSlot = ((player.data.selectedItemSlot == slotId) ? (-1) : slotId);
			}
		}
	}
	[HarmonyPatch(typeof(UI_Oxygen), "Update")]
	internal static class UI_Oxygen_Update
	{
		private static TextMeshProUGUI _text;

		private static UI_Oxygen _owner;

		private static string _lastValue;

		private static readonly Color Dark = new Color(0.12f, 0.08f, 0.03f, 1f);

		private static readonly Color Gold = new Color(0.95f, 0.75f, 0.35f, 1f);

		private static void Postfix(UI_Oxygen __instance)
		{
			//IL_0142: 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)
			if (!Cfg.OxygenOn.Value)
			{
				if ((Object)(object)_text != (Object)null && ((Component)_text).gameObject.activeSelf)
				{
					((Component)_text).gameObject.SetActive(false);
				}
			}
			else
			{
				if ((Object)(object)Player.localPlayer == (Object)null || Time.frameCount % 8 != 0)
				{
					return;
				}
				try
				{
					if ((Object)(object)_text == (Object)null || (Object)(object)_owner != (Object)(object)__instance)
					{
						_owner = __instance;
						_text = Create(__instance);
						_lastValue = null;
						if ((Object)(object)_text == (Object)null)
						{
							return;
						}
					}
					if (!((Component)_text).gameObject.activeSelf)
					{
						((Component)_text).gameObject.SetActive(true);
					}
					PlayerData data = Player.localPlayer.data;
					float num = Mathf.Max(0f, data.remainingOxygen);
					float num2 = ((data.maxOxygen > 0f) ? (num / data.maxOxygen) : 0f);
					string text = Mathf.CeilToInt(num2 * 100f) + "%";
					if (text != _lastValue)
					{
						_lastValue = text;
						((TMP_Text)_text).text = text;
						((Graphic)_text).color = ((num2 > 0.2f) ? Dark : Gold);
					}
				}
				catch (Exception e)
				{
					SafeLog.Once("Oxygen", e);
				}
			}
		}

		private static TextMeshProUGUI Create(UI_Oxygen ui)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ui.fill == (Object)null)
			{
				return null;
			}
			HotbarSlotUI val = Object.FindObjectOfType<HotbarSlotUI>();
			if ((Object)(object)val == (Object)null || (Object)(object)val.m_keybind == (Object)null)
			{
				return null;
			}
			GameObject val2 = Object.Instantiate<GameObject>(((Component)val.m_keybind).gameObject, ((Component)ui.fill).transform, false);
			((Object)val2).name = "CWPlus_OxygenText";
			AspectRatioUISetter[] componentsInChildren = val2.GetComponentsInChildren<AspectRatioUISetter>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			RectTransform val3 = (RectTransform)val2.transform;
			val3.anchorMin = Vector2.zero;
			val3.anchorMax = Vector2.one;
			val3.pivot = new Vector2(0.5f, 0.5f);
			((Transform)val3).localRotation = Quaternion.identity;
			((Transform)val3).localScale = Vector3.one;
			val3.offsetMin = new Vector2(10f, 0f);
			val3.offsetMax = new Vector2(-10f, 0f);
			TextMeshProUGUI component = val2.GetComponent<TextMeshProUGUI>();
			((TMP_Text)component).alignment = (TextAlignmentOptions)4097;
			((TMP_Text)component).enableWordWrapping = false;
			((TMP_Text)component).enableAutoSizing = true;
			((TMP_Text)component).fontSizeMin = 6f;
			((TMP_Text)component).fontSizeMax = 60f;
			((Graphic)component).raycastTarget = false;
			return component;
		}
	}
	[HarmonyPatch(typeof(UI_Health), "Update")]
	internal static class PlayersHud
	{
		private static RectTransform _root;

		private static UI_Health _owner;

		private static float _next;

		private static string _sig;

		private static readonly List<CanvasGroup> Boxes = new List<CanvasGroup>();

		private static readonly List<Player> Refs = new List<Player>();

		private static void Postfix(UI_Health __instance)
		{
			if (!Cfg.PlayersOn.Value)
			{
				if ((Object)(object)_root != (Object)null && ((Component)_root).gameObject.activeSelf)
				{
					((Component)_root).gameObject.SetActive(false);
				}
			}
			else
			{
				if ((Object)(object)Player.localPlayer == (Object)null || Time.unscaledTime < _next)
				{
					return;
				}
				_next = Time.unscaledTime + 0.25f;
				try
				{
					if ((Object)(object)_root == (Object)null || (Object)(object)_owner != (Object)(object)__instance)
					{
						_owner = __instance;
						_root = CreateRoot(__instance);
						_sig = null;
						if ((Object)(object)_root == (Object)null)
						{
							return;
						}
					}
					if (!((Component)_root).gameObject.activeSelf)
					{
						((Component)_root).gameObject.SetActive(true);
					}
					List<Player> list = new List<Player>();
					if ((Object)(object)PlayerHandler.instance != (Object)null && PlayerHandler.instance.players != null)
					{
						foreach (Player player in PlayerHandler.instance.players)
						{
							if ((Object)(object)player != (Object)null && !player.ai && (Object)(object)player.refs.view != (Object)null)
							{
								list.Add(player);
							}
						}
					}
					list.Sort((Player a, Player b) => Actor(a).CompareTo(Actor(b)));
					string text = "";
					foreach (Player item in list)
					{
						text = text + Actor(item) + "|" + Name(item) + ";";
					}
					if (text != _sig)
					{
						_sig = text;
						Rebuild(__instance, list);
					}
					for (int num = 0; num < Boxes.Count; num++)
					{
						Player val = Refs[num];
						float num2 = (((Object)(object)val == (Object)null || val.data.dead) ? 0.25f : 1f);
						if ((Object)(object)Boxes[num] != (Object)null && !Mathf.Approximately(Boxes[num].alpha, num2))
						{
							Boxes[num].alpha = num2;
						}
					}
				}
				catch (Exception e)
				{
					SafeLog.Once("PlayersHud", e);
				}
			}
		}

		private static RectTransform CreateRoot(UI_Health ui)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0076: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			if ((Object)(object)ui.fill == (Object)null)
			{
				return null;
			}
			RectTransform rectTransform = ((Graphic)ui.fill).rectTransform;
			RectTransform val = (RectTransform)new GameObject("CWPlus_Players", new Type[1] { typeof(RectTransform) }).transform;
			((Transform)val).SetParent((Transform)(object)rectTransform, false);
			float num = Mathf.Clamp01(Cfg.PlayersAlong.Value);
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(num, 0f);
			val.anchorMax = val2;
			val.anchorMin = val2;
			val.pivot = new Vector2(0.5f, 1f);
			val.sizeDelta = new Vector2(10f, 10f);
			Rect rect = rectTransform.rect;
			val.anchoredPosition = new Vector2(0f, (0f - ((Rect)(ref rect)).height) * Cfg.PlayersGap.Value);
			return val;
		}

		private static void Rebuild(UI_Health ui, List<Player> list)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Expected O, but got Unknown
			//IL_0152: 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_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			foreach (CanvasGroup box in Boxes)
			{
				if ((Object)(object)box != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)box).gameObject);
				}
			}
			Boxes.Clear();
			Refs.Clear();
			RectTransform rectTransform = ((Graphic)ui.fill).rectTransform;
			Rect rect = rectTransform.rect;
			float num = Mathf.Max(4f, ((Rect)(ref rect)).height * Cfg.PlayersSize.Value);
			float num2 = num * 0.3f;
			float num3 = (float)(-(list.Count - 1)) * (num + num2) * 0.5f;
			Color color = ((Graphic)ui.fill).color;
			color.a = 1f;
			TMP_FontAsset val = null;
			HotbarSlotUI val2 = Object.FindObjectOfType<HotbarSlotUI>();
			if ((Object)(object)val2 != (Object)null && (Object)(object)val2.m_keybind != (Object)null)
			{
				val = ((TMP_Text)val2.m_keybind).font;
			}
			Vector2 val5 = default(Vector2);
			for (int i = 0; i < list.Count; i++)
			{
				GameObject val3 = new GameObject("P" + i, new Type[1] { typeof(RectTransform) });
				RectTransform val4 = (RectTransform)val3.transform;
				((Transform)val4).SetParent((Transform)(object)_root, false);
				((Vector2)(ref val5))..ctor(0.5f, 1f);
				val4.anchorMax = val5;
				val4.anchorMin = val5;
				val4.pivot = new Vector2(0.5f, 1f);
				val4.sizeDelta = new Vector2(num, num);
				val4.anchoredPosition = new Vector2(num3 + (float)i * (num + num2), 0f);
				ProceduralImage val6 = val3.AddComponent<ProceduralImage>();
				val6.ModifierType = typeof(UniformModifier);
				UniformModifier component = val3.GetComponent<UniformModifier>();
				if ((Object)(object)component != (Object)null)
				{
					component.Radius = num * 0.25f;
				}
				val6.BorderWidth = Mathf.Max(1f, num * 0.09f);
				val6.FalloffDistance = 1f;
				((Graphic)val6).color = color;
				((Graphic)val6).raycastTarget = false;
				CanvasGroup item = val3.AddComponent<CanvasGroup>();
				if ((Object)(object)val != (Object)null)
				{
					GameObject val7 = new GameObject("L", new Type[1] { typeof(RectTransform) });
					RectTransform val8 = (RectTransform)val7.transform;
					((Transform)val8).SetParent((Transform)(object)val4, false);
					val8.anchorMin = Vector2.zero;
					val8.anchorMax = Vector2.one;
					val8.offsetMin = Vector2.zero;
					val8.offsetMax = Vector2.zero;
					TextMeshProUGUI obj = val7.AddComponent<TextMeshProUGUI>();
					((TMP_Text)obj).font = val;
					((TMP_Text)obj).fontSize = num * 0.6f;
					((Graphic)obj).color = color;
					((TMP_Text)obj).alignment = (TextAlignmentOptions)514;
					((TMP_Text)obj).enableWordWrapping = false;
					((Graphic)obj).raycastTarget = false;
					string text = Name(list[i]);
					((TMP_Text)obj).text = (string.IsNullOrEmpty(text) ? "?" : text.Substring(0, 1).ToUpperInvariant());
				}
				Boxes.Add(item);
				Refs.Add(list[i]);
			}
			CurvedUISettings componentInParent = ((Component)_root).GetComponentInParent<CurvedUISettings>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				componentInParent.AddEffectToChildren();
			}
		}

		private static int Actor(Player p)
		{
			if (!((Object)(object)p.refs.view != (Object)null) || p.refs.view.Owner == null)
			{
				return 0;
			}
			return p.refs.view.Owner.ActorNumber;
		}

		private static string Name(Player p)
		{
			if (!((Object)(object)p.refs.view != (Object)null) || p.refs.view.Owner == null)
			{
				return "?";
			}
			return p.refs.view.Owner.NickName;
		}
	}
	[BepInPlugin("enzo.cwplus", "CWPlus", "1.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "enzo.cwplus";

		public const string Name = "CWPlus";

		public const string Version = "1.2.0";

		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Cfg.Bind(((BaseUnityPlugin)this).Config);
			new Harmony("enzo.cwplus").PatchAll();
			GameObject val = new GameObject("CWPlus_Runner");
			Object.DontDestroyOnLoad((Object)val);
			((Object)val).hideFlags = (HideFlags)61;
			val.AddComponent<Runner>();
			Log.LogInfo((object)"CWPlus 1.2.0 chargé");
		}
	}
	internal static class Cfg
	{
		public static ConfigEntry<bool> InventoryOn;

		public static ConfigEntry<KeyCode> KeySlot4;

		public static ConfigEntry<KeyCode> KeySlot5;

		public static ConfigEntry<float> ShiftSlots;

		public static ConfigEntry<bool> BatteryOn;

		public static ConfigEntry<bool> OxygenOn;

		public static ConfigEntry<bool> PlayersOn;

		public static ConfigEntry<float> PlayersAlong;

		public static ConfigEntry<float> PlayersSize;

		public static ConfigEntry<float> PlayersGap;

		public static ConfigEntry<bool> PingOn;

		public static ConfigEntry<KeyCode> PingKey;

		public static ConfigEntry<float> PingDuration;

		public static ConfigEntry<bool> SponsorOn;

		public static ConfigEntry<KeyCode> SponsorKey;

		public static ConfigEntry<bool> EmotesOn;

		public static ConfigEntry<KeyCode> EmotePageKey;

		public static ConfigEntry<bool> CameraOn;

		public static void Bind(ConfigFile c)
		{
			InventoryOn = c.Bind<bool>("1 - Inventaire", "Activer", true, "5 cases d'inventaire. ATTENTION : doit être réglé pareil chez TOUS les joueurs de la partie.");
			KeySlot4 = c.Bind<KeyCode>("1 - Inventaire", "Touche4", (KeyCode)52, "Touche de la 4e case");
			KeySlot5 = c.Bind<KeyCode>("1 - Inventaire", "Touche5", (KeyCode)53, "Touche de la 5e case");
			ShiftSlots = c.Bind<float>("1 - Inventaire", "DecalageBarre", -1f, "Décalage de la barre vers la gauche, en nombre de cases. -1 = automatique. Augmente si la 5e case dépasse de l'écran.");
			BatteryOn = c.Bind<bool>("2 - Batterie", "Activer", true, "Petite barre de batterie sur les cases de l'inventaire");
			OxygenOn = c.Bind<bool>("3 - Oxygene", "Activer", true, "Affiche l'oxygène restant dans la barre d'oxygène");
			PlayersOn = c.Bind<bool>("4 - Joueurs", "Activer", true, "Petites cases avec l'initiale des joueurs (transparente = mort)");
			PlayersAlong = c.Bind<float>("4 - Joueurs", "PositionSurBarre", 0.5f, "Où sous la barre de vie : 0 = début (gauche), 0.5 = milieu, 1 = fin (droite)");
			PlayersSize = c.Bind<float>("4 - Joueurs", "TailleRelative", 0.6f, "Taille des cases par rapport à la hauteur de la barre de vie");
			PlayersGap = c.Bind<float>("4 - Joueurs", "Ecart", 0.3f, "Espace entre la barre de vie et les cases (par rapport à la hauteur de la barre)");
			PingOn = c.Bind<bool>("5 - Ping", "Activer", true, "Ping visible par l'équipe. Tout le monde doit avoir le mod pour voir les pings des autres.");
			PingKey = c.Bind<KeyCode>("5 - Ping", "Touche", (KeyCode)325, "Touche du ping (Mouse2 = clic molette)");
			PingDuration = c.Bind<float>("5 - Ping", "Duree", 5f, "Durée d'affichage d'un ping en secondes");
			SponsorOn = c.Bind<bool>("6 - Sponsor", "Activer", true, "Annuler la mission de sponsor en cours (host uniquement)");
			SponsorKey = c.Bind<KeyCode>("6 - Sponsor", "Touche", (KeyCode)283, "Touche pour annuler la mission");
			EmotesOn = c.Bind<bool>("7 - Emotes", "Activer", true, "Roue des emotes : maintenir la touche d'emote, viser, relâcher");
			EmotePageKey = c.Bind<KeyCode>("7 - Emotes", "TouchePage", (KeyCode)9, "Pendant que la roue est ouverte : passer à la page suivante");
			CameraOn = c.Bind<bool>("8 - Camera", "Activer", true, "Affiche le temps de film restant à côté de REC sur l'écran de la caméra");
		}
	}
	internal static class SafeLog
	{
		private static readonly HashSet<string> Seen = new HashSet<string>();

		public static void Once(string where, Exception e)
		{
			if (Seen.Add(where))
			{
				Plugin.Log.LogError((object)("[" + where + "] " + e));
			}
		}
	}
	internal class Runner : MonoBehaviour
	{
		private class Ping
		{
			public Vector3 Pos;

			public float Until;

			public RectTransform Marker;

			public TextMeshProUGUI MarkerText;

			public RectTransform Edge;

			public RectTransform EdgeArrow;

			public TextMeshProUGUI EdgeText;

			public int LastDist = -1;
		}

		private static Runner _inst;

		private Canvas _canvas;

		private RectTransform _root;

		private TMP_FontAsset _font;

		private Sprite _circle;

		private Sprite _triangle;

		private Sprite _triangleDown;

		private const byte PingEventCode = 87;

		private bool _eventRegistered;

		private readonly Dictionary<int, Ping> _pings = new Dictionary<int, Ping>();

		private readonly List<int> _toRemove = new List<int>();

		private static readonly Color Orange = new Color(1f, 0.55f, 0.1f, 1f);

		private TextMeshProUGUI _notif;

		private float _notifUntil;

		private static string _pendingNotif;

		private RectTransform _wheelRoot;

		private RectTransform _wheelCursor;

		private readonly List<Image> _wheelBgs = new List<Image>();

		private readonly List<RectTransform> _wheelOptions = new List<RectTransform>();

		private int _wheelBuiltKey = -1;

		private TextMeshProUGUI _wheelPageText;

		private void Awake()
		{
			_inst = this;
		}

		public static void Notify(string msg)
		{
			if ((Object)(object)_inst != (Object)null && (Object)(object)_inst._notif != (Object)null)
			{
				((TMP_Text)_inst._notif).text = msg;
				((Component)_inst._notif).gameObject.SetActive(true);
				_inst._notifUntil = Time.unscaledTime + 3f;
			}
			else
			{
				_pendingNotif = msg;
			}
			Plugin.Log.LogInfo((object)msg);
		}

		private void Update()
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				RegisterEvents();
				Player localPlayer = Player.localPlayer;
				if ((Object)(object)localPlayer == (Object)null)
				{
					if ((Object)(object)_root != (Object)null && ((Component)_root).gameObject.activeSelf)
					{
						((Component)_root).gameObject.SetActive(false);
					}
					EmoteWheel.Reset();
				}
				else if (EnsureCanvas())
				{
					if (!((Component)_root).gameObject.activeSelf)
					{
						((Component)_root).gameObject.SetActive(true);
					}
					if (localPlayer.HasLockedInput())
					{
						EmoteWheel.Reset();
					}
					bool flag = GlobalInputHandler.CanTakeInput() && !localPlayer.HasLockedInput();
					if (Cfg.SponsorOn.Value && flag && Input.GetKeyDown(Cfg.SponsorKey.Value))
					{
						Sponsor.TryCancel();
					}
					if (Cfg.PingOn.Value && flag && Input.GetKeyDown(Cfg.PingKey.Value))
					{
						DoPing(localPlayer);
					}
					UpdatePings();
					UpdateWheel();
					UpdateNotif();
				}
			}
			catch (Exception e)
			{
				SafeLog.Once("Runner", e);
			}
		}

		private bool EnsureCanvas()
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: 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_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_canvas != (Object)null)
			{
				return true;
			}
			if ((Object)(object)_font == (Object)null)
			{
				HotbarSlotUI val = Object.FindObjectOfType<HotbarSlotUI>();
				if ((Object)(object)val != (Object)null && (Object)(object)val.m_keybind != (Object)null)
				{
					_font = ((TMP_Text)val.m_keybind).font;
				}
				if ((Object)(object)_font == (Object)null)
				{
					TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
					if (array.Length != 0)
					{
						_font = array[0];
					}
				}
				if ((Object)(object)_font == (Object)null)
				{
					return false;
				}
			}
			_circle = MakeCircleSprite();
			_triangle = MakeTriangleSprite(pointDown: false);
			_triangleDown = MakeTriangleSprite(pointDown: true);
			GameObject val2 = new GameObject("CWPlus_Canvas");
			val2.transform.SetParent(((Component)this).transform, false);
			_canvas = val2.AddComponent<Canvas>();
			_canvas.renderMode = (RenderMode)0;
			_canvas.sortingOrder = 500;
			CanvasScaler obj = val2.AddComponent<CanvasScaler>();
			obj.uiScaleMode = (ScaleMode)1;
			obj.referenceResolution = new Vector2(1920f, 1080f);
			obj.matchWidthOrHeight = 1f;
			_root = NewRect("Root", val2.transform);
			Stretch(_root);
			_notif = NewText("Notif", (Transform)(object)_root, 28f, Orange);
			RectTransform rectTransform = ((TMP_Text)_notif).rectTransform;
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, 1f);
			rectTransform.anchorMax = val3;
			rectTransform.anchorMin = val3;
			rectTransform.pivot = new Vector2(0.5f, 1f);
			rectTransform.anchoredPosition = new Vector2(0f, -140f);
			rectTransform.sizeDelta = new Vector2(1200f, 50f);
			((TMP_Text)_notif).alignment = (TextAlignmentOptions)514;
			((Component)_notif).gameObject.SetActive(false);
			if (_pendingNotif != null)
			{
				string pendingNotif = _pendingNotif;
				_pendingNotif = null;
				Notify(pendingNotif);
			}
			_wheelRoot = NewRect("EmoteWheel", (Transform)(object)_root);
			RectTransform wheelRoot = _wheelRoot;
			RectTransform wheelRoot2 = _wheelRoot;
			((Vector2)(ref val3))..ctor(0.5f, 0.5f);
			wheelRoot2.anchorMax = val3;
			wheelRoot.anchorMin = val3;
			_wheelRoot.sizeDelta = new Vector2(10f, 10f);
			((Component)_wheelRoot).gameObject.SetActive(false);
			return true;
		}

		private static int GetActor(Player p)
		{
			if (!((Object)(object)p.refs.view != (Object)null) || p.refs.view.Owner == null)
			{
				return 0;
			}
			return p.refs.view.Owner.ActorNumber;
		}

		private static string GetName(Player p)
		{
			if (!((Object)(object)p.refs.view != (Object)null) || p.refs.view.Owner == null)
			{
				return "?";
			}
			return p.refs.view.Owner.NickName;
		}

		private void RegisterEvents()
		{
			if (!_eventRegistered && PhotonNetwork.NetworkingClient != null)
			{
				PhotonNetwork.NetworkingClient.EventReceived += OnPhotonEvent;
				_eventRegistered = true;
			}
		}

		private void OnPhotonEvent(EventData ev)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (ev.Code == 87 && Cfg.PingOn.Value && ev.CustomData is float[] array && array.Length >= 4)
			{
				AddPing((int)array[0], new Vector3(array[1], array[2], array[3]));
			}
		}

		private static Camera GetCam()
		{
			if ((Object)(object)MainCamera.instance != (Object)null && (Object)(object)MainCamera.instance.Cam != (Object)null)
			{
				return MainCamera.instance.Cam;
			}
			return Camera.main;
		}

		private void DoPing(Player lp)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_0123: 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_0135: 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_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Expected O, but got Unknown
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			Camera cam = GetCam();
			if ((Object)(object)cam == (Object)null)
			{
				return;
			}
			RaycastHit[] array = Physics.RaycastAll(new Ray(((Component)cam).transform.position, ((Component)cam).transform.forward), 250f, -1, (QueryTriggerInteraction)1);
			float num = float.MaxValue;
			Vector3 val = Vector3.zero;
			bool flag = false;
			RaycastHit[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				RaycastHit val2 = array2[i];
				if (((RaycastHit)(ref val2)).distance >= num || (Object)(object)((RaycastHit)(ref val2)).collider == (Object)null)
				{
					continue;
				}
				Player componentInParent = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<Player>();
				if (!((Object)(object)componentInParent != (Object)null) || !((Object)(object)componentInParent == (Object)(object)lp))
				{
					ItemInstance componentInParent2 = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<ItemInstance>();
					if (!((Object)(object)componentInParent2 != (Object)null) || !((Object)(object)componentInParent2 == (Object)(object)lp.data.currentItem))
					{
						num = ((RaycastHit)(ref val2)).distance;
						val = ((RaycastHit)(ref val2)).point;
						flag = true;
					}
				}
			}
			if (flag)
			{
				int num2 = ((PhotonNetwork.LocalPlayer != null) ? PhotonNetwork.LocalPlayer.ActorNumber : 0);
				AddPing(num2, val);
				if (PhotonNetwork.InRoom && !PhotonNetwork.OfflineMode)
				{
					float[] array3 = new float[4] { num2, val.x, val.y, val.z };
					RaiseEventOptions val3 = new RaiseEventOptions
					{
						Receivers = (ReceiverGroup)0
					};
					PhotonNetwork.RaiseEvent((byte)87, (object)array3, val3, SendOptions.SendReliable);
				}
			}
		}

		private void AddPing(int actor, Vector3 pos)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: 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_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_root == (Object)null))
			{
				if (!_pings.TryGetValue(actor, out var value) || (Object)(object)value.Marker == (Object)null)
				{
					value = new Ping();
					value.Marker = NewRect("Ping" + actor, (Transform)(object)_root);
					value.Marker.sizeDelta = new Vector2(10f, 10f);
					RectTransform obj = NewRect("Arrow", (Transform)(object)value.Marker);
					obj.pivot = new Vector2(0.5f, 0f);
					obj.sizeDelta = new Vector2(18f, 14f);
					obj.anchoredPosition = Vector2.zero;
					Image obj2 = ((Component)obj).gameObject.AddComponent<Image>();
					obj2.sprite = _triangleDown;
					((Graphic)obj2).color = Orange;
					((Graphic)obj2).raycastTarget = false;
					value.MarkerText = NewText("Dist", (Transform)(object)value.Marker, 17f, Orange);
					((TMP_Text)value.MarkerText).rectTransform.pivot = new Vector2(0.5f, 0f);
					((TMP_Text)value.MarkerText).rectTransform.sizeDelta = new Vector2(120f, 22f);
					((TMP_Text)value.MarkerText).rectTransform.anchoredPosition = new Vector2(0f, 15f);
					((TMP_Text)value.MarkerText).alignment = (TextAlignmentOptions)1026;
					value.Edge = NewRect("PingEdge" + actor, (Transform)(object)_root);
					value.Edge.sizeDelta = new Vector2(10f, 10f);
					value.EdgeArrow = NewRect("Arrow", (Transform)(object)value.Edge);
					value.EdgeArrow.sizeDelta = new Vector2(20f, 20f);
					Image obj3 = ((Component)value.EdgeArrow).gameObject.AddComponent<Image>();
					obj3.sprite = _triangle;
					((Graphic)obj3).color = Orange;
					((Graphic)obj3).raycastTarget = false;
					value.EdgeText = NewText("Dist", (Transform)(object)value.Edge, 16f, Orange);
					((TMP_Text)value.EdgeText).rectTransform.sizeDelta = new Vector2(90f, 22f);
					((TMP_Text)value.EdgeText).alignment = (TextAlignmentOptions)514;
					_pings[actor] = value;
				}
				value.Pos = pos;
				value.Until = Time.unscaledTime + Cfg.PingDuration.Value;
				value.LastDist = -1;
			}
		}

		private void UpdatePings()
		{
			//IL_0086: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: 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_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: 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_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: 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)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: 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_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			if (_pings.Count == 0)
			{
				return;
			}
			Camera cam = GetCam();
			float unscaledTime = Time.unscaledTime;
			_toRemove.Clear();
			Vector2 val2 = default(Vector2);
			foreach (KeyValuePair<int, Ping> ping2 in _pings)
			{
				Ping value = ping2.Value;
				if (unscaledTime > value.Until || (Object)(object)cam == (Object)null || (Object)(object)value.Marker == (Object)null)
				{
					_toRemove.Add(ping2.Key);
					continue;
				}
				int num = Mathf.RoundToInt(Vector3.Distance(((Component)cam).transform.position, value.Pos));
				if (num != value.LastDist)
				{
					value.LastDist = num;
					string text = num + " m";
					((TMP_Text)value.MarkerText).text = text;
					((TMP_Text)value.EdgeText).text = text;
				}
				Vector3 val = cam.WorldToScreenPoint(value.Pos);
				bool flag = val.z < 0f;
				if (!flag && val.x >= 0f && val.x <= (float)Screen.width && val.y >= 0f && val.y <= (float)Screen.height)
				{
					if (!((Component)value.Marker).gameObject.activeSelf)
					{
						((Component)value.Marker).gameObject.SetActive(true);
					}
					if (((Component)value.Edge).gameObject.activeSelf)
					{
						((Component)value.Edge).gameObject.SetActive(false);
					}
					((Transform)value.Marker).position = new Vector3(val.x, val.y, 0f);
					continue;
				}
				if (((Component)value.Marker).gameObject.activeSelf)
				{
					((Component)value.Marker).gameObject.SetActive(false);
				}
				if (!((Component)value.Edge).gameObject.activeSelf)
				{
					((Component)value.Edge).gameObject.SetActive(true);
				}
				((Vector2)(ref val2))..ctor((float)Screen.width * 0.5f, (float)Screen.height * 0.5f);
				Vector2 val3 = new Vector2(val.x, val.y) - val2;
				if (flag)
				{
					val3 = -val3;
				}
				if (((Vector2)(ref val3)).sqrMagnitude < 1f)
				{
					val3 = Vector2.down;
				}
				((Vector2)(ref val3)).Normalize();
				float num2 = (float)Screen.height / 1080f;
				float num3 = 40f * num2;
				float num4 = val2.x - num3;
				float num5 = val2.y - num3;
				float num6 = Mathf.Min(num4 / Mathf.Max(Mathf.Abs(val3.x), 0.0001f), num5 / Mathf.Max(Mathf.Abs(val3.y), 0.0001f));
				Vector2 val4 = val2 + val3 * num6;
				((Transform)value.Edge).position = new Vector3(val4.x, val4.y, 0f);
				((Transform)value.EdgeArrow).localRotation = Quaternion.Euler(0f, 0f, Mathf.Atan2(val3.y, val3.x) * 57.29578f - 90f);
				((TMP_Text)value.EdgeText).rectTransform.anchoredPosition = -val3 * 30f;
			}
			foreach (int item in _toRemove)
			{
				Ping ping = _pings[item];
				if ((Object)(object)ping.Marker != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)ping.Marker).gameObject);
				}
				if ((Object)(object)ping.Edge != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)ping.Edge).gameObject);
				}
				_pings.Remove(item);
			}
		}

		private void UpdateWheel()
		{
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			if (!EmoteWheel.Open)
			{
				if (((Component)_wheelRoot).gameObject.activeSelf)
				{
					((Component)_wheelRoot).gameObject.SetActive(false);
				}
				return;
			}
			int num = EmoteWheel.Page * 1000 + EmoteWheel.PageItemCount * 10 + EmoteWheel.PageCount;
			if (num != _wheelBuiltKey)
			{
				BuildWheel(num);
			}
			if (!((Component)_wheelRoot).gameObject.activeSelf)
			{
				((Component)_wheelRoot).gameObject.SetActive(true);
			}
			for (int i = 0; i < _wheelOptions.Count; i++)
			{
				bool flag = i == EmoteWheel.Selected;
				((Graphic)_wheelBgs[i]).color = (flag ? new Color(1f, 0.55f, 0.1f, 0.85f) : new Color(0.1f, 0.1f, 0.1f, 0.75f));
				((Transform)_wheelOptions[i]).localScale = Vector3.one * (flag ? 1.15f : 1f);
			}
			_wheelCursor.anchoredPosition = EmoteWheel.Cursor * 0.6f;
		}

		private void BuildWheel(int key)
		{
			//IL_0085: 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_0126: 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_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			for (int num = ((Transform)_wheelRoot).childCount - 1; num >= 0; num--)
			{
				Object.Destroy((Object)(object)((Component)((Transform)_wheelRoot).GetChild(num)).gameObject);
			}
			_wheelBgs.Clear();
			_wheelOptions.Clear();
			_wheelBuiltKey = key;
			int pageItemCount = EmoteWheel.PageItemCount;
			int num2 = EmoteWheel.Page * 8;
			float num3 = ((pageItemCount <= 4) ? 150f : 190f);
			RectTransform obj = NewRect("Center", (Transform)(object)_wheelRoot);
			obj.sizeDelta = new Vector2(70f, 70f);
			Image obj2 = ((Component)obj).gameObject.AddComponent<Image>();
			obj2.sprite = _circle;
			((Graphic)obj2).color = new Color(0f, 0f, 0f, 0.5f);
			((Graphic)obj2).raycastTarget = false;
			for (int i = 0; i < pageItemCount; i++)
			{
				Item val = EmoteWheel.Learned[num2 + i];
				float num4 = (90f - (float)i * 360f / (float)pageItemCount) * (MathF.PI / 180f);
				RectTransform val2 = NewRect("Opt" + i, (Transform)(object)_wheelRoot);
				val2.sizeDelta = new Vector2(110f, 110f);
				val2.anchoredPosition = new Vector2(Mathf.Cos(num4), Mathf.Sin(num4)) * num3;
				Image val3 = ((Component)val2).gameObject.AddComponent<Image>();
				val3.sprite = _circle;
				((Graphic)val3).raycastTarget = false;
				if ((Object)(object)val != (Object)null && (Object)(object)val.icon != (Object)null)
				{
					RectTransform obj3 = NewRect("Icon", (Transform)(object)val2);
					obj3.sizeDelta = new Vector2(58f, 58f);
					obj3.anchoredPosition = new Vector2(0f, 10f);
					Image obj4 = ((Component)obj3).gameObject.AddComponent<Image>();
					obj4.sprite = val.icon;
					obj4.preserveAspect = true;
					((Graphic)obj4).raycastTarget = false;
				}
				TextMeshProUGUI obj5 = NewText("Name", (Transform)(object)val2, 15f, Color.white);
				((TMP_Text)obj5).rectTransform.sizeDelta = new Vector2(150f, 30f);
				((TMP_Text)obj5).rectTransform.anchoredPosition = new Vector2(0f, -32f);
				((TMP_Text)obj5).alignment = (TextAlignmentOptions)514;
				((TMP_Text)obj5).text = (((Object)(object)val != (Object)null) ? SafeName(val) : "?");
				_wheelBgs.Add(val3);
				_wheelOptions.Add(val2);
			}
			if (EmoteWheel.PageCount > 1)
			{
				_wheelPageText = NewText("Page", (Transform)(object)_wheelRoot, 18f, Color.white);
				((TMP_Text)_wheelPageText).rectTransform.sizeDelta = new Vector2(400f, 30f);
				((TMP_Text)_wheelPageText).rectTransform.anchoredPosition = new Vector2(0f, 0f - (num3 + 85f));
				((TMP_Text)_wheelPageText).alignment = (TextAlignmentOptions)514;
				((TMP_Text)_wheelPageText).text = "Page " + (EmoteWheel.Page + 1) + "/" + EmoteWheel.PageCount + "  [" + ((object)Cfg.EmotePageKey.Value/*cast due to .constrained prefix*/).ToString() + "] page suivante";
			}
			_wheelCursor = NewRect("Cursor", (Transform)(object)_wheelRoot);
			_wheelCursor.sizeDelta = new Vector2(12f, 12f);
			Image obj6 = ((Component)_wheelCursor).gameObject.AddComponent<Image>();
			obj6.sprite = _circle;
			((Graphic)obj6).color = Orange;
			((Graphic)obj6).raycastTarget = false;
		}

		private static string SafeName(Item item)
		{
			try
			{
				string localizedDisplayName = item.GetLocalizedDisplayName();
				if (!string.IsNullOrEmpty(localizedDisplayName))
				{
					return localizedDisplayName;
				}
			}
			catch
			{
			}
			if (!string.IsNullOrEmpty(item.displayName))
			{
				return item.displayName;
			}
			return ((Object)item).name;
		}

		private void UpdateNotif()
		{
			if (((Component)_notif).gameObject.activeSelf && Time.unscaledTime > _notifUntil)
			{
				((Component)_notif).gameObject.SetActive(false);
			}
		}

		private static RectTransform NewRect(string name, Transform parent)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			RectTransform val = (RectTransform)new GameObject(name, new Type[1] { typeof(RectTransform) }).transform;
			((Transform)val).SetParent(parent, false);
			return val;
		}

		private static void Stretch(RectTransform rt)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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)
			rt.anchorMin = Vector2.zero;
			rt.anchorMax = Vector2.one;
			rt.offsetMin = Vector2.zero;
			rt.offsetMax = Vector2.zero;
		}

		private TextMeshProUGUI NewText(string name, Transform parent, float size, Color color)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI obj = ((Component)NewRect(name, parent)).gameObject.AddComponent<TextMeshProUGUI>();
			((TMP_Text)obj).font = _font;
			((TMP_Text)obj).fontSize = size;
			((Graphic)obj).color = color;
			((TMP_Text)obj).enableWordWrapping = false;
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		private static Sprite MakeCircleSprite()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false);
			float num = 32f;
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num2 = Vector2.Distance(new Vector2((float)j + 0.5f, (float)i + 0.5f), new Vector2(num, num));
					float num3 = Mathf.Clamp01(num - num2);
					val.SetPixel(j, i, new Color(1f, 1f, 1f, num3));
				}
			}
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f));
		}

		private static Sprite MakeTriangleSprite(bool pointDown)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_009c: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false);
			for (int i = 0; i < 64; i++)
			{
				int num = (pointDown ? (63 - i) : i);
				float num2 = (float)(64 - num) * 0.5f;
				for (int j = 0; j < 64; j++)
				{
					float num3 = Mathf.Abs((float)j + 0.5f - 32f);
					float num4 = Mathf.Clamp01(num2 - num3);
					val.SetPixel(j, i, new Color(1f, 1f, 1f, num4));
				}
			}
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f));
		}
	}
	internal static class Sponsor
	{
		private struct Offer
		{
			public NetworkDealBase Deal;

			public DealRewardBase Reward;

			public DIFFICULTY Difficulty;
		}

		private static readonly List<Offer> SavedOffers = new List<Offer>();

		internal static void SaveOffers()
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			if (!PhotonNetwork.IsMasterClient || SurfaceNetworkHandler.RoomStats == null)
			{
				return;
			}
			NetworkDealBase[] networkDealsToSelect = SurfaceNetworkHandler.RoomStats.NetworkDealsToSelect;
			if (networkDealsToSelect == null || networkDealsToSelect.Length == 0)
			{
				return;
			}
			SavedOffers.Clear();
			NetworkDealBase[] array = networkDealsToSelect;
			foreach (NetworkDealBase val in array)
			{
				if (val != null)
				{
					SavedOffers.Add(new Offer
					{
						Deal = val,
						Reward = val.reward,
						Difficulty = val.difficulty
					});
				}
			}
		}

		internal static void TryCancel()
		{
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			if (!PhotonNetwork.IsMasterClient)
			{
				Runner.Notify("Seul le host peut annuler un sponsor");
				return;
			}
			NetworkDealBase activeDeal = NetworkDealBoss.activeDeal;
			if (activeDeal == null || (Object)(object)NetworkDealBoss.me == (Object)null)
			{
				Runner.Notify("Aucune mission de sponsor en cours");
				return;
			}
			if (activeDeal.IsDone)
			{
				Runner.Notify("La mission est déjà terminée");
				return;
			}
			NetworkDealBoss.me.RemoveDeal(activeDeal);
			if (SavedOffers.Count > 0 && SurfaceNetworkHandler.RoomStats != null)
			{
				NetworkDealBase[] array = (NetworkDealBase[])(object)new NetworkDealBase[SavedOffers.Count];
				for (int i = 0; i < SavedOffers.Count; i++)
				{
					SavedOffers[i].Deal.Init(SavedOffers[i].Reward, SavedOffers[i].Difficulty);
					array[i] = SavedOffers[i].Deal;
				}
				SurfaceNetworkHandler.RoomStats.SetNetworkDealsToSelect(array);
				SavedOffers.Clear();
				Runner.Notify("Sponsor annulé : choisissez-en un autre sur l'ordinateur");
			}
			else
			{
				Runner.Notify("Sponsor annulé");
			}
		}
	}
	[HarmonyPatch(typeof(NetworkDealBoss), "RPCA_AddDeal")]
	internal static class NetworkDealBoss_RPCA_AddDeal
	{
		private static void Prefix()
		{
			try
			{
				Sponsor.SaveOffers();
			}
			catch (Exception e)
			{
				SafeLog.Once("SponsorSave", e);
			}
		}
	}
}