Decompiled source of LethalSmoking v1.0.0

BepInEx/plugins/LethalSmoking/LethalSmoking.dll

Decompiled 3 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using LethalLib.Modules;
using LethalSmoking.Assets;
using LethalSmoking.Configuration;
using LethalSmoking.Items;
using LethalSmoking.Smoking;
using LethalSmoking.UI;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LethalSmoking")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LethalSmoking")]
[assembly: AssemblyTitle("LethalSmoking")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace LethalSmoking
{
	[BepInPlugin("artemzimoglyad.lethalsmoking", "LethalSmoking", "1.0.0")]
	[BepInDependency("evaisa.lethallib", "1.2.0")]
	[BepInDependency("com.rune580.LethalCompanyInputUtils", "0.7.14")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "artemzimoglyad.lethalsmoking";

		internal const string LibraryGuid = "evaisa.lethallib";

		internal const string InputUtilsGuid = "com.rune580.LethalCompanyInputUtils";

		private ItemAssets assets;

		private Item pack;

		private Item cigarette;

		private Settings settings;

		private void Awake()
		{
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: 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_0278: Expected O, but got Unknown
			try
			{
				settings = new Settings(((BaseUnityPlugin)this).Config);
				if (Settings.DiagnosticLogging)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin loaded from " + ((BaseUnityPlugin)this).Info.Location));
				}
				PackProtocol.InitializeSerialization(((BaseUnityPlugin)this).Logger);
				SmokingAudio.Load(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), ((BaseUnityPlugin)this).Logger);
				assets = new ItemAssets(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location));
				assets.ApplyGameShader();
				if (Settings.DiagnosticLogging)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)("[LethalSmoking] PHASE1_BUNDLE atlas=" + assets.AtlasSize));
				}
				pack = PackRegistration.Register(assets);
				cigarette = CigaretteRegistration.Register(assets);
				OriginalItemAudio.Install(pack, ((BaseUnityPlugin)this).Logger);
				ControlDiagnostics.Install(((BaseUnityPlugin)this).Logger);
				PackProp.CigaretteItem = cigarette;
				PackProp.CigarettePackIcon = assets.CigarettePackIcon;
				SceneManager.sceneLoaded += OnSceneLoaded;
				if (Settings.DiagnosticLogging)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"[LethalSmoking] PHASE1_REGISTERED {pack.itemName} ({pack.creditsWorth} credits) prefab={((Object)pack.spawnPrefab).name}");
					((BaseUnityPlugin)this).Logger.LogInfo((object)"[LethalSmoking] PHASE2_REGISTERED cigarette and pack container");
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("[LethalSmoking] Item initialization failed: " + ex));
				return;
			}
			try
			{
				if (Settings.DiagnosticLogging)
				{
					PluginInfo val = Chainloader.PluginInfos["com.rune580.LethalCompanyInputUtils"];
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"InputUtils loaded: {val.Metadata.Version} ({val.Location})");
				}
				ExpeditionEffects.Initialize(settings);
				SmokingProtocol.Initialize(assets.Cigarette, settings, ((BaseUnityPlugin)this).Logger);
				try
				{
					ExpeditionPatches.Install();
				}
				catch (Exception ex2)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("[LethalSmoking] Expedition patch initialization failed: " + ex2));
				}
				try
				{
					AmbientSmokeManager.Install(settings, ((BaseUnityPlugin)this).Logger);
				}
				catch (Exception ex3)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("[LethalSmoking] Ambient smoke initialization failed: " + ex3));
				}
				GameObject val2 = new GameObject("LethalSmoking.Input")
				{
					hideFlags = (HideFlags)61
				};
				Object.DontDestroyOnLoad((Object)val2);
				val2.AddComponent<SmokeInput>().Initialize(((BaseUnityPlugin)this).Logger);
			}
			catch (Exception ex4)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("[LethalSmoking] Smoking initialization failed: " + ex4));
			}
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			assets.ApplyGameShader();
			if (!Object.op_Implicit((Object)(object)pack.pocketSFX) || settings.LogShopCheck.Value)
			{
				((MonoBehaviour)this).StartCoroutine(PrepareShop());
			}
		}

		private IEnumerator PrepareShop()
		{
			yield return null;
			Terminal val = Object.FindObjectOfType<Terminal>();
			if ((Object)(object)val == (Object)null || val.buyableItemsList == null)
			{
				yield break;
			}
			if (!Object.op_Implicit((Object)(object)pack.pocketSFX))
			{
				Item val2 = Array.Find(val.buyableItemsList, (Item item) => Object.op_Implicit((Object)(object)item) && item.itemId == 7 && Object.op_Implicit((Object)(object)item.pocketSFX));
				if (Object.op_Implicit((Object)(object)val2))
				{
					pack.pocketSFX = val2.pocketSFX;
					cigarette.pocketSFX = val2.pocketSFX;
				}
			}
			if (settings.LogShopCheck.Value)
			{
				int num = Array.IndexOf(val.buyableItemsList, pack);
				if (num >= 0)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"[LethalSmoking] PHASE1_SHOP index={num} price={pack.creditsWorth}");
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"[LethalSmoking] Pack not present in this terminal at scene startup.");
				}
			}
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
			PackProtocol.Unregister();
		}
	}
}
namespace LethalSmoking.UI
{
	internal sealed class PackMenu : MonoBehaviour
	{
		private static readonly Color Border = Color32.op_Implicit(new Color32((byte)94, (byte)39, (byte)52, (byte)220));

		private static readonly Color HoverBorder = Color32.op_Implicit(new Color32((byte)174, (byte)103, (byte)119, (byte)245));

		private const int NoHit = -1;

		private const int CloseHit = -2;

		private const float ShowDuration = 0.2f;

		private const float MenuScale = 0.8f;

		private readonly Image[] frames = (Image[])(object)new Image[5];

		private readonly Image[] icons = (Image[])(object)new Image[5];

		private readonly Vector3[] corners = (Vector3[])(object)new Vector3[4];

		private PackProp pack;

		private PlayerControllerB player;

		private HUDManager hud;

		private Canvas panelCanvas;

		private RectTransform panel;

		private RectTransform closeHitArea;

		private Image closeFrame;

		private readonly Image[] closeStrokes = (Image[])(object)new Image[2];

		private CanvasGroup panelOpacity;

		private Coroutine showAnimation;

		private HUDElement inventory;

		private float originalInventoryTarget;

		private float fittedScale = 1f;

		private float showScale = 1f;

		private Image dragIcon;

		private InputAction activateItem;

		private Vector2 pressPosition;

		private Vector2 lastHoverPosition = new Vector2(float.NaN, float.NaN);

		private Vector2 fittedCanvasSize;

		private ulong pressedItemId;

		private int pressedSlot = -1;

		private int hoverSlot = -1;

		private bool dragging;

		private bool ownsMenu;

		private bool suppressOpeningClick;

		private int openedFrame;

		internal bool IsInteractionActive
		{
			get
			{
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				if (ownsMenu && Object.op_Implicit((Object)(object)player) && player.inSpecialMenu && Object.op_Implicit((Object)(object)hud) && (int)hud.currentSpecialMenu == 0 && !player.inTerminalMenu)
				{
					if (Object.op_Implicit((Object)(object)player.quickMenuManager))
					{
						return !player.quickMenuManager.isMenuOpen;
					}
					return true;
				}
				return false;
			}
		}

		internal static PackMenu Open(PackProp pack, PlayerControllerB player, Sprite cigarette)
		{
			HUDManager instance = HUDManager.Instance;
			if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)player) || player.inSpecialMenu || !Object.op_Implicit((Object)(object)cigarette) || player.ItemSlots == null || instance.itemSlotIconFrames == null || instance.itemSlotIconFrames.Length == 0 || !Object.op_Implicit((Object)(object)instance.itemSlotIconFrames[0]))
			{
				return null;
			}
			InputActionAsset actions = InputSystem.actions;
			InputAction val = ((actions != null) ? actions.FindAction("ActivateItem", false) : null);
			Canvas componentInParent = ((Component)instance.itemSlotIconFrames[0]).GetComponentInParent<Canvas>();
			if (val == null || !Object.op_Implicit((Object)(object)componentInParent) || !((Behaviour)componentInParent).isActiveAndEnabled)
			{
				return null;
			}
			RectTransform val2 = MakeRect(((Component)componentInParent).transform, "Cibarettes container");
			PackMenu packMenu = ((Component)val2).gameObject.AddComponent<PackMenu>();
			packMenu.pack = pack;
			packMenu.player = player;
			packMenu.hud = instance;
			packMenu.panel = val2;
			packMenu.panelCanvas = componentInParent;
			try
			{
				packMenu.Build(cigarette);
				packMenu.EnterInteraction(val);
				return packMenu;
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("[LethalSmoking] Unable to open Cibarettes interface: " + ex));
				packMenu.Close();
				return null;
			}
		}

		private void Build(Sprite cigarette)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_009a: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: 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_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: 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_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0409: Unknown result type (might be due to invalid IL or missing references)
			//IL_0410: Unknown result type (might be due to invalid IL or missing references)
			//IL_044f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0470: Unknown result type (might be due to invalid IL or missing references)
			//IL_0485: Unknown result type (might be due to invalid IL or missing references)
			BeltBagInventoryUI componentInChildren = ((Component)hud).GetComponentInChildren<BeltBagInventoryUI>(true);
			RectTransform val = (RectTransform)((Object.op_Implicit((Object)(object)componentInChildren) && componentInChildren.inventorySlots != null && componentInChildren.inventorySlots.Length != 0) ? /*isinst with value type is only supported in some contexts*/: null);
			float num;
			if (!Object.op_Implicit((Object)(object)val))
			{
				num = 68f;
			}
			else
			{
				Rect rect = val.rect;
				num = Mathf.Clamp(((Rect)(ref rect)).width, 56f, 82f);
			}
			float num2 = num;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(num2 * 0.87f, num2 * 0.58f);
			float num3 = val2.x * 0.75f;
			float num4 = val2.x + num3;
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(val2.x * 0.68f, val2.x * 0.46f);
			float num5 = val3.y * 0.23f;
			float num6 = val2.y + 42f;
			float num7 = num6 + Mathf.Max(0f, val3.y + num5 + 5f - 21f);
			RectTransform obj = panel;
			RectTransform obj2 = panel;
			Vector2 val4 = default(Vector2);
			((Vector2)(ref val4))..ctor(0.5f, 0.465f);
			obj2.anchorMax = val4;
			obj.anchorMin = val4;
			panel.pivot = new Vector2(0.5f, num6 * 0.5f / num7);
			panel.sizeDelta = new Vector2(num4 * 5f - num3 + 34f, num7);
			((Transform)panel).SetAsLastSibling();
			FitPanel();
			panelOpacity = ((Component)panel).gameObject.AddComponent<CanvasGroup>();
			AddImage(panel, Color32.op_Implicit(new Color32((byte)84, (byte)40, (byte)51, (byte)55)), null, warped: true);
			RectTransform val5 = MakeRect((Transform)(object)panel, "Panel outline");
			Stretch(val5, 0f);
			AddImage(val5, Color32.op_Implicit(new Color32((byte)83, (byte)33, (byte)48, (byte)208)));
			((Component)val5).gameObject.AddComponent<PackSlotBorder>().Thickness = 2.25f;
			((Component)val5).gameObject.AddComponent<PackPanelPerspective>().Panel = panel;
			for (int i = 0; i < 5; i++)
			{
				RectTransform val6 = MakeRect((Transform)(object)panel, $"Pack slot {i + 1}");
				val4 = (val6.anchorMin = (val6.anchorMax = panel.pivot));
				val6.anchoredPosition = new Vector2((float)(i - 2) * num4, 0f);
				val6.sizeDelta = val2;
				frames[i] = AddImage(val6, Border);
				RectTransform rect2 = MakeRect((Transform)(object)val6, "Slot fill");
				Stretch(rect2, 1f);
				((Component)frames[i]).gameObject.AddComponent<PackSlotBorder>().Thickness = 1.95f;
				((Component)val6).gameObject.AddComponent<PackPanelPerspective>().Panel = panel;
				AddImage(rect2, new Color(0.22f, 0.13f, 0.15f, 0.025f), null, warped: true);
				RectTransform rect3 = MakeRect((Transform)(object)val6, "Cigarette icon");
				Stretch(rect3, 2f);
				icons[i] = AddImage(rect3, Color.white, cigarette, warped: true);
			}
			closeHitArea = MakeRect((Transform)(object)panel, "Close pack");
			val4 = (closeHitArea.anchorMin = (closeHitArea.anchorMax = Vector2.one));
			closeHitArea.sizeDelta = val3;
			closeHitArea.anchoredPosition = -(val3 * 0.5f + Vector2.one * num5);
			closeFrame = AddImage(closeHitArea, Border);
			((Component)closeHitArea).gameObject.AddComponent<PackSlotBorder>().Thickness = 1.75f;
			((Component)closeHitArea).gameObject.AddComponent<PackPanelPerspective>().Panel = panel;
			float num8 = Mathf.Atan2(val3.y, val3.x) * 57.29578f;
			for (int j = 0; j < closeStrokes.Length; j++)
			{
				RectTransform val9 = MakeRect((Transform)(object)closeHitArea, "Close stroke");
				val9.sizeDelta = new Vector2(((Vector2)(ref val3)).magnitude * 0.64f, 1.95f);
				((Transform)val9).localRotation = Quaternion.Euler(0f, 0f, (j == 0) ? num8 : (0f - num8));
				closeStrokes[j] = AddImage(val9, Border, null, warped: true);
			}
			RectTransform val10 = MakeRect(((Component)panelCanvas).transform, "Dragged cigarette");
			val10.sizeDelta = val2;
			((Transform)val10).localScale = Vector3.one * fittedScale;
			dragIcon = AddImage(val10, Color.white, cigarette);
			((Behaviour)dragIcon).enabled = false;
			RefreshSlots();
		}

		private void EnterInteraction(InputAction activate)
		{
			if (Object.op_Implicit((Object)(object)ShipBuildModeManager.Instance))
			{
				ShipBuildModeManager.Instance.CancelBuildMode(true);
			}
			ownsMenu = true;
			player.inSpecialMenu = true;
			((Behaviour)player.cursorIcon).enabled = false;
			((TMP_Text)player.cursorTip).text = string.Empty;
			Cursor.lockState = (CursorLockMode)0;
			Cursor.visible = true;
			SetCursor(hud.handOpenCursorTex);
			openedFrame = Time.frameCount;
			Mouse current = Mouse.current;
			suppressOpeningClick = current != null && current.leftButton.isPressed;
			activateItem = activate;
			activateItem.performed += ActivateWhileOpen;
			inventory = hud.Inventory;
			if (inventory != null && Object.op_Implicit((Object)(object)inventory.canvasGroup))
			{
				originalInventoryTarget = inventory.targetAlpha;
				ShowInventory();
			}
			showAnimation = ((MonoBehaviour)this).StartCoroutine(AnimateOpening());
			ControlDiagnostics.Menu("open", player, pack);
		}

		private IEnumerator AnimateOpening()
		{
			for (float elapsed = 0f; elapsed < 0.2f; elapsed += Time.unscaledDeltaTime)
			{
				ApplyOpeningProgress(elapsed / 0.2f);
				yield return null;
			}
			ApplyOpeningProgress(1f);
			showAnimation = null;
		}

		private void ApplyOpeningProgress(float progress)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			showScale = ((progress < 0.6f) ? Mathf.SmoothStep(0.93f, 1.04f, progress / 0.6f) : Mathf.SmoothStep(1.04f, 1f, (progress - 0.6f) / 0.39999998f));
			((Transform)panel).localScale = Vector3.one * (fittedScale * showScale);
			panelOpacity.alpha = Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(progress / 0.6f));
			lastHoverPosition = new Vector2(float.NaN, float.NaN);
		}

		private void LateUpdate()
		{
			if (inventory != null && inventory.targetAlpha < 1f && IsInteractionActive && !player.isPlayerDead)
			{
				ShowInventory();
			}
		}

		private void ShowInventory()
		{
			if (inventory.fadeCoroutine != null)
			{
				((MonoBehaviour)hud).StopCoroutine(inventory.fadeCoroutine);
				inventory.fadeCoroutine = null;
			}
			hud.PingHUDElement(inventory, 0f, 1f, 1f);
		}

		private void ActivateWhileOpen(CallbackContext context)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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)
			if (!IsInteractionActive || Time.frameCount == openedFrame)
			{
				return;
			}
			InputDevice device = ((CallbackContext)(ref context)).control.device;
			Mouse val = (Mouse)(object)((device is Mouse) ? device : null);
			if (val != null && (object)((CallbackContext)(ref context)).control == val.leftButton)
			{
				Vector2 val2 = ((InputControl<Vector2>)(object)((Pointer)val).position).ReadValue();
				if (pressedSlot != -1 || FindSlot(val2) != -1 || Contains(panel, val2, warped: true))
				{
					return;
				}
			}
			pack.EndInteraction();
		}

		private void Update()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			if (!IsInteractionActive || Mouse.current == null)
			{
				return;
			}
			FitPanel();
			Mouse current = Mouse.current;
			Vector2 val = ((InputControl<Vector2>)(object)((Pointer)current).position).ReadValue();
			if (val != lastHoverPosition)
			{
				lastHoverPosition = val;
				UpdateHover(FindSlot(val));
			}
			if (suppressOpeningClick)
			{
				if (!current.leftButton.isPressed)
				{
					suppressOpeningClick = false;
				}
				return;
			}
			if (current.leftButton.wasPressedThisFrame)
			{
				PressPointer(val);
			}
			if (pressedSlot != -1)
			{
				MovePointer(val);
				if (current.leftButton.wasReleasedThisFrame)
				{
					ReleasePointer(val);
				}
				else if (!current.leftButton.isPressed)
				{
					ResetPointer();
				}
			}
		}

		private void FitPanel()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_002f: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_0120: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: 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)
			//IL_0175: 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_017e: 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_0198: 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_01a2: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = (RectTransform)((Transform)panel).parent;
			Rect rect = val.rect;
			Vector2 size = ((Rect)(ref rect)).size;
			if (size == fittedCanvasSize || size.x <= 0f || size.y <= 0f)
			{
				return;
			}
			fittedCanvasSize = size;
			rect = panel.rect;
			float num = -2f * ((Rect)(ref rect)).yMin;
			float num2 = Mathf.Min(1f, size.x * 0.88f / panel.sizeDelta.x);
			num2 = Mathf.Min(num2, size.y * 0.17f / num);
			fittedScale = num2 * 0.8f;
			((Transform)panel).localScale = Vector3.one * (fittedScale * showScale);
			if (Object.op_Implicit((Object)(object)dragIcon))
			{
				((Transform)((Graphic)dragIcon).rectTransform).localScale = Vector3.one * fittedScale;
			}
			rect = val.rect;
			float num3 = ((Rect)(ref rect)).yMin + size.y * panel.anchorMin.y;
			float num4 = float.NegativeInfinity;
			Image[] itemSlotIconFrames = hud.itemSlotIconFrames;
			foreach (Image val2 in itemSlotIconFrames)
			{
				if (Object.op_Implicit((Object)(object)val2) && ((Component)val2).gameObject.activeInHierarchy)
				{
					RectTransform rectTransform = ((Graphic)val2).rectTransform;
					float num5 = num4;
					rect = rectTransform.rect;
					float x = ((Rect)(ref rect)).center.x;
					rect = rectTransform.rect;
					num4 = Mathf.Max(num5, ((Transform)val).InverseTransformPoint(((Transform)rectTransform).TransformPoint(new Vector3(x, ((Rect)(ref rect)).yMax))).y);
				}
			}
			float num6 = num4 + num * fittedScale * 0.53f + 8f;
			panel.anchoredPosition = Vector2.up * Mathf.Max(0f, num6 - num3);
			lastHoverPosition = new Vector2(float.NaN, float.NaN);
		}

		private void PressPointer(Vector2 position)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			if (pressedSlot != -1)
			{
				return;
			}
			int num = FindSlot(position);
			switch (num)
			{
			default:
				if (pack.Busy)
				{
					return;
				}
				break;
			case -1:
				return;
			case -2:
				break;
			}
			if (IsPackSlot(num))
			{
				if ((pack.Mask & (1 << num)) == 0)
				{
					return;
				}
				pressedItemId = 0uL;
			}
			else if (num != -2)
			{
				int num2 = num - 5;
				if (!(player.ItemSlots[num2] is CigaretteProp cigaretteProp) || !Object.op_Implicit((Object)(object)cigaretteProp) || !((NetworkBehaviour)cigaretteProp).IsSpawned)
				{
					return;
				}
				pressedItemId = ((NetworkBehaviour)cigaretteProp).NetworkObjectId;
			}
			pressedSlot = num;
			pressPosition = position;
		}

		private void MovePointer(Vector2 position)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			if (pressedSlot == -2)
			{
				return;
			}
			int num = (Object.op_Implicit((Object)(object)EventSystem.current) ? EventSystem.current.pixelDragThreshold : 6);
			if (!dragging)
			{
				Vector2 val = position - pressPosition;
				if (((Vector2)(ref val)).sqrMagnitude >= (float)(num * num))
				{
					dragging = true;
					((Behaviour)dragIcon).enabled = true;
					SetCursor(hud.handClosedCursorTex);
					RefreshSlots();
				}
			}
			Vector3 position2 = default(Vector3);
			if (dragging && RectTransformUtility.ScreenPointToWorldPointInRectangle((RectTransform)((Component)dragIcon).transform.parent, position, CanvasCamera(panelCanvas), ref position2))
			{
				((Transform)((Graphic)dragIcon).rectTransform).position = position2;
			}
		}

		private void ReleasePointer(Vector2 position)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			int num = pressedSlot;
			int num2 = FindSlot(position);
			bool flag = dragging;
			ulong itemId = pressedItemId;
			ResetPointer();
			switch (num)
			{
			case -2:
				if (num2 == -2)
				{
					pack.EndInteraction();
				}
				return;
			case -1:
				return;
			}
			if (pack.Busy)
			{
				return;
			}
			if (flag)
			{
				if (num2 >= 0 && IsPackSlot(num) != IsPackSlot(num2))
				{
					bool flag2 = IsPackSlot(num);
					pack.Transfer(flag2, flag2 ? num : num2, (flag2 ? num2 : num) - 5, itemId);
				}
				return;
			}
			if (num != num2)
			{
				return;
			}
			if (IsPackSlot(num))
			{
				if (PackProp.FirstFreeSlot(player) >= 0)
				{
					pack.Transfer(take: true, num, -1, 0uL);
				}
				return;
			}
			for (int i = 0; i < 5; i++)
			{
				if ((pack.Mask & (1 << i)) == 0)
				{
					pack.Transfer(take: false, i, num - 5, itemId);
					break;
				}
			}
		}

		private void ResetPointer()
		{
			pressedSlot = -1;
			dragging = false;
			if (Object.op_Implicit((Object)(object)dragIcon))
			{
				((Behaviour)dragIcon).enabled = false;
			}
			if (Object.op_Implicit((Object)(object)hud))
			{
				SetCursor(hud.handOpenCursorTex);
			}
			RefreshSlots();
		}

		private int FindSlot(Vector2 position)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			if (Contains(closeHitArea, position, warped: true))
			{
				return -2;
			}
			for (int i = 0; i < 5; i++)
			{
				if (Contains(((Graphic)frames[i]).rectTransform, position, warped: true))
				{
					return i;
				}
			}
			int num = Mathf.Min(player.ItemSlots.Length, hud.itemSlotIconFrames.Length);
			for (int j = 0; j < num; j++)
			{
				Image val = hud.itemSlotIconFrames[j];
				if (Object.op_Implicit((Object)(object)val) && ((Component)val).gameObject.activeInHierarchy && Contains(((Graphic)val).rectTransform, position, warped: false))
				{
					return 5 + j;
				}
			}
			return -1;
		}

		private bool Contains(RectTransform rect, Vector2 point, bool warped)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			Camera val = CanvasCamera(warped ? panelCanvas : ((Component)rect).GetComponentInParent<Canvas>());
			if (!warped)
			{
				return RectTransformUtility.RectangleContainsScreenPoint(rect, point, val);
			}
			rect.GetLocalCorners(corners);
			Vector2 val2 = RectTransformUtility.WorldToScreenPoint(val, PackPanelPerspective.ProjectWorld(panel, ((Transform)rect).TransformPoint(corners[3])));
			float num = 0f;
			for (int i = 0; i < corners.Length; i++)
			{
				Vector2 val3 = RectTransformUtility.WorldToScreenPoint(val, PackPanelPerspective.ProjectWorld(panel, ((Transform)rect).TransformPoint(corners[i])));
				Vector2 val4 = val3 - val2;
				Vector2 val5 = point - val2;
				float num2 = val4.x * val5.y - val4.y * val5.x;
				if (num2 * num < 0f)
				{
					return false;
				}
				if (num2 != 0f)
				{
					num = Mathf.Sign(num2);
				}
				val2 = val3;
			}
			return num != 0f;
		}

		private Camera CanvasCamera(Canvas canvas)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)canvas) && (int)canvas.renderMode != 0)
			{
				if (!Object.op_Implicit((Object)(object)canvas.worldCamera))
				{
					return hud.UICamera;
				}
				return canvas.worldCamera;
			}
			return null;
		}

		private void UpdateHover(int slot)
		{
			//IL_0024: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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)
			if (hoverSlot == slot)
			{
				return;
			}
			if (IsPackSlot(hoverSlot))
			{
				((Graphic)frames[hoverSlot]).color = Border;
			}
			if (hoverSlot == -2)
			{
				((Graphic)closeFrame).color = Border;
				Image[] array = closeStrokes;
				for (int i = 0; i < array.Length; i++)
				{
					((Graphic)array[i]).color = Border;
				}
			}
			hoverSlot = slot;
			if (IsPackSlot(hoverSlot))
			{
				((Graphic)frames[hoverSlot]).color = HoverBorder;
			}
			if (hoverSlot == -2)
			{
				((Graphic)closeFrame).color = HoverBorder;
				Image[] array = closeStrokes;
				for (int i = 0; i < array.Length; i++)
				{
					((Graphic)array[i]).color = HoverBorder;
				}
			}
		}

		internal void RefreshSlots()
		{
			for (int i = 0; i < 5; i++)
			{
				if (Object.op_Implicit((Object)(object)icons[i]))
				{
					((Behaviour)icons[i]).enabled = (pack.Mask & (1 << i)) != 0 && (!dragging || pressedSlot != i);
				}
			}
		}

		internal void Close()
		{
			try
			{
				ReleaseInteraction();
			}
			finally
			{
				((Component)this).gameObject.SetActive(false);
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		private void OnDisable()
		{
			ReleaseInteraction();
		}

		private void ReleaseInteraction()
		{
			bool flag = ownsMenu;
			ownsMenu = false;
			if (activateItem != null)
			{
				activateItem.performed -= ActivateWhileOpen;
				activateItem = null;
			}
			try
			{
				if (showAnimation != null)
				{
					((MonoBehaviour)this).StopCoroutine(showAnimation);
					showAnimation = null;
				}
				if (Object.op_Implicit((Object)(object)dragIcon))
				{
					((Behaviour)dragIcon).enabled = false;
					Object.Destroy((Object)(object)((Component)dragIcon).gameObject);
					dragIcon = null;
				}
				if (inventory != null && Object.op_Implicit((Object)(object)hud) && inventory.targetAlpha == 1f)
				{
					if (((Behaviour)hud).isActiveAndEnabled && Object.op_Implicit((Object)(object)player) && !player.isPlayerDead && !player.inTerminalMenu && flag)
					{
						hud.PingHUDElement(inventory, 1.5f, 1f, 0.13f);
					}
					else
					{
						hud.PingHUDElement(inventory, 0f, originalInventoryTarget, originalInventoryTarget);
					}
				}
			}
			finally
			{
				inventory = null;
				if (flag)
				{
					try
					{
						ReleasePlayerInput();
					}
					finally
					{
						ControlDiagnostics.Menu("close", player, pack);
					}
				}
			}
		}

		private void ReleasePlayerInput()
		{
			//IL_002d: 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)
			if ((Object.op_Implicit((Object)(object)player) && !player.inSpecialMenu) || (Object.op_Implicit((Object)(object)hud) && (int)hud.currentSpecialMenu != 0))
			{
				return;
			}
			if (Object.op_Implicit((Object)(object)player) && (player.inTerminalMenu || (Object.op_Implicit((Object)(object)player.quickMenuManager) && player.quickMenuManager.isMenuOpen)))
			{
				player.inSpecialMenu = false;
				return;
			}
			if (Object.op_Implicit((Object)(object)player) && Object.op_Implicit((Object)(object)hud) && Object.op_Implicit((Object)(object)StartOfRound.Instance) && Object.op_Implicit((Object)(object)EventSystem.current))
			{
				player.SetInSpecialMenu(false, (SpecialHUDMenu)0);
				return;
			}
			if (Object.op_Implicit((Object)(object)player))
			{
				player.inSpecialMenu = false;
			}
			Cursor.lockState = (CursorLockMode)1;
			Cursor.visible = false;
			Cursor.SetCursor((Texture2D)null, Vector2.zero, (CursorMode)0);
		}

		private static bool IsPackSlot(int slot)
		{
			return (uint)slot < 5u;
		}

		private void SetCursor(Texture2D texture)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			hud.SetMouseCursorSprite(texture, new Vector2(16f, 16f));
		}

		private Image AddImage(RectTransform rect, Color color, Sprite icon = null, bool warped = false)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			Image obj = ((Component)rect).gameObject.AddComponent<Image>();
			((Graphic)obj).color = color;
			obj.sprite = icon;
			obj.preserveAspect = Object.op_Implicit((Object)(object)icon);
			((Graphic)obj).raycastTarget = false;
			if (warped)
			{
				((Component)rect).gameObject.AddComponent<PackPanelPerspective>().Panel = panel;
			}
			return obj;
		}

		private static RectTransform MakeRect(Transform parent, string name)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = new GameObject(name, new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
			((Transform)component).SetParent(parent, false);
			return component;
		}

		private static void Stretch(RectTransform rect, float margin)
		{
			//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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			rect.anchorMin = Vector2.zero;
			rect.anchorMax = Vector2.one;
			rect.offsetMin = Vector2.one * margin;
			rect.offsetMax = -Vector2.one * margin;
		}
	}
	internal sealed class PackPanelPerspective : BaseMeshEffect
	{
		private static readonly Quaternion Tilt = Quaternion.AngleAxis(13f, Vector3.right);

		internal RectTransform Panel;

		internal static Vector3 ProjectWorld(RectTransform panel, Vector3 world)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Transform)panel).InverseTransformPoint(world);
			Vector3 val2 = Tilt * new Vector3(val.x, val.y, 0f);
			float num = 680f / (680f + val2.z);
			return ((Transform)panel).TransformPoint(new Vector3(val2.x * num, val2.y * num, val.z));
		}

		public override void ModifyMesh(VertexHelper vertices)
		{
			//IL_0010: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)Panel))
			{
				UIVertex val = default(UIVertex);
				for (int i = 0; i < vertices.currentVertCount; i++)
				{
					vertices.PopulateUIVertex(ref val, i);
					val.position = ((Component)this).transform.InverseTransformPoint(ProjectWorld(Panel, ((Component)this).transform.TransformPoint(val.position)));
					vertices.SetUIVertex(val, i);
				}
			}
		}
	}
	internal sealed class PackSlotBorder : BaseMeshEffect
	{
		internal float Thickness = 1.25f;

		public override void ModifyMesh(VertexHelper vertices)
		{
			//IL_000b: 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_0030: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			if (vertices.currentVertCount != 0)
			{
				UIVertex val = default(UIVertex);
				vertices.PopulateUIVertex(ref val, 0);
				vertices.Clear();
				Rect rect = ((RectTransform)((Component)this).transform).rect;
				float thickness = Thickness;
				AddStrip(vertices, val.color, ((Rect)(ref rect)).xMin, ((Rect)(ref rect)).yMin, ((Rect)(ref rect)).xMin + thickness, ((Rect)(ref rect)).yMax);
				AddStrip(vertices, val.color, ((Rect)(ref rect)).xMax - thickness, ((Rect)(ref rect)).yMin, ((Rect)(ref rect)).xMax, ((Rect)(ref rect)).yMax);
				AddStrip(vertices, val.color, ((Rect)(ref rect)).xMin + thickness, ((Rect)(ref rect)).yMin, ((Rect)(ref rect)).xMax - thickness, ((Rect)(ref rect)).yMin + thickness);
				AddStrip(vertices, val.color, ((Rect)(ref rect)).xMin + thickness, ((Rect)(ref rect)).yMax - thickness, ((Rect)(ref rect)).xMax - thickness, ((Rect)(ref rect)).yMax);
			}
		}

		private static void AddStrip(VertexHelper mesh, Color32 color, float left, float bottom, float right, float top)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			int currentVertCount = mesh.currentVertCount;
			mesh.AddVert(new Vector3(left, bottom), color, Vector4.op_Implicit(Vector2.zero));
			mesh.AddVert(new Vector3(left, top), color, Vector4.op_Implicit(Vector2.zero));
			mesh.AddVert(new Vector3(right, top), color, Vector4.op_Implicit(Vector2.zero));
			mesh.AddVert(new Vector3(right, bottom), color, Vector4.op_Implicit(Vector2.zero));
			mesh.AddTriangle(currentVertCount, currentVertCount + 1, currentVertCount + 2);
			mesh.AddTriangle(currentVertCount + 2, currentVertCount + 3, currentVertCount);
		}
	}
}
namespace LethalSmoking.Smoking
{
	internal static class AmbientSmokeCamera
	{
		private struct FogState
		{
			internal Fog Fog;

			internal bool Enabled;

			internal bool Volumetric;

			internal float MeanFreePath;
		}

		private static readonly Dictionary<Camera, FogState> overrides = new Dictionary<Camera, FogState>();

		internal static void Install()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.Method(typeof(HDCamera), "UpdateVolumeAndPhysicalParameters", (Type[])null, (Type[])null);
			HarmonyMethod val = new HarmonyMethod(typeof(AmbientSmokeCamera), "EnableForSmoke", (Type[])null);
			HarmonyMethod val2 = new HarmonyMethod(typeof(AmbientSmokeCamera), "RestoreBeforeUpdate", (Type[])null);
			Harmony val3 = new Harmony("artemzimoglyad.lethalsmoking.ambient-camera");
			val3.Patch((MethodBase)methodInfo, val2, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			string[] commandLineArgs = Environment.GetCommandLineArgs();
			if (Array.IndexOf(commandLineArgs, "-ls-ambient-diagnostics") >= 0 || Array.IndexOf(commandLineArgs, "-ls-ambient-percent") >= 0)
			{
				MethodInfo methodInfo2 = AccessTools.Method(typeof(HDRenderPipeline), "PrepareVisibleLocalVolumetricFogList", (Type[])null, (Type[])null);
				val3.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(typeof(AmbientSmokeCamera), "TraceVisible", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			RenderPipelineManager.endCameraRendering += RestoreAfterRender;
		}

		private static void TraceVisible(HDCamera __0, List<LocalVolumetricFog> ___m_VisibleLocalVolumetricFogVolumes)
		{
			AmbientSmokeManager.TraceVisible(__0.camera, ___m_VisibleLocalVolumetricFogVolumes);
		}

		private static void EnableForSmoke(HDCamera __instance)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Camera camera = __instance.camera;
			if (!Object.op_Implicit((Object)(object)camera) || (int)camera.cameraType != 1 || !AmbientSmokeManager.HasFogNear(((Component)camera).transform.position))
			{
				return;
			}
			FrameSettings frameSettings = __instance.frameSettings;
			bool flag = ((FrameSettings)(ref frameSettings)).IsEnabled((FrameSettingsField)27);
			frameSettings = __instance.frameSettings;
			bool flag2 = ((FrameSettings)(ref frameSettings)).IsEnabled((FrameSettingsField)28);
			AmbientSmokeManager.TraceCamera(camera, flag, flag2);
			VolumeStack volumeStack = __instance.volumeStack;
			Fog val = ((volumeStack != null) ? volumeStack.GetComponent<Fog>() : null);
			AmbientSmokeManager.TraceFog(camera, val);
			if (flag && flag2 && !((Object)(object)val == (Object)null) && (!((VolumeParameter<bool>)(object)val.enabled).value || !((VolumeParameter<bool>)(object)val.enableVolumetricFog).value))
			{
				overrides[camera] = new FogState
				{
					Fog = val,
					Enabled = ((VolumeParameter<bool>)(object)val.enabled).value,
					Volumetric = ((VolumeParameter<bool>)(object)val.enableVolumetricFog).value,
					MeanFreePath = ((VolumeParameter<float>)(object)val.meanFreePath).value
				};
				if (!((VolumeParameter<bool>)(object)val.enabled).value)
				{
					((VolumeParameter<float>)(object)val.meanFreePath).value = 10000000f;
				}
				((VolumeParameter<bool>)(object)val.enabled).value = true;
				((VolumeParameter<bool>)(object)val.enableVolumetricFog).value = true;
			}
		}

		private static void RestoreBeforeUpdate(HDCamera __instance)
		{
			Restore(__instance.camera);
		}

		private static void RestoreAfterRender(ScriptableRenderContext _, Camera camera)
		{
			Restore(camera);
		}

		private static void Restore(Camera camera)
		{
			if (overrides.TryGetValue(camera, out var value))
			{
				overrides.Remove(camera);
				((VolumeParameter<bool>)(object)value.Fog.enabled).value = value.Enabled;
				((VolumeParameter<bool>)(object)value.Fog.enableVolumetricFog).value = value.Volumetric;
				((VolumeParameter<float>)(object)value.Fog.meanFreePath).value = value.MeanFreePath;
			}
		}
	}
	internal sealed class AmbientSmokeField
	{
		internal sealed class Area
		{
			private readonly int[] stamps = new int[45];

			private readonly float[] amounts = new float[45];

			internal bool Active;

			internal bool Sheltered;

			internal Vector3 Origin;

			internal float Density;

			internal float Spread;

			internal uint Revision;

			internal void Start(Vector3 origin, bool sheltered)
			{
				//IL_0015: 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)
				Array.Clear(amounts, 0, amounts.Length);
				Origin = origin;
				Sheltered = sheltered;
				Active = true;
				Density = (Spread = 0f);
				Revision++;
			}

			internal void Deposit(float burnedFraction, bool test, double now)
			{
				int num = (int)(Math.Max(0.0, now) / 2.0);
				int num2 = num % 45;
				if (stamps[num2] != num)
				{
					stamps[num2] = num;
					amounts[num2] = 0f;
				}
				amounts[num2] += burnedFraction * 0.1f * (test ? 2f : 1f);
			}

			internal void Advance(double now)
			{
				float num = 0f;
				float num2 = (Sheltered ? 64f : 38f);
				float num3 = (Sheltered ? 88f : 62f);
				for (int i = 0; i < 45; i++)
				{
					if (!(amounts[i] <= 0f))
					{
						float num4 = Mathf.Max(0f, (float)(now - ((double)stamps[i] + 0.5) * 2.0));
						if (num4 >= num3)
						{
							amounts[i] = 0f;
							continue;
						}
						float num5 = 1f - num4 * 0.00055f;
						num += amounts[i] * num5 * (1f - Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(num2, num3, num4)));
					}
				}
				Density = Mathf.Clamp01(num);
				Spread = Mathf.MoveTowards(Spread, Density, 0.035f);
				if (num < 0.001f && Spread < 0.001f)
				{
					Active = false;
				}
			}
		}

		internal const int MaxAreas = 16;

		private const float CellSeconds = 2f;

		private const int History = 45;

		private const float JoinDistanceSquared = 25f;

		private const float UnitPerCigarette = 0.1f;

		internal const float MinimumDensity = 0.001f;

		internal readonly Area[] Areas = new Area[16];

		internal AmbientSmokeField()
		{
			for (int i = 0; i < Areas.Length; i++)
			{
				Areas[i] = new Area();
			}
		}

		internal int Deposit(Vector3 point, bool sheltered, float amount, bool test, double now, int mask)
		{
			//IL_0037: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_0071: 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)
			if (amount <= 0f)
			{
				return -1;
			}
			Area area = null;
			Area area2 = null;
			float num = 25f;
			Area[] areas = Areas;
			foreach (Area area3 in areas)
			{
				if (!area3.Active)
				{
					if (area2 == null)
					{
						area2 = area3;
					}
					continue;
				}
				Vector3 val = point - area3.Origin;
				float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
				if (area3.Sheltered == sheltered && !(sqrMagnitude >= num) && !(Mathf.Abs(val.y) > 1.2f) && !Physics.Linecast(point, area3.Origin, mask, (QueryTriggerInteraction)1))
				{
					num = sqrMagnitude;
					area = area3;
				}
			}
			if (area == null)
			{
				if (area2 == null)
				{
					return -1;
				}
				area = area2;
				area.Start(point, sheltered);
			}
			area.Deposit(amount, test, now);
			return Array.IndexOf(Areas, area);
		}

		internal void Advance(double now)
		{
			Area[] areas = Areas;
			foreach (Area area in areas)
			{
				if (area.Active)
				{
					area.Advance(now);
				}
			}
		}

		internal void Clear()
		{
			Area[] areas = Areas;
			for (int i = 0; i < areas.Length; i++)
			{
				areas[i].Active = false;
			}
		}
	}
	internal sealed class AmbientSmokeManager : MonoBehaviour
	{
		private struct Sample
		{
			internal uint Key;

			internal Vector3 Center;

			internal Vector3 Size;

			internal byte Density;
		}

		private sealed class Display
		{
			internal uint Key;

			internal float Current;

			internal float Target;

			internal LocalVolumetricFog Fog;
		}

		private const string SnapshotMessage = "artemzimoglyad.lethalsmoking.ambient.v1";

		private const int VolumeLimit = 32;

		private const int VolumeBytes = 29;

		private const float SmoothSeconds = 0.65f;

		private const uint PreviewKey = uint.MaxValue;

		private static readonly Vector3[] Directions = (Vector3[])(object)new Vector3[4]
		{
			Vector3.right,
			Vector3.left,
			Vector3.forward,
			Vector3.back
		};

		private static readonly Vector3[] Axes = (Vector3[])(object)new Vector3[3]
		{
			Vector3.up,
			Vector3.right,
			Vector3.forward
		};

		private static AmbientSmokeManager instance;

		private readonly AmbientSmokeField field = new AmbientSmokeField();

		private readonly Sample[] snapshot = new Sample[32];

		private readonly Display[] displays = new Display[32];

		private readonly List<ulong> recipients = new List<ulong>();

		private readonly uint[] loggedAreaRevisions = new uint[16];

		private Settings settings;

		private NetworkManager network;

		private CustomMessagingManager messaging;

		private double nextSnapshot;

		private int count;

		private bool sentNonempty;

		private ManualLogSource log;

		private bool diagnostics;

		private int previewPercent;

		private bool previewUsed;

		private float previewUntil;

		private float nextDepositLog;

		private float nextSnapshotLog;

		private float nextCameraLog;

		private bool traceFog;

		private Camera traceVisibility;

		private Display preview;

		internal static void Install(Settings settings, ManualLogSource log)
		{
			AmbientSmokeCamera.Install();
			SceneManager.sceneLoaded += Start;
			void Start(Scene scene, LoadSceneMode mode)
			{
				SceneManager.sceneLoaded -= Start;
				Create(settings, log);
			}
		}

		private static void Create(Settings settings, ManualLogSource log)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("LethalSmoking ambient smoke");
			instance = val.AddComponent<AmbientSmokeManager>();
			instance.settings = settings;
			instance.log = log;
			Object.DontDestroyOnLoad((Object)(object)val);
			string[] commandLineArgs = Environment.GetCommandLineArgs();
			instance.diagnostics = Array.IndexOf(commandLineArgs, "-ls-ambient-diagnostics") >= 0;
			int num = Array.IndexOf(commandLineArgs, "-ls-ambient-percent");
			if (num >= 0 && num + 1 < commandLineArgs.Length && int.TryParse(commandLineArgs[num + 1], out var result) && (result == 25 || result == 50 || result == 75 || result == 100))
			{
				instance.previewPercent = result;
				instance.diagnostics = true;
			}
			if (instance.diagnostics || Settings.DiagnosticLogging)
			{
				ManualLogSource obj = instance.log;
				object[] array = new object[4];
				Scene scene = val.scene;
				array[0] = ((Scene)(ref scene)).name;
				array[1] = settings.SoloSmokeTestMode.Value;
				array[2] = instance.diagnostics;
				array[3] = instance.previewPercent;
				obj.LogInfo((object)string.Format("[AmbientSmoke] initialized scene={0}, SoloSmokeTestMode={1}, diagnostics={2}, preview={3}%", array));
			}
			SceneManager.sceneUnloaded += instance.OnSceneUnloaded;
		}

		internal static bool HasFogNear(Vector3 point)
		{
			//IL_0020: 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)
			if (!Object.op_Implicit((Object)(object)instance))
			{
				return false;
			}
			Display[] array = instance.displays;
			for (int i = 0; i < array.Length; i++)
			{
				if (IsNearby(array[i], point))
				{
					return true;
				}
			}
			return IsNearby(instance.preview, point);
		}

		private static bool IsNearby(Display display, Vector3 point)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (display != null && display.Current >= 0.001f && ((Behaviour)display.Fog).isActiveAndEnabled)
			{
				Vector3 val = ((Component)display.Fog).transform.position - point;
				return ((Vector3)(ref val)).sqrMagnitude < 1024f;
			}
			return false;
		}

		internal static void TraceCamera(Camera camera, bool atmosphere, bool volumetrics)
		{
			//IL_0198: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)instance) || !instance.diagnostics || Time.unscaledTime < instance.nextCameraLog)
			{
				return;
			}
			PlayerControllerB val = (Object.op_Implicit((Object)(object)GameNetworkManager.Instance) ? GameNetworkManager.Instance.localPlayerController : null);
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.gameplayCamera) && ((Behaviour)val.gameplayCamera).isActiveAndEnabled && (Object)(object)camera != (Object)(object)val.gameplayCamera)
			{
				return;
			}
			instance.nextCameraLog = Time.unscaledTime + 5f;
			instance.traceFog = true;
			instance.traceVisibility = camera;
			HDAdditionalCameraData component = ((Component)camera).GetComponent<HDAdditionalCameraData>();
			StringBuilder stringBuilder = new StringBuilder();
			if (Object.op_Implicit((Object)(object)component))
			{
				Volume[] volumes = VolumeManager.instance.GetVolumes(component.volumeLayerMask);
				Fog val4 = default(Fog);
				foreach (Volume val2 in volumes)
				{
					if (!((Behaviour)val2).isActiveAndEnabled || val2.weight <= 0f || (!val2.HasInstantiatedProfile() && !Object.op_Implicit((Object)(object)val2.sharedProfile)))
					{
						continue;
					}
					VolumeProfile val3 = (val2.HasInstantiatedProfile() ? val2.profile : val2.sharedProfile);
					if (val3.TryGet<Fog>(ref val4))
					{
						if (stringBuilder.Length > 0)
						{
							stringBuilder.Append(", ");
						}
						stringBuilder.Append(((Object)val2).name).Append('/').Append(((Object)val3).name);
					}
				}
			}
			AmbientSmokeManager ambientSmokeManager = instance;
			object[] obj = new object[4]
			{
				((Object)camera).name,
				null,
				null,
				null
			};
			Scene scene = ((Component)camera).gameObject.scene;
			obj[1] = ((Scene)(ref scene)).name;
			obj[2] = atmosphere;
			obj[3] = volumetrics;
			ambientSmokeManager.Log(string.Format("camera={0} scene={1} atmosphere={2} volumetrics={3} ", obj) + $"renderMask={camera.cullingMask} volumeMask={(Object.op_Implicit((Object)(object)component) ? ((LayerMask)(ref component.volumeLayerMask)).value : 0)} fogProfileCandidates={stringBuilder}");
			Display display = instance.preview;
			if (!IsNearby(display, ((Component)camera).transform.position))
			{
				display = null;
				Display[] array = instance.displays;
				foreach (Display display2 in array)
				{
					if (IsNearby(display2, ((Component)camera).transform.position) && (display == null || display2.Current > display.Current))
					{
						display = display2;
					}
				}
			}
			if (display != null)
			{
				instance.Log($"HDRP volume={display.Key} actual={display.Current:P1} meanFreePath={display.Fog.parameters.meanFreePath:F2}m");
			}
		}

		internal static void TraceFog(Camera camera, Fog fog)
		{
			if (Object.op_Implicit((Object)(object)instance) && instance.traceFog)
			{
				instance.traceFog = false;
				instance.Log(((Object)(object)fog == (Object)null) ? ("camera=" + ((Object)camera).name + " missing resolved Fog component") : ($"camera={((Object)camera).name} resolved Fog enabled={((VolumeParameter<bool>)(object)fog.enabled).value} volumetrics={((VolumeParameter<bool>)(object)fog.enableVolumetricFog).value} " + $"globalMfp={((VolumeParameter<float>)(object)fog.meanFreePath).value:F2}m volumeDepth={((VolumeParameter<float>)(object)fog.depthExtent).value:F2}m"));
			}
		}

		internal static void TraceVisible(Camera camera, List<LocalVolumetricFog> visible)
		{
			//IL_0083: 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)
			if (!Object.op_Implicit((Object)(object)instance) || (Object)(object)instance.traceVisibility != (Object)(object)camera)
			{
				return;
			}
			instance.traceVisibility = null;
			int num = 0;
			StringBuilder stringBuilder = new StringBuilder();
			foreach (LocalVolumetricFog item in visible)
			{
				if (Object.op_Implicit((Object)(object)item))
				{
					if ((Object)(object)((Component)item).transform.parent == (Object)(object)((Component)instance).transform)
					{
						num++;
					}
					stringBuilder.Append($" {((Object)item).name}[{item.parameters.blendingMode},p={item.parameters.priority}," + $"mfp={item.parameters.meanFreePath:F2},size={item.parameters.size:F1}]");
				}
			}
			instance.Log($"camera={((Object)camera).name} HDRP visible volumes total={visible.Count} ambient={num}{stringBuilder}");
		}

		internal static void Record(PlayerControllerB player, float fraction, double now)
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)instance) || fraction <= 0f || !Object.op_Implicit((Object)(object)player) || !((NetworkBehaviour)player).IsSpawned)
			{
				return;
			}
			NetworkManager networkManager = ((NetworkBehaviour)player).NetworkManager;
			if (!Object.op_Implicit((Object)(object)networkManager) || !networkManager.IsServer || networkManager.ShutdownInProgress)
			{
				return;
			}
			instance.Bind(networkManager);
			bool flag = player.isInsideFactory || player.isInHangarShipRoom;
			Vector3 val = ((Component)player).transform.position + Vector3.up * 1.05f;
			int num = instance.field.Deposit(val, flag, fraction, instance.settings.SoloSmokeTestMode.Value, now, CollisionMask());
			if (instance.diagnostics && num >= 0)
			{
				AmbientSmokeField.Area area = instance.field.Areas[num];
				if (instance.loggedAreaRevisions[num] != area.Revision)
				{
					instance.loggedAreaRevisions[num] = area.Revision;
					instance.Log($"area={num} created at {area.Origin:F2} sheltered={flag}");
				}
			}
			if (instance.diagnostics && Time.unscaledTime >= instance.nextDepositLog)
			{
				instance.nextDepositLog = Time.unscaledTime + 4f;
				instance.Log((num < 0) ? $"deposit rejected: all {16} areas occupied at {val:F2}" : $"deposit player={player.actualClientId} fraction={fraction:F4} area={num} origin={val:F2} sheltered={flag}");
			}
		}

		private static int CollisionMask()
		{
			if (!Object.op_Implicit((Object)(object)StartOfRound.Instance))
			{
				return LayerMask.GetMask(new string[3] { "Default", "Room", "Colliders" });
			}
			return StartOfRound.Instance.collidersAndRoomMaskAndDefault;
		}

		private void Update()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			Bind((Object.op_Implicit((Object)(object)singleton) && singleton.IsListening && !singleton.ShutdownInProgress) ? singleton : null);
			if (!Object.op_Implicit((Object)(object)network))
			{
				return;
			}
			if (network.IsServer)
			{
				NetworkTime serverTime = network.ServerTime;
				if (((NetworkTime)(ref serverTime)).Time >= nextSnapshot)
				{
					serverTime = network.ServerTime;
					double time = ((NetworkTime)(ref serverTime)).Time;
					nextSnapshot = time + 1.0;
					for (int i = 0; i < field.Areas.Length; i++)
					{
						AmbientSmokeField.Area area = field.Areas[i];
						if (area.Active)
						{
							area.Advance(time);
							if (!area.Active && diagnostics)
							{
								Log($"area={i} removed: dispersed");
							}
						}
					}
					BuildSnapshot(CollisionMask());
					if (count > 0 || sentNonempty)
					{
						Publish();
					}
					sentNonempty = count > 0;
				}
			}
			if (network.IsClient)
			{
				UpdatePreview();
				Render(Time.deltaTime);
				RenderDisplay(preview, 1f - Mathf.Exp((0f - Time.deltaTime) / 0.65f));
			}
		}

		private void Bind(NetworkManager current)
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			if (network == current)
			{
				return;
			}
			CustomMessagingManager obj = messaging;
			if (obj != null)
			{
				obj.UnregisterNamedMessageHandler("artemzimoglyad.lethalsmoking.ambient.v1");
			}
			Clear();
			sentNonempty = false;
			network = current;
			messaging = (Object.op_Implicit((Object)(object)current) ? current.CustomMessagingManager : null);
			if (diagnostics)
			{
				Log(Object.op_Implicit((Object)(object)current) ? $"network bound host={current.IsHost} server={current.IsServer}" : "network ended: cleared areas");
			}
			if (Object.op_Implicit((Object)(object)current) && !current.IsServer)
			{
				CustomMessagingManager obj2 = messaging;
				if (obj2 != null)
				{
					obj2.RegisterNamedMessageHandler("artemzimoglyad.lethalsmoking.ambient.v1", new HandleNamedMessageDelegate(Receive));
				}
			}
		}

		private void BuildSnapshot(int mask)
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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_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_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: 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_0187: Unknown result type (might be due to invalid IL or missing references)
			count = 0;
			int num = 0;
			AmbientSmokeField.Area[] areas = field.Areas;
			Vector3 reach = default(Vector3);
			foreach (AmbientSmokeField.Area area in areas)
			{
				if (area.Active && area.Density >= 0.001f)
				{
					float num2 = Mathf.Lerp(1.15f, area.Sheltered ? 4.2f : 6.2f, Mathf.Sqrt(area.Spread));
					((Vector3)(ref reach))..ctor(num2, Mathf.Lerp(0.75f, 1.9f, area.Spread), num2);
					Append(area, num, 0, Fit(area.Origin, reach, mask), area.Density);
				}
				num++;
			}
			Vector3 reach2 = default(Vector3);
			for (int j = 0; j < Directions.Length; j++)
			{
				if (count >= 32)
				{
					break;
				}
				for (int k = 0; k < field.Areas.Length; k++)
				{
					if (count >= 32)
					{
						break;
					}
					AmbientSmokeField.Area area2 = field.Areas[k];
					if (area2.Active && !(area2.Density < 0.001f) && !(area2.Spread < 0.28f))
					{
						Vector3 val = area2.Origin + Directions[j] * 3.4f;
						if (!Physics.Linecast(area2.Origin, val, mask, (QueryTriggerInteraction)1))
						{
							float num3 = Mathf.InverseLerp(0.28f, 0.85f, area2.Spread);
							float num4 = Mathf.Lerp(1.1f, 3.6f, num3);
							((Vector3)(ref reach2))..ctor(num4, Mathf.Lerp(0.75f, 1.6f, num3), num4);
							Append(area2, k, j + 1, Fit(val, reach2, mask), area2.Density * num3 * 0.9f);
						}
					}
				}
			}
		}

		internal static Bounds Fit(Vector3 origin, Vector3 reach, int mask)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			Bounds box = default(Bounds);
			((Bounds)(ref box))..ctor(origin, Vector3.one * 0.24f);
			Vector3[] axes = Axes;
			foreach (Vector3 val in axes)
			{
				float range = Vector3.Dot(reach, val);
				Expand(ref box, val, range, mask);
				Expand(ref box, -val, range, mask);
			}
			return box;
		}

		private static void Expand(ref Bounds box, Vector3 direction, float range, int mask)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: 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_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			if (Physics.BoxCast(((Bounds)(ref box)).center, ((Bounds)(ref box)).extents, direction, ref val, Quaternion.identity, range, mask, (QueryTriggerInteraction)1))
			{
				range = Mathf.Max(0f, ((RaycastHit)(ref val)).distance - 0.065f);
			}
			box = new Bounds(((Bounds)(ref box)).center + direction * (range * 0.5f), ((Bounds)(ref box)).size + new Vector3(Mathf.Abs(direction.x), Mathf.Abs(direction.y), Mathf.Abs(direction.z)) * range);
		}

		private void Append(AmbientSmokeField.Area area, int index, int part, Bounds bounds, float density)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_00ae: 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)
			byte b = (byte)Mathf.RoundToInt(density * 255f);
			if (b != 0)
			{
				snapshot[count++] = new Sample
				{
					Key = ((area.Revision << 8) | (uint)(index * 5 + part + 1)),
					Center = ((Bounds)(ref bounds)).center,
					Size = ((Bounds)(ref bounds)).size,
					Density = b
				};
				if (diagnostics && part == 0 && Time.unscaledTime >= nextSnapshotLog)
				{
					Log($"area={index} density={density:P1} center={((Bounds)(ref bounds)).center:F2} size={((Bounds)(ref bounds)).size:F2}");
				}
			}
		}

		private unsafe void Publish()
		{
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: 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_01ac: Unknown result type (might be due to invalid IL or missing references)
			if (diagnostics && Time.unscaledTime >= nextSnapshotLog)
			{
				nextSnapshotLog = Time.unscaledTime + 5f;
				int num = 0;
				AmbientSmokeField.Area[] areas = field.Areas;
				for (int i = 0; i < areas.Length; i++)
				{
					if (areas[i].Active)
					{
						num++;
					}
				}
				Log($"host snapshot areas={num} volumes={count} localHost={network.IsClient}");
			}
			if (network.IsClient)
			{
				ApplySnapshot();
			}
			if (messaging == null)
			{
				return;
			}
			recipients.Clear();
			foreach (ulong connectedClientsId in network.ConnectedClientsIds)
			{
				if (connectedClientsId != 0L)
				{
					recipients.Add(connectedClientsId);
				}
			}
			if (recipients.Count == 0)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(1 + count * 29, (Allocator)2, -1);
			try
			{
				byte b = (byte)count;
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
				for (int j = 0; j < count; j++)
				{
					Sample sample = snapshot[j];
					((FastBufferWriter)(ref val)).WriteValueSafe<uint>(ref sample.Key, default(ForPrimitives));
					((FastBufferWriter)(ref val)).WriteValueSafe(ref sample.Center);
					((FastBufferWriter)(ref val)).WriteValueSafe(ref sample.Size);
					((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref sample.Density, default(ForPrimitives));
				}
				messaging.SendNamedMessage("artemzimoglyad.lethalsmoking.ambient.v1", (IReadOnlyList<ulong>)recipients, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private void Receive(ulong sender, FastBufferReader reader)
		{
			//IL_0014: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			if (sender != 0L || !((FastBufferReader)(ref reader)).TryBeginRead(1))
			{
				return;
			}
			byte b = default(byte);
			((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref b, default(ForPrimitives));
			if (b <= 32 && ((FastBufferReader)(ref reader)).TryBeginRead(b * 29))
			{
				count = b;
				for (int i = 0; i < count; i++)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe<uint>(ref snapshot[i].Key, default(ForPrimitives));
					((FastBufferReader)(ref reader)).ReadValueSafe(ref snapshot[i].Center);
					((FastBufferReader)(ref reader)).ReadValueSafe(ref snapshot[i].Size);
					((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref snapshot[i].Density, default(ForPrimitives));
				}
				if (diagnostics && Time.unscaledTime >= nextSnapshotLog)
				{
					nextSnapshotLog = Time.unscaledTime + 5f;
					Log($"received host snapshot volumes={count}");
				}
				ApplySnapshot();
			}
		}

		private void UpdatePreview()
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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_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_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: 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)
			if (previewPercent != 0)
			{
				PlayerControllerB val = (Object.op_Implicit((Object)(object)GameNetworkManager.Instance) ? GameNetworkManager.Instance.localPlayerController : null);
				if (!previewUsed && Object.op_Implicit((Object)(object)val) && ((NetworkBehaviour)val).IsSpawned && val.isPlayerControlled && !val.isPlayerDead && Object.op_Implicit((Object)(object)val.gameplayCamera))
				{
					previewUsed = true;
					previewUntil = Time.unscaledTime + 30f;
					Bounds val2 = Fit(((Component)val).transform.position + Vector3.up * 1.05f, new Vector3(4.2f, 1.9f, 4.2f), CollisionMask());
					SetSample(preview ?? (preview = CreateDisplay()), new Sample
					{
						Key = uint.MaxValue,
						Center = ((Bounds)(ref val2)).center,
						Size = ((Bounds)(ref val2)).size,
						Density = (byte)Mathf.RoundToInt((float)previewPercent * 2.55f)
					});
					Log($"preview={previewPercent}% center={((Bounds)(ref val2)).center:F2} size={((Bounds)(ref val2)).size:F2} duration=30s");
				}
				if (preview != null && Time.unscaledTime >= previewUntil)
				{
					preview.Target = 0f;
				}
			}
		}

		private void ApplySnapshot()
		{
			Display[] array = displays;
			foreach (Display display in array)
			{
				if (display != null)
				{
					display.Target = 0f;
				}
			}
			for (int j = 0; j < count; j++)
			{
				Sample sample = snapshot[j];
				Display display2 = FindDisplay(sample.Key);
				if (display2 != null)
				{
					SetSample(display2, sample);
				}
			}
		}

		private Display FindDisplay(uint key)
		{
			int num = -1;
			for (int i = 0; i < displays.Length; i++)
			{
				Display display = displays[i];
				if (display != null && display.Key == key)
				{
					return display;
				}
				if (num < 0 && (display == null || display.Key == 0))
				{
					num = i;
				}
			}
			if (num < 0)
			{
				return null;
			}
			if (displays[num] != null)
			{
				return displays[num];
			}
			return displays[num] = CreateDisplay();
		}

		private static void SetSample(Display display, Sample sample)
		{
			//IL_002b: 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)
			display.Key = sample.Key;
			display.Target = (float)(int)sample.Density / 255f;
			((Component)display.Fog).transform.position = sample.Center;
			display.Fog.parameters.size = sample.Size;
		}

		private Display CreateDisplay()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Ambient cigarette fog");
			val.SetActive(false);
			val.transform.SetParent(((Component)this).transform, false);
			LocalVolumetricFog val2 = val.AddComponent<LocalVolumetricFog>();
			val2.parameters.albedo = new Color(0.83f, 0.83f, 0.81f);
			val2.parameters.anisotropy = 0.22f;
			val2.parameters.blendingMode = (LocalVolumetricFogBlendingMode)4;
			val2.parameters.priority = 10;
			val2.parameters.positiveFade = (val2.parameters.negativeFade = new Vector3(0.25f, 0.2f, 0.25f));
			if (diagnostics)
			{
				Log($"created HDRP LocalVolumetricFog on layer={val.layer}");
			}
			return new Display
			{
				Fog = val2
			};
		}

		internal static float MeanFreePath(float density)
		{
			return 1f / (0.17f * density + 0.83f * density * density);
		}

		private void Render(float elapsed)
		{
			float blend = 1f - Mathf.Exp((0f - elapsed) / 0.65f);
			Display[] array = displays;
			foreach (Display display in array)
			{
				RenderDisplay(display, blend);
			}
		}

		private void RenderDisplay(Display display, float blend)
		{
			if (display == null || display.Key == 0)
			{
				return;
			}
			display.Current = Mathf.Lerp(display.Current, display.Target, blend);
			bool flag = display.Current >= 0.001f;
			if (flag)
			{
				display.Fog.parameters.meanFreePath = MeanFreePath(display.Current);
			}
			if (((Component)display.Fog).gameObject.activeSelf != flag)
			{
				((Component)display.Fog).gameObject.SetActive(flag);
				if (diagnostics)
				{
					Log(flag ? $"HDRP volume={display.Key} active target={display.Target:P1}" : $"HDRP volume={display.Key} removed: faded");
				}
			}
			if (!flag && display.Target == 0f)
			{
				display.Key = 0u;
			}
		}

		private void Log(string message)
		{
			ManualLogSource obj = log;
			if (obj != null)
			{
				obj.LogInfo((object)("[AmbientSmoke] " + message));
			}
		}

		private void OnSceneUnloaded(Scene scene)
		{
			if (diagnostics && count > 0)
			{
				Log("scene=" + ((Scene)(ref scene)).name + " unloaded: cleared areas");
			}
			Clear();
		}

		private void Clear()
		{
			nextSnapshot = 0.0;
			count = 0;
			field.Clear();
			ResetDisplay(preview);
			Display[] array = displays;
			for (int i = 0; i < array.Length; i++)
			{
				ResetDisplay(array[i]);
			}
		}

		private static void ResetDisplay(Display display)
		{
			if (display != null)
			{
				display.Key = 0u;
				display.Current = (display.Target = 0f);
				((Component)display.Fog).gameObject.SetActive(false);
			}
		}

		private void OnDestroy()
		{
			SceneManager.sceneUnloaded -= OnSceneUnloaded;
			CustomMessagingManager obj = messaging;
			if (obj != null)
			{
				obj.UnregisterNamedMessageHandler("artemzimoglyad.lethalsmoking.ambient.v1");
			}
			if ((Object)(object)instance == (Object)(object)this)
			{
				instance = null;
			}
		}
	}
	internal static class ExpeditionEffects
	{
		private sealed class Record
		{
			internal ulong Owner;

			internal int Completed;

			internal float StaminaCap = 1f;
		}

		private const string Message = "artemzimoglyad.lethalsmoking.expedition.v2";

		private const int WireSize = 28;

		private static readonly Dictionary<ulong, Record> Records = new Dictionary<ulong, Record>();

		private static NetworkManager network;

		private static CustomMessagingManager messages;

		private static Settings settings;

		private static readonly Random CoughRandom = new Random();

		internal static float CoughChance => ValidFraction(settings.CoughChanceOnSmokingCompleted.Value, 0.2f, 1f);

		private static bool OnExpedition
		{
			get
			{
				if (Object.op_Implicit((Object)(object)StartOfRound.Instance))
				{
					return !StartOfRound.Instance.inShipPhase;
				}
				return false;
			}
		}

		internal static byte RollCough()
		{
			if (!(CoughRandom.NextDouble() < (double)CoughChance))
			{
				return 0;
			}
			return (byte)CoughRandom.Next(1, 4);
		}

		internal static void Initialize(Settings configuration)
		{
			settings = configuration;
		}

		internal static void Bind(NetworkManager manager, CustomMessagingManager messaging)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			Unbind();
			network = manager;
			messages = messaging;
			messages.RegisterNamedMessageHandler("artemzimoglyad.lethalsmoking.expedition.v2", new HandleNamedMessageDelegate(Receive));
			manager.OnClientDisconnectCallback += Disconnected;
			if (manager.IsServer)
			{
				manager.OnClientConnectedCallback += SyncClient;
			}
		}

		internal static void Unbind()
		{
			if (Object.op_Implicit((Object)(object)network))
			{
				network.OnClientConnectedCallback -= SyncClient;
				network.OnClientDisconnectCallback -= Disconnected;
			}
			CustomMessagingManager obj = messages;
			if (obj != null)
			{
				obj.UnregisterNamedMessageHandler("artemzimoglyad.lethalsmoking.expedition.v2");
			}
			network = null;
			messages = null;
			Records.Clear();
		}

		internal static float WeightReduction(PlayerControllerB player)
		{
			int num = Get(((NetworkBehaviour)player).NetworkObjectId, player.actualClientId, create: false)?.Completed ?? 0;
			return 0.05f * (float)Mathf.Max(0, 6 - Mathf.Abs(num - 3));
		}

		private static float ValidFraction(float value, float fallback, float maximum)
		{
			if (!float.IsNaN(value) && !float.IsInfinity(value))
			{
				return Mathf.Clamp(value, 0f, maximum);
			}
			return fallback;
		}

		internal static float StaminaCap(PlayerControllerB player)
		{
			return Get(((NetworkBehaviour)player).NetworkObjectId, player.actualClientId, create: false)?.StaminaCap ?? 1f;
		}

		private static Record Get(ulong id, ulong owner, bool create)
		{
			if (Records.TryGetValue(id, out var value) && value.Owner == owner)
			{
				return value;
			}
			if (!create)
			{
				return null;
			}
			value = new Record
			{
				Owner = owner
			};
			Records[id] = value;
			return value;
		}

		internal static void Complete(PlayerControllerB player)
		{
			if (Object.op_Implicit((Object)(object)network) && network.IsServer && OnExpedition && SmokingProtocol.IsAlive(player))
			{
				ulong networkObjectId = ((NetworkBehaviour)player).NetworkObjectId;
				Record record = Get(networkObjectId, player.actualClientId, create: true);
				record.Completed++;
				float num = ValidFraction(settings.MaxStaminaPenaltyPerCigarette.Value, 0.05f, 1f);
				record.StaminaCap = Mathf.Clamp01(1f - (float)record.Completed * num);
				int value = settings.DamagePerCompletedCigarette.Value;
				Broadcast(networkObjectId, record, value);
				if (((NetworkBehaviour)player).IsOwner)
				{
					ApplyCompletion(player, record.StaminaCap, value);
				}
			}
		}

		internal static void ReturnedToOrbit()
		{
			if (Records.Count != 0)
			{
				Records.Clear();
				GameNetworkManager instance = GameNetworkManager.Instance;
				PlayerControllerB val = (Object.op_Implicit((Object)(object)instance) ? instance.localPlayerController : null);
				if (SmokingProtocol.IsAlive(val))
				{
					val.sprintMeter = 1f;
				}
			}
		}

		private static void ApplyCompletion(PlayerControllerB player, float cap, int damage)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			if (!SmokingProtocol.IsAlive(player))
			{
				return;
			}
			player.sprintMeter = Mathf.Min(player.sprintMeter, cap);
			if (damage == 0)
			{
				return;
			}
			bool flag = player.health <= damage && !player.criticallyInjured;
			if (flag)
			{
				player.criticallyInjured = true;
			}
			try
			{
				player.DamagePlayer(damage, true, true, (CauseOfDeath)0, 0, false, Vector3.zero);
			}
			finally
			{
				if (flag && !player.isPlayerDead)
				{
					player.criticallyInjured = false;
				}
			}
		}

		private static void Broadcast(ulong id, Record record, int damage)
		{
			foreach (ulong connectedClientsId in network.ConnectedClientsIds)
			{
				if (connectedClientsId != 0L)
				{
					Send(connectedClientsId, id, record, (connectedClientsId == record.Owner) ? damage : 0);
				}
			}
		}

		private static void SyncClient(ulong client)
		{
			if (client == 0L || !OnExpedition)
			{
				return;
			}
			foreach (KeyValuePair<ulong, Record> record in Records)
			{
				Send(client, record.Key, record.Value, 0);
			}
		}

		private unsafe static void Send(ulong client, ulong id, Record record, int damage)
		{
			//IL_0011: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(28, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref id, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref record.Owner, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref record.Completed, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref record.StaminaCap, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref damage, default(ForPrimitives));
				messages.SendNamedMessage("artemzimoglyad.lethalsmoking.expedition.v2", client, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private static void Receive(ulong sender, FastBufferReader reader)
		{
			//IL_0034: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)network) || network.IsServer || sender != 0L || !OnExpedition || !((FastBufferReader)(ref reader)).TryBeginRead(28))
			{
				return;
			}
			ulong id = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref id, default(ForPrimitives));
			ulong owner = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref owner, default(ForPrimitives));
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			float num2 = default(float);
			((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref num2, default(ForPrimitives));
			int damage = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref damage, default(ForPrimitives));
			Record record = Get(id, owner, create: true);
			bool flag = num > record.Completed;
			if (num >= record.Completed)
			{
				record.Completed = num;
				record.StaminaCap = num2;
				if (FindPlayer(id, owner, out var player) && flag && ((NetworkBehaviour)player).IsOwner)
				{
					ApplyCompletion(player, num2, damage);
				}
			}
		}

		private static bool FindPlayer(ulong id, ulong owner, out PlayerControllerB player)
		{
			player = null;
			if (network.SpawnManager.SpawnedObjects.TryGetValue(id, out var value) && ((Component)value).TryGetComponent<PlayerControllerB>(ref player))
			{
				return player.actualClientId == owner;
			}
			return false;
		}

		private static void Disconnected(ulong owner)
		{
			ulong? num = null;
			foreach (KeyValuePair<ulong, Record> record in Records)
			{
				if (record.Value.Owner == owner)
				{
					num = record.Key;
					break;
				}
			}
			if (num.HasValue)
			{
				Records.Remove(num.Value);
			}
		}
	}
	internal static class ExpeditionPatches
	{
		private static readonly FieldInfo CarryWeight = AccessTools.Field(typeof(PlayerControllerB), "carryWeight");

		private static readonly FieldInfo SprintMeter = AccessTools.Field(typeof(PlayerControllerB), "sprintMeter");

		private static Image meter;

		private static Image blocked;

		private static int lastPounds = -1;

		private static bool refreshWeight;

		internal static void Install()
		{
			//IL_0005: 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_0020: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown