Decompiled source of Bummer Mart v0.14.0

plugins/ZabkowySklep.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Playables;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ZabkowySklep
{
	internal sealed class BagInventory
	{
		private static readonly Action<PlayerControllerB, int, GrabbableObject> SwitchSlot = AccessTools.MethodDelegate<Action<PlayerControllerB, int, GrabbableObject>>(AccessTools.Method(typeof(PlayerControllerB), "SwitchToItemSlot", (Type[])null, (Type[])null), (object)null, true);

		private static readonly Action<PlayerControllerB, bool> SyncSwitch = AccessTools.MethodDelegate<Action<PlayerControllerB, bool>>(AccessTools.Method(typeof(PlayerControllerB), "SwitchItemSlotsServerRpc", (Type[])null, (Type[])null), (object)null, true);

		private static readonly FieldRef<PlayerControllerB, bool> Throwing = AccessTools.FieldRefAccess<PlayerControllerB, bool>("throwingObject");

		private readonly Dictionary<PlayerControllerB, int> slots = new Dictionary<PlayerControllerB, int>();

		private HUDManager hud;

		private Image bagFrame;

		private float nextRetirementAction;

		private ulong owners;

		internal static ulong Bit(PlayerControllerB player)
		{
			if (!Object.op_Implicit((Object)(object)player) || player.playerClientId >= 64)
			{
				return 0uL;
			}
			return (ulong)(1L << (int)player.playerClientId);
		}

		internal void Update(StartOfRound round, ulong entitled, bool hasRoster)
		{
			owners = entitled;
			if (!Object.op_Implicit((Object)(object)round) || round.allPlayerScripts == null)
			{
				return;
			}
			PlayerControllerB localPlayer = ShopPlugin.LocalPlayer;
			PlayerControllerB[] allPlayerScripts = round.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (!Object.op_Implicit((Object)(object)val) || val.ItemSlots == null)
				{
					continue;
				}
				if ((owners & Bit(val)) != 0)
				{
					EnsureSlot(val);
				}
				else
				{
					if (!hasRoster || !slots.TryGetValue(val, out var value))
					{
						continue;
					}
					GrabbableObject[] itemSlots = val.ItemSlots;
					if (value >= itemSlots.Length)
					{
						slots.Remove(val);
						if ((Object)(object)val == (Object)(object)localPlayer)
						{
							RemoveHud();
						}
					}
					else
					{
						if (value != itemSlots.Length - 1)
						{
							continue;
						}
						if (!Object.op_Implicit((Object)(object)itemSlots[value]) && val.currentItemSlot != value)
						{
							Array.Resize(ref val.ItemSlots, value);
							slots.Remove(val);
							if ((Object)(object)val == (Object)(object)localPlayer)
							{
								RemoveHud();
							}
						}
						else if ((Object)(object)val == (Object)(object)localPlayer && ((NetworkBehaviour)val).IsOwner)
						{
							RetireLocalSlot(val, value, itemSlots[value]);
						}
					}
				}
			}
		}

		internal void EnsureSlot(PlayerControllerB player)
		{
			GrabbableObject[] itemSlots = player.ItemSlots;
			if (itemSlots == null || itemSlots.Length == 0)
			{
				return;
			}
			int value;
			int num = (slots.TryGetValue(player, out value) ? value : itemSlots.Length);
			if (!((Object)(object)player == (Object)(object)ShopPlugin.LocalPlayer) || EnsureHud(num))
			{
				if (itemSlots.Length == num)
				{
					Array.Resize(ref player.ItemSlots, num + 1);
				}
				slots[player] = num;
			}
		}

		internal bool IsRetiringSlot(PlayerControllerB player, int index)
		{
			if (slots.TryGetValue(player, out var value) && value == index)
			{
				return (owners & Bit(player)) == 0;
			}
			return false;
		}

		private void RetireLocalSlot(PlayerControllerB player, int index, GrabbableObject item)
		{
			//IL_0079: 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)
			if (!player.isPlayerControlled || player.isPlayerDead || player.inSpecialInteractAnimation || player.isGrabbingObjectAnimation || player.inTerminalMenu || Throwing.Invoke(player) || Time.unscaledTime < nextRetirementAction)
			{
				return;
			}
			nextRetirementAction = Time.unscaledTime + 0.14f;
			if (Object.op_Implicit((Object)(object)item) && player.currentItemSlot == index)
			{
				if ((Object)(object)player.currentlyHeldObjectServer == (Object)(object)item)
				{
					player.DiscardHeldObject(false, (NetworkObject)null, default(Vector3), true);
				}
			}
			else
			{
				int arg = ((player.currentItemSlot != 50) ? ((player.currentItemSlot + 1) % player.ItemSlots.Length) : 0);
				SwitchSlot(player, arg, null);
				SyncSwitch(player, arg2: true);
			}
		}

		private bool EnsureHud(int index)
		{
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			HUDManager instance = HUDManager.Instance;
			if (!Object.op_Implicit((Object)(object)instance) || instance.itemSlotIcons == null || instance.itemSlotIconFrames == null)
			{
				return false;
			}
			if (instance.itemSlotIcons.Length > index && instance.itemSlotIconFrames.Length > index)
			{
				return true;
			}
			if (instance.itemSlotIcons.Length != index || instance.itemSlotIconFrames.Length != index)
			{
				return false;
			}
			Image val = instance.itemSlotIconFrames[index - 1];
			Image val2 = instance.itemSlotIcons[index - 1];
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2) || (Object)(object)((Component)val2).transform.parent != (Object)(object)((Component)val).transform)
			{
				return false;
			}
			hud = instance;
			bagFrame = Object.Instantiate<Image>(val, ((Component)val).transform.parent, false);
			((Object)bagFrame).name = "Bag slot";
			Vector2 anchoredPosition = ((Graphic)val).rectTransform.anchoredPosition;
			float num = ((index > 1) ? (anchoredPosition.x - ((Graphic)instance.itemSlotIconFrames[index - 2]).rectTransform.anchoredPosition.x) : 51f);
			((Graphic)bagFrame).rectTransform.anchoredPosition = anchoredPosition + Vector2.right * num;
			Image component = ((Component)((Component)bagFrame).transform.GetChild(((Component)val2).transform.GetSiblingIndex())).GetComponent<Image>();
			component.sprite = null;
			((Behaviour)component).enabled = false;
			Animator component2 = ((Component)bagFrame).GetComponent<Animator>();
			if (component2 != null)
			{
				component2.SetBool("selectedSlot", false);
			}
			TextMeshProUGUI val3 = new GameObject("Bag slot caption", new Type[1] { typeof(RectTransform) }).AddComponent<TextMeshProUGUI>();
			((TMP_Text)val3).transform.SetParent(((Component)bagFrame).transform, false);
			if (Object.op_Implicit((Object)(object)hud.utilitySlotKeyText))
			{
				((TMP_Text)val3).font = ((TMP_Text)hud.utilitySlotKeyText).font;
			}
			((TMP_Text)val3).text = ShopLanguage.T("TOTE");
			((TMP_Text)val3).fontSize = 8f;
			((TMP_Text)val3).alignment = (TextAlignmentOptions)514;
			((Graphic)val3).raycastTarget = false;
			((TMP_Text)val3).rectTransform.sizeDelta = new Vector2(42f, 9f);
			((TMP_Text)val3).rectTransform.anchoredPosition = new Vector2(0f, -24f);
			Array.Resize(ref hud.itemSlotIconFrames, index + 1);
			Array.Resize(ref hud.itemSlotIcons, index + 1);
			hud.itemSlotIconFrames[index] = bagFrame;
			hud.itemSlotIcons[index] = component;
			return true;
		}

		private void RemoveHud()
		{
			if (Object.op_Implicit((Object)(object)hud) && Object.op_Implicit((Object)(object)bagFrame) && hud.itemSlotIconFrames.Length != 0 && hud.itemSlotIconFrames.Length == hud.itemSlotIcons.Length && (Object)(object)hud.itemSlotIconFrames[hud.itemSlotIconFrames.Length - 1] == (Object)(object)bagFrame)
			{
				Array.Resize(ref hud.itemSlotIconFrames, hud.itemSlotIconFrames.Length - 1);
				Array.Resize(ref hud.itemSlotIcons, hud.itemSlotIcons.Length - 1);
			}
			if (Object.op_Implicit((Object)(object)bagFrame))
			{
				Object.Destroy((Object)(object)((Component)bagFrame).gameObject);
			}
			bagFrame = null;
			hud = null;
		}

		internal void Reset()
		{
			RemoveHud();
			slots.Clear();
			owners = 0uL;
			nextRetirementAction = 0f;
		}
	}
	[HarmonyPatch]
	internal static class BagInventoryPatches
	{
		[HarmonyPatch(typeof(StartOfRound), "SyncAlreadyHeldObjectsClientRpc")]
		[HarmonyPrefix]
		private static void PrepareExistingInventory(StartOfRound __instance, int[] playersHeldBy, int[] itemSlotNumbers, int syncWithClient)
		{
			NetworkManager singleton = NetworkManager.Singleton;
			ShopPlugin instance = ShopPlugin.Instance;
			if ((Object)(object)instance == (Object)null || !Object.op_Implicit((Object)(object)singleton) || !singleton.IsClient || (int)singleton.LocalClientId != syncWithClient || playersHeldBy == null || itemSlotNumbers == null || __instance.allPlayerScripts == null)
			{
				return;
			}
			for (int i = 0; i < playersHeldBy.Length && i < itemSlotNumbers.Length; i++)
			{
				int num = playersHeldBy[i];
				if (num >= 0 && num < __instance.allPlayerScripts.Length)
				{
					PlayerControllerB val = __instance.allPlayerScripts[num];
					if (Object.op_Implicit((Object)(object)val) && val.ItemSlots != null && itemSlotNumbers[i] != 50 && itemSlotNumbers[i] == val.ItemSlots.Length)
					{
						instance.EnsureBagSlot(val);
					}
				}
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "FirstEmptyItemSlot")]
		[HarmonyPostfix]
		[HarmonyPriority(0)]
		private static void BlockRefillDuringRetirement(PlayerControllerB __instance, ref int __result)
		{
			ShopPlugin instance = ShopPlugin.Instance;
			if (instance == null || !instance.IsRetiringBagSlot(__instance, __result))
			{
				return;
			}
			int num = __result;
			__result = -1;
			for (int i = 0; i < num; i++)
			{
				if (!Object.op_Implicit((Object)(object)__instance.ItemSlots[i]))
				{
					__result = i;
					break;
				}
			}
		}
	}
	internal enum CashierCue : byte
	{
		Welcome = 1,
		Purchase,
		Idle
	}
	[BepInPlugin("saltanis.zabkowysklep", "Bummer Mart", "0.14.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class ShopPlugin : BaseUnityPlugin
	{
		private struct ChalkMark
		{
			internal int Id;

			internal Vector3 Position;

			internal Vector3 Normal;

			internal Vector3 Up;
		}

		private struct OrderReply
		{
			internal ulong Sequence;

			internal PurchaseResult Result;
		}

		private const string CashierMessage = "saltanis.zabkowysklep/1/cashier";

		private const int CashierMessageSize = 5;

		private readonly HashSet<ulong> shopVisitors = new HashSet<ulong>();

		private float nextWelcome;

		private float nextIdleCue;

		private float nextPurchaseCue;

		private const string ChalkRequest = "saltanis.zabkowysklep/10/chalk-request";

		private const string ChalkDrawn = "saltanis.zabkowysklep/10/chalk-drawn";

		private const int MarkSize = 44;

		private const float MarkRange = 3.7f;

		private ConfigEntry<Key> chalkKey;

		private readonly Dictionary<string, int> chalkUses = new Dictionary<string, int>();

		private readonly List<ChalkMark> chalkHistory = new List<ChalkMark>();

		private readonly Dictionary<int, GameObject> chalkObjects = new Dictionary<int, GameObject>();

		private Mesh chalkMesh;

		private Material chalkMaterial;

		private int chalkSeed;

		private CrewGrades glowGrades;

		private CrewGrades quietGrades;

		private readonly Dictionary<PlayerControllerB, Light> candyLights = new Dictionary<PlayerControllerB, Light>();

		private const string DumpsterMessage = "saltanis.zabkowysklep/10/dumpster";

		private const float HideDuration = 3f;

		private PlayerControllerB binPending;

		private PlayerControllerB binOccupant;

		private float binReadyAt;

		private float binEntryGrace;

		private PlayerControllerB hiddenLocal;

		private Vector3 hiddenAt;

		private Vector3 hiddenExit;

		private bool previousMoveInput;

		private bool previousCrouch;

		private readonly List<Collider> ignoredBinColliders = new List<Collider>();

		private float localHidingSince = -1f;

		private int dumpsterRequestFrame = -1;

		private static readonly HashSet<string> BaseRoofScrap = new HashSet<string>
		{
			"7Ball", "Airhorn", "Bell", "BigBolt", "BottleBin", "Brush", "Candy", "CashRegister", "ChemicalJug", "Clock",
			"ClownHorn", "Cog1", "ComedyMask", "ControlPad", "Dentures", "DiyFlashbang", "DustPan", "EasterEgg", "EggBeater", "EnginePart1",
			"FancyCup", "FancyLamp", "FancyPainting", "FishTestProp", "FlashLaserPointer", "Flask", "GarbageLid", "GiftBox", "GoldBar", "Hairdryer",
			"MagnifyingGlass", "MetalSheet", "MoldPan", "Mug", "PerfumeBottle", "Phone", "PickleJar", "PillBottle", "PlasticCup", "Remote",
			"Ring", "RobotToy", "RubberDuck", "SeveredBone", "SeveredBoneRib", "SeveredEar", "SeveredFoot", "SeveredHand", "SeveredHeart", "SeveredThigh",
			"SeveredTongue", "SoccerBall", "SodaCanRed", "SteeringWheel", "StopSign", "TeaKettle", "ToiletPaperRolls", "Toothpaste", "ToyCube", "ToyTrain",
			"TragedyMask", "WhoopieCushion", "YieldSign", "Zeddog"
		};

		private readonly Random roofScrapRandom = new Random();

		private GrabbableObject roofScrap;

		private ulong? syncedRoofScrap;

		private const string RequestMessage = "saltanis.zabkowysklep/12/request";

		private const string OrderMessage = "saltanis.zabkowysklep/12/basket";

		private const string StatusMessage = "saltanis.zabkowysklep/12/status";

		private const int OrderSize = 20;

		private const int StatusSize = 143;

		private readonly Dictionary<ulong, ShopStatus> lastStatus = new Dictionary<ulong, ShopStatus>();

		private readonly Dictionary<ulong, OrderReply> orderReplies = new Dictionary<ulong, OrderReply>();

		private CustomMessagingManager messenger;

		private ShopStatus status;

		private bool receivedStatus;

		private float nextRequest;

		private ulong nextOrder;

		private ulong pendingOrder;

		private uint pendingVisit;

		private int pendingTarget;

		private BasketAction pendingAction;

		private ProductId pendingProduct;

		private byte pendingLevel;

		private float pendingSince;

		private string feedback;

		internal const string Id = "saltanis.zabkowysklep";

		internal const string Version = "0.14.0";

		private const float DefaultMusicVolume = 0.68f;

		private const string SaveKey = "saltanis.zabkowysklep.campaign.v1";

		private const string CompanyScene = "CompanyBuilding";

		internal const float RegisterRangeSquared = 9f;

		private const float ShelfRangeSquared = 6.25f;

		internal static ShopPlugin Instance;

		private Harmony harmony;

		private NetworkManager network;

		private StartOfRound round;

		private string slot;

		private string lanSession;

		private Campaign campaign;

		private bool loadFailed;

		private bool workLanding;

		private bool needsSave;

		private float nextTick;

		private Vector3? shopPosition;

		private uint shopVisit;

		private bool stockReady;

		private readonly Dictionary<ulong, ulong> baskets = new Dictionary<ulong, ulong>();

		private ShopView shop;

		private readonly BagInventory bagInventory = new BagInventory();

		private ulong bagOwners;

		private Scene shopScene;

		private PlayerControllerB effectPlayer;

		private int healthBonus;

		private int waterInterval;

		private float waterRegenRemaining;

		private readonly WalletHud walletHud = new WalletHud();

		private ConfigEntry<float> musicVolume;

		internal string ChalkKeyName => ((object)chalkKey.Value/*cast due to .constrained prefix*/).ToString();

		private bool CanDrawOnMoon
		{
			get
			{
				if (HasLanded && Object.op_Implicit((Object)(object)round.currentLevel) && round.currentLevel.planetHasTime)
				{
					return !IsCompany(round);
				}
				return false;
			}
		}

		internal ShopStatus Status => status;

		internal bool WaitingForOrder => pendingOrder != 0;

		internal string Feedback => feedback;

		internal static PlayerControllerB LocalPlayer
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)GameNetworkManager.Instance))
				{
					return null;
				}
				return GameNetworkManager.Instance.localPlayerController;
			}
		}

		private bool HasLanded
		{
			get
			{
				if (Object.op_Implicit((Object)(object)round) && round.shipHasLanded && !round.shipIsLeaving)
				{
					return !round.inShipPhase;
				}
				return false;
			}
		}

		public Func<DepositItemsDesk, int> SupplementalCrewSaleValue { get; set; }

		private bool OpenForOrders
		{
			get
			{
				if (shopPosition.HasValue && stockReady && HasLanded && Object.op_Implicit((Object)(object)TimeOfDay.Instance) && TimeOfDay.Instance.profitQuota > 0 && TimeOfDay.Instance.quotaFulfilled >= TimeOfDay.Instance.profitQuota)
				{
					return campaign != null;
				}
				return false;
			}
		}

		private void ResetCashierCues()
		{
			shopVisitors.Clear();
			nextWelcome = (nextIdleCue = (nextPurchaseCue = 0f));
		}

		private void PollCashierCues()
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			if (!shopPosition.HasValue)
			{
				ResetCashierCues();
				return;
			}
			bool flag = shopVisitors.Count != 0;
			bool flag2 = false;
			foreach (ulong connectedClientsId in network.ConnectedClientsIds)
			{
				PlayerControllerB val = PlayerFromClient(connectedClientsId);
				if (Object.op_Implicit((Object)(object)val) && val.isPlayerControlled && !val.isPlayerDead && !val.isClimbingLadder && !val.inSpecialInteractAnimation && ShopView.Inside(((Component)val).transform.position, shopPosition.Value))
				{
					flag2 |= shopVisitors.Add(connectedClientsId);
				}
				else
				{
					shopVisitors.Remove(connectedClientsId);
				}
			}
			float unscaledTime = Time.unscaledTime;
			if (flag2 && unscaledTime >= nextWelcome)
			{
				CueCashier(CashierCue.Welcome);
			}
			else if (!flag)
			{
				nextIdleCue = unscaledTime + 42f;
			}
			else if (shopVisitors.Count != 0 && unscaledTime >= nextIdleCue)
			{
				CueCashier(CashierCue.Idle);
			}
		}

		private unsafe void CueCashier(CashierCue cue)
		{
			//IL_007d: 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_0091: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			float unscaledTime = Time.unscaledTime;
			if (cue == CashierCue.Purchase)
			{
				if (unscaledTime < nextPurchaseCue)
				{
					return;
				}
				nextPurchaseCue = unscaledTime + 2.9f;
			}
			nextWelcome = unscaledTime + 7f;
			nextIdleCue = unscaledTime + 42f;
			shop?.PlayCashierCue(cue);
			if (messenger == null || network.ConnectedClientsIds.Count <= 1)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(5, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<uint>(ref shopVisit, default(ForPrimitives));
				byte b = (byte)cue;
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
				foreach (ulong connectedClientsId in network.ConnectedClientsIds)
				{
					if (connectedClientsId != network.LocalClientId)
					{
						messenger.SendNamedMessage("saltanis.zabkowysklep/1/cashier", connectedClientsId, val, (NetworkDelivery)3);
					}
				}
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private void ReceiveCashierCue(ulong sender, FastBufferReader reader)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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)
			if (sender == 0L && ((FastBufferReader)(ref reader)).Length - ((FastBufferReader)(ref reader)).Position == 5)
			{
				uint num = default(uint);
				((FastBufferReader)(ref reader)).ReadValueSafe<uint>(ref num, default(ForPrimitives));
				byte b = default(byte);
				((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref b, default(ForPrimitives));
				if (status.HasShop && status.Visit == num && b >= 1 && b <= 3)
				{
					shop?.PlayCashierCue((CashierCue)b);
				}
			}
		}

		private void UpdateChalk()
		{
			//IL_0078: 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_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			if (!CanDrawOnMoon)
			{
				if (chalkObjects.Count != 0 || chalkHistory.Count != 0 || chalkUses.Count != 0)
				{
					ClearChalk();
				}
				return;
			}
			if (chalkSeed != round.randomMapSeed)
			{
				ClearChalk();
				chalkSeed = round.randomMapSeed;
			}
			PlayerControllerB localPlayer = LocalPlayer;
			Keyboard current = Keyboard.current;
			if (current != null && (int)chalkKey.Value != 0 && ((ButtonControl)current[chalkKey.Value]).wasPressedThisFrame && Object.op_Implicit((Object)(object)localPlayer) && localPlayer.isPlayerControlled && !localPlayer.isTypingChat && !localPlayer.inTerminalMenu && !localPlayer.inSpecialInteractAnimation && !localPlayer.isInHangarShipRoom && (!Object.op_Implicit((Object)(object)localPlayer.quickMenuManager) || !localPlayer.quickMenuManager.isMenuOpen) && PerkStrength(localPlayer, ProductId.Chalk) != 0 && messenger != null && Object.op_Implicit((Object)(object)localPlayer.gameplayCamera))
			{
				Transform transform = ((Component)localPlayer.gameplayCamera).transform;
				RequestChalkMark(transform.position, transform.forward);
			}
		}

		private unsafe void RequestChalkMark(Vector3 start, Vector3 direction)
		{
			//IL_001f: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			if (network.IsServer)
			{
				TryPlaceChalk(network.LocalClientId, chalkSeed, start, direction);
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(28, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref chalkSeed, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe(ref start);
				((FastBufferWriter)(ref val)).WriteValueSafe(ref direction);
				messenger.SendNamedMessage("saltanis.zabkowysklep/10/chalk-request", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private void ReceiveChalkRequest(ulong client, FastBufferReader reader)
		{
			//IL_001a: 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_003b: 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)
			if (((FastBufferReader)(ref reader)).Length - ((FastBufferReader)(ref reader)).Position == 28)
			{
				int seed = default(int);
				((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref seed, default(ForPrimitives));
				Vector3 start = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref start);
				Vector3 direction = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref direction);
				TryPlaceChalk(client, seed, start, direction);
			}
		}

		private unsafe void TryPlaceChalk(ulong client, int seed, Vector3 start, Vector3 direction)
		{
			//IL_00b3: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: 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_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: 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_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			if (!network.IsServer || !network.ConnectedClients.ContainsKey(client) || !CanDrawOnMoon || seed != round.randomMapSeed || !EnsureCampaign())
			{
				((BaseUnityPlugin)this).Logger.LogDebug((object)"Trail Mix request outside the current landing.");
				return;
			}
			PlayerControllerB val = PlayerFromClient(client);
			if (!Object.op_Implicit((Object)(object)val) || !val.isPlayerControlled || val.isPlayerDead || val.inSpecialInteractAnimation || val.inTerminalMenu)
			{
				return;
			}
			if (Object.op_Implicit((Object)(object)round.shipInnerRoomBounds))
			{
				Bounds bounds = round.shipInnerRoomBounds.bounds;
				if (((Bounds)(ref bounds)).Contains(start))
				{
					return;
				}
			}
			Vector3 val2 = start - ((Component)val).transform.position;
			Vector3 val3 = Vector3.ProjectOnPlane(val2, Vector3.up);
			if (!(((Vector3)(ref val3)).sqrMagnitude < 2.25f) || !(Mathf.Abs(val2.y) < 2.8f) || !(((Vector3)(ref direction)).sqrMagnitude > 0.94f) || !(((Vector3)(ref direction)).sqrMagnitude < 1.06f))
			{
				ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
				val3 = val2;
				logger.LogDebug((object)("Trail Mix target outside reach. Eye offset " + ((object)(*(Vector3*)(&val3))/*cast due to .constrained prefix*/).ToString()));
				return;
			}
			string text = PlayerKey(val);
			if (text == null)
			{
				return;
			}
			int num = Product.Find(ProductId.Chalk).StrengthIn(campaign.Find(text)?.Active ?? 0);
			chalkUses.TryGetValue(text, out var value);
			if (value >= num)
			{
				((BaseUnityPlugin)this).Logger.LogDebug((object)("Trail Mix charges exhausted. Used " + value + ", limit " + num + "."));
				return;
			}
			int num2 = round.collidersAndRoomMaskAndDefault | LayerMask.GetMask(new string[2] { "Terrain", "MiscLevelGeometry" });
			RaycastHit hit = default(RaycastHit);
			if (!Physics.Raycast(start, direction, ref hit, 3.7f, num2, (QueryTriggerInteraction)1))
			{
				((BaseUnityPlugin)this).Logger.LogDebug((object)"Trail Mix could not find a nearby surface.");
				return;
			}
			Vector3 val4 = Vector3.ProjectOnPlane(direction, ((RaycastHit)(ref hit)).normal);
			if (((Vector3)(ref val4)).sqrMagnitude < 0.08f)
			{
				val4 = Vector3.ProjectOnPlane(Vector3.up, ((RaycastHit)(ref hit)).normal);
			}
			if (((Vector3)(ref val4)).sqrMagnitude < 0.08f)
			{
				val4 = Vector3.ProjectOnPlane(((Component)val).transform.forward, ((RaycastHit)(ref hit)).normal);
			}
			if (((Vector3)(ref val4)).sqrMagnitude < 0.08f || chalkHistory.Exists(delegate(ChalkMark mark)
			{
				//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_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val5 = mark.Position - ((RaycastHit)(ref hit)).point;
				return ((Vector3)(ref val5)).sqrMagnitude < 0.035f;
			}))
			{
				return;
			}
			chalkUses[text] = value + 1;
			ChalkMark chalkMark = new ChalkMark
			{
				Id = chalkHistory.Count + 1,
				Position = ((RaycastHit)(ref hit)).point,
				Normal = ((RaycastHit)(ref hit)).normal,
				Up = ((Vector3)(ref val4)).normalized
			};
			chalkHistory.Add(chalkMark);
			DrawChalkMark(chalkMark);
			foreach (ulong connectedClientsId in network.ConnectedClientsIds)
			{
				if (connectedClientsId != network.LocalClientId)
				{
					SendChalkMark(connectedClientsId, chalkMark);
				}
			}
		}

		private unsafe void SendChalkMark(ulong client, ChalkMark mark)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(44, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref chalkSeed, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref mark.Id, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe(ref mark.Position);
				((FastBufferWriter)(ref val)).WriteValueSafe(ref mark.Normal);
				((FastBufferWriter)(ref val)).WriteValueSafe(ref mark.Up);
				messenger.SendNamedMessage("saltanis.zabkowysklep/10/chalk-drawn", client, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private void ReceiveChalkMark(ulong sender, FastBufferReader reader)
		{
			//IL_0025: 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_0069: 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)
			if (sender != 0L || !CanDrawOnMoon || ((FastBufferReader)(ref reader)).Length - ((FastBufferReader)(ref reader)).Position != 44)
			{
				return;
			}
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			if (num == round.randomMapSeed)
			{
				if (num != chalkSeed)
				{
					ClearChalk();
					chalkSeed = num;
				}
				ChalkMark mark = default(ChalkMark);
				((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref mark.Id, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe(ref mark.Position);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref mark.Normal);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref mark.Up);
				DrawChalkMark(mark);
			}
		}

		private void DrawChalkMark(ChalkMark mark)
		{
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Expected O, but got Unknown
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: 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_0189: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Expected O, but got Unknown
			if (!chalkObjects.ContainsKey(mark.Id))
			{
				if (!Object.op_Implicit((Object)(object)chalkMesh))
				{
					chalkMesh = new Mesh
					{
						name = "Trail Mix arrow"
					};
					chalkMesh.vertices = (Vector3[])(object)new Vector3[7]
					{
						new Vector3(-0.045f, -0.24f),
						new Vector3(0.045f, -0.24f),
						new Vector3(-0.045f, 0.03f),
						new Vector3(0.045f, 0.03f),
						new Vector3(-0.15f, 0.03f),
						new Vector3(0.15f, 0.03f),
						new Vector3(0f, 0.23f)
					};
					chalkMesh.triangles = new int[9] { 0, 2, 1, 1, 2, 3, 4, 6, 5 };
					chalkMesh.RecalculateNormals();
					Shader val = Shader.Find("HDRP/Unlit") ?? Shader.Find("Standard");
					chalkMaterial = new Material(val)
					{
						color = new Color(0.94f, 0.87f, 0.29f)
					};
				}
				GameObject val2 = new GameObject("Trail Mix arrow");
				val2.transform.SetPositionAndRotation(mark.Position + mark.Normal * 0.018f, Quaternion.LookRotation(-mark.Normal, mark.Up));
				val2.AddComponent<MeshFilter>().sharedMesh = chalkMesh;
				((Renderer)val2.AddComponent<MeshRenderer>()).sharedMaterial = chalkMaterial;
				chalkObjects.Add(mark.Id, val2);
			}
		}

		private void ClearChalk()
		{
			foreach (GameObject value in chalkObjects.Values)
			{
				if (Object.op_Implicit((Object)(object)value))
				{
					Object.Destroy((Object)(object)value);
				}
			}
			chalkObjects.Clear();
			chalkHistory.Clear();
			chalkUses.Clear();
		}

		private void DisposeChalk()
		{
			ClearChalk();
			if (Object.op_Implicit((Object)(object)chalkMesh))
			{
				Object.Destroy((Object)(object)chalkMesh);
			}
			if (Object.op_Implicit((Object)(object)chalkMaterial))
			{
				Object.Destroy((Object)(object)chalkMaterial);
			}
		}

		private void UpdateCandyLights()
		{
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: 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_0134: Unknown result type (might be due to invalid IL or missing references)
			if (round.allPlayerScripts == null)
			{
				return;
			}
			PlayerControllerB[] allPlayerScripts = round.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (!Object.op_Implicit((Object)(object)val))
				{
					continue;
				}
				byte b = status.Glow.GradeFor(val);
				if (val.isPlayerDead || !val.isPlayerControlled || PlayerNumber(val) == status.BinOccupant || !Object.op_Implicit((Object)(object)round.currentLevel) || !round.currentLevel.planetHasTime || round.inShipPhase || round.shipIsLeaving)
				{
					b = 0;
				}
				candyLights.TryGetValue(val, out var value);
				if (b == 0)
				{
					if (Object.op_Implicit((Object)(object)value))
					{
						((Behaviour)value).enabled = false;
					}
					continue;
				}
				if (!Object.op_Implicit((Object)(object)value))
				{
					GameObject val2 = new GameObject("Glow Drops light");
					val2.transform.SetParent(((Component)val).transform, false);
					val2.transform.localPosition = new Vector3(0f, 1.23f, 0f);
					value = val2.AddComponent<Light>();
					value.type = (LightType)2;
					value.color = new Color(0.75f, 0.93f, 0.6f);
					value.shadows = (LightShadows)0;
					candyLights[val] = value;
				}
				value.range = Product.Find(ProductId.Candy).Strength(b);
				value.intensity = 0.76f + 0.08f * (float)(int)b;
				((Behaviour)value).enabled = true;
			}
		}

		private void ClearCrewPerks()
		{
			glowGrades = default(CrewGrades);
			quietGrades = default(CrewGrades);
			foreach (Light value in candyLights.Values)
			{
				if (Object.op_Implicit((Object)(object)value))
				{
					Object.Destroy((Object)(object)((Component)value).gameObject);
				}
			}
			candyLights.Clear();
		}

		internal float FootstepRange(float distance, PlayerControllerB player)
		{
			byte level = ((Object.op_Implicit((Object)(object)network) && network.IsServer) ? quietGrades.GradeFor(player) : status.Quiet.GradeFor(player));
			int num = Product.Find(ProductId.Chips).Strength(level);
			return distance * (1f - (float)num * 0.01f);
		}

		private static byte PlayerNumber(PlayerControllerB player)
		{
			if (!Object.op_Implicit((Object)(object)player) || player.playerClientId >= 64)
			{
				return 0;
			}
			return (byte)(player.playerClientId + 1);
		}

		internal unsafe void RequestDumpster()
		{
			//IL_0086: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			if (messenger == null || !status.HasShop || shop == null || !Object.op_Implicit((Object)(object)network) || dumpsterRequestFrame == Time.frameCount)
			{
				return;
			}
			dumpsterRequestFrame = Time.frameCount;
			if (network.IsServer)
			{
				ToggleDumpster(network.LocalClientId, status.Visit);
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(4, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<uint>(ref status.Visit, default(ForPrimitives));
				messenger.SendNamedMessage("saltanis.zabkowysklep/10/dumpster", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private void ReceiveDumpster(ulong client, FastBufferReader reader)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (((FastBufferReader)(ref reader)).Length - ((FastBufferReader)(ref reader)).Position == 4)
			{
				uint visit = default(uint);
				((FastBufferReader)(ref reader)).ReadValueSafe<uint>(ref visit, default(ForPrimitives));
				ToggleDumpster(client, visit);
			}
		}

		private bool CanHide(PlayerControllerB player)
		{
			//IL_003e: 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)
			if (Object.op_Implicit((Object)(object)player) && PlayerNumber(player) != 0 && player.isPlayerControlled && !player.isPlayerDead && !player.inSpecialInteractAnimation && !player.inTerminalMenu && !player.isInHangarShipRoom)
			{
				Vector3 val = ((Component)player).transform.position - shop.DumpsterInside;
				return ((Vector3)(ref val)).sqrMagnitude <= 5.2f;
			}
			return false;
		}

		private void ToggleDumpster(ulong client, uint visit)
		{
			if (!network.IsServer || visit != shopVisit || !HasLanded || !IsCompany(round) || shop == null || !network.ConnectedClients.ContainsKey(client))
			{
				return;
			}
			PlayerControllerB val = PlayerFromClient(client);
			if (Object.op_Implicit((Object)(object)val))
			{
				if ((Object)(object)binOccupant == (Object)(object)val)
				{
					binOccupant = null;
				}
				else if ((Object)(object)binPending == (Object)(object)val)
				{
					binPending = null;
				}
				else if (!Object.op_Implicit((Object)(object)binOccupant) && !Object.op_Implicit((Object)(object)binPending) && CanHide(val))
				{
					binPending = val;
					binReadyAt = Time.unscaledTime + 3f;
				}
				SendChangedStatus();
			}
		}

		private void PollDumpster()
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			if (shop == null || !HasLanded || !IsCompany(round))
			{
				binPending = null;
				binOccupant = null;
				return;
			}
			if (Object.op_Implicit((Object)(object)binOccupant))
			{
				if (!binOccupant.isPlayerControlled || binOccupant.isPlayerDead || !network.ConnectedClients.ContainsKey(binOccupant.actualClientId))
				{
					goto IL_00ac;
				}
				if (Time.unscaledTime > binEntryGrace)
				{
					Vector3 val = ((Component)binOccupant).transform.position - shop.DumpsterInside;
					if (((Vector3)(ref val)).sqrMagnitude > 5.2f)
					{
						goto IL_00ac;
					}
				}
			}
			goto IL_00b3;
			IL_00b3:
			if (Object.op_Implicit((Object)(object)binPending))
			{
				if (!CanHide(binPending) || !network.ConnectedClients.ContainsKey(binPending.actualClientId))
				{
					binPending = null;
				}
				else if (Time.unscaledTime >= binReadyAt)
				{
					binOccupant = binPending;
					binEntryGrace = Time.unscaledTime + 1.4f;
					binPending = null;
				}
			}
			return;
			IL_00ac:
			binOccupant = null;
			goto IL_00b3;
		}

		private void UpdateDumpsterLocal()
		{
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			shop?.UpdateDumpsterAppearance(status);
			PlayerControllerB localPlayer = LocalPlayer;
			byte b = PlayerNumber(localPlayer);
			if (b != 0 && Keyboard.current != null && ((ButtonControl)Keyboard.current.eKey).wasPressedThisFrame)
			{
				HandleDumpsterInteract(localPlayer);
			}
			if (b != 0 && status.BinPending == b)
			{
				if (localHidingSince < 0f)
				{
					localHidingSince = Time.unscaledTime;
				}
			}
			else
			{
				localHidingSince = -1f;
			}
			if (shop != null && b != 0 && status.BinOccupant == b && ((NetworkBehaviour)localPlayer).IsOwner && !localPlayer.isPlayerDead)
			{
				if ((Object)(object)hiddenLocal == (Object)(object)localPlayer)
				{
					localPlayer.disableMoveInput = true;
					Vector3 position = ((Component)localPlayer).transform.position;
					Vector2 val = new Vector2(position.x - hiddenAt.x, position.z - hiddenAt.z);
					if (((Vector2)(ref val)).sqrMagnitude > 0.008f)
					{
						((Component)localPlayer).transform.position = new Vector3(hiddenAt.x, position.y, hiddenAt.z);
					}
					return;
				}
				ReleaseDumpsterLocal(moveOut: true);
				hiddenLocal = localPlayer;
				hiddenAt = shop.DumpsterInside;
				hiddenExit = shop.DumpsterExit;
				previousMoveInput = localPlayer.disableMoveInput;
				previousCrouch = localPlayer.isCrouching;
				BoxCollider[] componentsInChildren = ((Component)shop.DumpsterModel).GetComponentsInChildren<BoxCollider>();
				foreach (BoxCollider val2 in componentsInChildren)
				{
					if (!(((Object)((Component)val2).gameObject).name == "Dumpster floor") && !Physics.GetIgnoreCollision((Collider)(object)localPlayer.thisController, (Collider)(object)val2))
					{
						Physics.IgnoreCollision((Collider)(object)localPlayer.thisController, (Collider)(object)val2);
						ignoredBinColliders.Add((Collider)(object)val2);
					}
				}
				localPlayer.Crouch(true);
				localPlayer.TeleportPlayer(hiddenAt, true, 90f, false, true);
				localPlayer.disableMoveInput = true;
			}
			else
			{
				ReleaseDumpsterLocal(moveOut: true);
			}
		}

		private void ReleaseDumpsterLocal(bool moveOut)
		{
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = hiddenLocal;
			hiddenLocal = null;
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.thisController))
			{
				foreach (Collider ignoredBinCollider in ignoredBinColliders)
				{
					if (Object.op_Implicit((Object)(object)ignoredBinCollider))
					{
						Physics.IgnoreCollision((Collider)(object)val.thisController, ignoredBinCollider, false);
					}
				}
			}
			ignoredBinColliders.Clear();
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			val.disableMoveInput = previousMoveInput;
			if (moveOut && !val.isPlayerDead && ((NetworkBehaviour)val).IsOwner)
			{
				Vector3 val2 = ((Component)val).transform.position - hiddenAt;
				if (((Vector3)(ref val2)).sqrMagnitude < 2.2f)
				{
					val.TeleportPlayer(hiddenExit, true, 90f, false, true);
				}
				val.Crouch(previousCrouch);
			}
		}

		private void ResetDumpster(bool moveOut)
		{
			binPending = null;
			binOccupant = null;
			localHidingSince = -1f;
			dumpsterRequestFrame = -1;
			ReleaseDumpsterLocal(moveOut);
		}

		internal bool IsLocalDumpsterOccupant(PlayerControllerB player)
		{
			if (Object.op_Implicit((Object)(object)player))
			{
				return (Object)(object)player == (Object)(object)hiddenLocal;
			}
			return false;
		}

		internal bool HandleDumpsterInteract(PlayerControllerB player)
		{
			byte b = PlayerNumber(player);
			if ((Object)(object)player != (Object)(object)LocalPlayer || b == 0 || player.isTypingChat || (Object.op_Implicit((Object)(object)player.quickMenuManager) && player.quickMenuManager.isMenuOpen) || (b != status.BinPending && b != status.BinOccupant))
			{
				return false;
			}
			RequestDumpster();
			return true;
		}

		private void DrawDumpster()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			if (!(localHidingSince < 0f) || Object.op_Implicit((Object)(object)hiddenLocal))
			{
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(((float)Screen.width - 310f) * 0.5f, (float)Screen.height * 0.64f, 310f, 42f);
				GUI.Box(val, Object.op_Implicit((Object)(object)hiddenLocal) ? ShopLanguage.T("Inside the dumpster   [E] Exit") : ShopLanguage.T("Climbing in   [E] Cancel"));
				if (!(localHidingSince < 0f))
				{
					float num = Mathf.Clamp01((Time.unscaledTime - localHidingSince) / 3f);
					Color color = GUI.color;
					GUI.color = new Color(0.53f, 0.83f, 0.37f);
					GUI.DrawTexture(new Rect(((Rect)(ref val)).x + 9f, ((Rect)(ref val)).yMax - 11f, (((Rect)(ref val)).width - 18f) * num, 5f), (Texture)(object)Texture2D.whiteTexture);
					GUI.color = color;
				}
			}
		}

		private void TrySpawnRoofScrap()
		{
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			RoundManager instance = RoundManager.Instance;
			if (!campaign.RoofScrapIssued && shopPosition.HasValue && HasLanded && Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)round.allItemsList))
			{
				NetworkObject val3 = default(NetworkObject);
				GrabbableObject val4 = default(GrabbableObject);
				List<Item> list = round.allItemsList.itemsList.FindAll((Item item) => Object.op_Implicit((Object)(object)item) && BaseRoofScrap.Contains(((Object)item).name) && item.isScrap && item.maxValue > 0 && item.maxValue >= item.minValue && Object.op_Implicit((Object)(object)item.spawnPrefab) && item.spawnPrefab.TryGetComponent<NetworkObject>(ref val3) && item.spawnPrefab.TryGetComponent<GrabbableObject>(ref val4) && (Object)(object)val4.itemProperties == (Object)(object)item);
				if (list.Count != 0)
				{
					Item val = list[roofScrapRandom.Next(list.Count)];
					int num = roofScrapRandom.Next(val.minValue, val.maxValue);
					int scrapValue = Mathf.Max(1, (int)((float)num * instance.scrapValueMultiplier));
					float num2 = (val.itemSpawnsOnGround ? Mathf.Max(0.4f, val.verticalOffset + 0.1f) : Mathf.Max(0.02f, val.verticalOffset));
					Vector3 val2 = shopPosition.Value + new Vector3(4.3f, 4.35f + num2, 2.6f);
					GrabbableObject component = Object.Instantiate<GameObject>(val.spawnPrefab, val2, Quaternion.Euler(val.restingRotation)).GetComponent<GrabbableObject>();
					component.SetScrapValue(scrapValue);
					((NetworkBehaviour)component).NetworkObject.Spawn(false);
					roofScrap = component;
					campaign.RoofScrapIssued = true;
					needsSave = true;
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Scrap spawned on the Bummer Mart roof: " + val.itemName + " (" + scrapValue + " credits)."));
				}
			}
		}

		private void SyncRoofScrap()
		{
			ulong num = status.RoofScrap;
			GrabbableObject val = default(GrabbableObject);
			if (status.RoofScrapValue > 0 && syncedRoofScrap != num && network.SpawnManager.SpawnedObjects.TryGetValue(num, out var value) && ((Component)value).TryGetComponent<GrabbableObject>(ref val))
			{
				val.SetScrapValue(status.RoofScrapValue);
				syncedRoofScrap = num;
			}
		}

		private void BindMessages()
		{
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Expected O, but got Unknown
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			if (messenger == null && network.CustomMessagingManager != null)
			{
				messenger = network.CustomMessagingManager;
				if (network.IsServer)
				{
					messenger.RegisterNamedMessageHandler("saltanis.zabkowysklep/12/request", new HandleNamedMessageDelegate(ReceiveRequest));
					messenger.RegisterNamedMessageHandler("saltanis.zabkowysklep/12/basket", new HandleNamedMessageDelegate(ReceiveOrder));
					messenger.RegisterNamedMessageHandler("saltanis.zabkowysklep/10/dumpster", new HandleNamedMessageDelegate(ReceiveDumpster));
					messenger.RegisterNamedMessageHandler("saltanis.zabkowysklep/10/chalk-request", new HandleNamedMessageDelegate(ReceiveChalkRequest));
					network.OnClientDisconnectCallback += ForgetClient;
				}
				else
				{
					messenger.RegisterNamedMessageHandler("saltanis.zabkowysklep/12/status", new HandleNamedMessageDelegate(ReceiveStatus));
					messenger.RegisterNamedMessageHandler("saltanis.zabkowysklep/1/cashier", new HandleNamedMessageDelegate(ReceiveCashierCue));
					messenger.RegisterNamedMessageHandler("saltanis.zabkowysklep/10/chalk-drawn", new HandleNamedMessageDelegate(ReceiveChalkMark));
				}
			}
		}

		private void UnbindMessages()
		{
			if (messenger != null)
			{
				messenger.UnregisterNamedMessageHandler("saltanis.zabkowysklep/12/request");
				messenger.UnregisterNamedMessageHandler("saltanis.zabkowysklep/12/basket");
				messenger.UnregisterNamedMessageHandler("saltanis.zabkowysklep/12/status");
				messenger.UnregisterNamedMessageHandler("saltanis.zabkowysklep/1/cashier");
				messenger.UnregisterNamedMessageHandler("saltanis.zabkowysklep/10/dumpster");
				messenger.UnregisterNamedMessageHandler("saltanis.zabkowysklep/10/chalk-request");
				messenger.UnregisterNamedMessageHandler("saltanis.zabkowysklep/10/chalk-drawn");
				if (Object.op_Implicit((Object)(object)network))
				{
					network.OnClientDisconnectCallback -= ForgetClient;
				}
				messenger = null;
			}
		}

		private void ResetMessages()
		{
			ApplyStatus(default(ShopStatus));
			lastStatus.Clear();
			orderReplies.Clear();
			receivedStatus = false;
			nextRequest = 0f;
			nextOrder = 0uL;
			pendingOrder = 0uL;
			feedback = null;
		}

		private void ForgetClient(ulong client)
		{
			lastStatus.Remove(client);
			orderReplies.Remove(client);
			baskets.Remove(client);
			shopVisitors.Remove(client);
		}

		private unsafe void RequestInitialState()
		{
			//IL_007c: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			if (messenger == null || !network.IsConnectedClient)
			{
				return;
			}
			if (pendingOrder != 0L && Time.unscaledTime - pendingSince >= 2f)
			{
				pendingSince = Time.unscaledTime;
				SendOrder();
			}
			else if (!receivedStatus && !(Time.unscaledTime < nextRequest))
			{
				nextRequest = Time.unscaledTime + 2f;
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(1, (Allocator)2, -1);
				try
				{
					byte b = 1;
					((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
					messenger.SendNamedMessage("saltanis.zabkowysklep/12/request", 0uL, val, (NetworkDelivery)3);
				}
				finally
				{
					((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
				}
			}
		}

		private void ReceiveRequest(ulong client, FastBufferReader reader)
		{
			if (!network.IsServer || !network.ConnectedClients.ContainsKey(client) || ((FastBufferReader)(ref reader)).Length - ((FastBufferReader)(ref reader)).Position != 1)
			{
				return;
			}
			SendStatus(client, StatusFor(client), default(OrderReply), 0L);
			if (!CanDrawOnMoon)
			{
				return;
			}
			foreach (ChalkMark item in chalkHistory)
			{
				SendChalkMark(client, item);
			}
		}

		private void ReceiveOrder(ulong client, FastBufferReader reader)
		{
			//IL_003a: 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_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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_0079: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			if (network.IsServer && network.ConnectedClients.ContainsKey(client) && ((FastBufferReader)(ref reader)).Length - ((FastBufferReader)(ref reader)).Position == 20)
			{
				ulong num = default(ulong);
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref num, default(ForPrimitives));
				uint visit = default(uint);
				((FastBufferReader)(ref reader)).ReadValueSafe<uint>(ref visit, default(ForPrimitives));
				int cycle = default(int);
				((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref cycle, default(ForPrimitives));
				byte action = default(byte);
				((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref action, default(ForPrimitives));
				ushort item = default(ushort);
				((FastBufferReader)(ref reader)).ReadValueSafe<ushort>(ref item, default(ForPrimitives));
				byte level = default(byte);
				((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref level, default(ForPrimitives));
				if (num != 0L)
				{
					EvaluateOrder(client, num, visit, cycle, (BasketAction)action, (ProductId)item, level);
				}
			}
		}

		private void EvaluateOrder(ulong client, ulong sequence, uint visit, int cycle, BasketAction action, ProductId item, byte level)
		{
			if (orderReplies.TryGetValue(client, out var value) && sequence < value.Sequence)
			{
				return;
			}
			if (sequence != value.Sequence)
			{
				value.Sequence = sequence;
				value.Result = UpdateBasket(client, visit, cycle, action, item, level);
				orderReplies[client] = value;
				if (value.Result == PurchaseResult.Bought)
				{
					CueCashier(CashierCue.Purchase);
				}
			}
			SendStatus(client, StatusFor(client), value, 0L);
		}

		internal void SendBasketAction(BasketAction action, ProductId item = ProductId.None, byte level = 0)
		{
			if (pendingOrder == 0L && status.HasShop && Object.op_Implicit((Object)(object)network) && messenger != null)
			{
				pendingOrder = ++nextOrder;
				pendingVisit = status.Visit;
				pendingTarget = status.Target;
				pendingAction = action;
				pendingProduct = item;
				pendingLevel = level;
				pendingSince = Time.unscaledTime;
				feedback = ((action == BasketAction.Checkout) ? ShopLanguage.T("Checking your order…") : null);
				if (network.IsServer)
				{
					EvaluateOrder(network.LocalClientId, pendingOrder, pendingVisit, pendingTarget, action, item, level);
				}
				else
				{
					SendOrder();
				}
			}
		}

		private unsafe void SendOrder()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(20, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref pendingOrder, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<uint>(ref pendingVisit, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref pendingTarget, default(ForPrimitives));
				byte b = (byte)pendingAction;
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
				ushort num = (ushort)pendingProduct;
				((FastBufferWriter)(ref val)).WriteValueSafe<ushort>(ref num, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref pendingLevel, default(ForPrimitives));
				messenger.SendNamedMessage("saltanis.zabkowysklep/12/basket", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private ShopStatus StatusFor(ulong client)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			string text = PlayerKey(PlayerFromClient(client));
			Wallet wallet = ((text == null) ? null : campaign?.Find(text));
			int num = ((campaign != null) ? (campaign.Cycle + 1) : 0);
			ulong value;
			return new ShopStatus
			{
				HasShop = shopPosition.HasValue,
				Position = shopPosition.GetValueOrDefault(),
				Open = OpenForOrders,
				Visit = shopVisit,
				Target = num,
				Basket = (baskets.TryGetValue(client, out value) ? value : 0),
				Balance = (wallet?.Balance ?? 0),
				Ordered = (wallet?.OrdersFor(num) ?? 0),
				Active = (wallet?.Active ?? 0),
				SoldOut = ((stockReady && campaign != null) ? campaign.SoldOut : ProductId.None),
				Glow = glowGrades,
				Quiet = quietGrades,
				BinPending = PlayerNumber(binPending),
				BinOccupant = PlayerNumber(binOccupant),
				BagOwners = bagOwners,
				RoofScrap = ((Object.op_Implicit((Object)(object)roofScrap) && ((NetworkBehaviour)roofScrap).IsSpawned) ? ((NetworkBehaviour)roofScrap).NetworkObjectId : 0),
				RoofScrapValue = ((Object.op_Implicit((Object)(object)roofScrap) && ((NetworkBehaviour)roofScrap).IsSpawned) ? roofScrap.scrapValue : 0)
			};
		}

		private void SendChangedStatus()
		{
			if (messenger == null)
			{
				return;
			}
			foreach (ulong connectedClientsId in network.ConnectedClientsIds)
			{
				ShopStatus shopStatus = StatusFor(connectedClientsId);
				if (!lastStatus.TryGetValue(connectedClientsId, out var value) || !value.Equals(shopStatus))
				{
					SendStatus(connectedClientsId, shopStatus, default(OrderReply), 0L);
				}
			}
		}

		private void SendSaleReceipts(long payout, long crewSupplement)
		{
			foreach (ulong connectedClientsId in network.ConnectedClientsIds)
			{
				string text = PlayerKey(PlayerFromClient(connectedClientsId));
				if (text != null)
				{
					long num = campaign.PayConnectedPlayerForSale(text, payout, crewSupplement);
					if (num > 0 && messenger != null)
					{
						ShopStatus current2 = StatusFor(connectedClientsId);
						long payout2 = num;
						SendStatus(connectedClientsId, current2, default(OrderReply), payout2);
					}
				}
			}
		}

		private unsafe void SendStatus(ulong client, ShopStatus current, OrderReply reply = default(OrderReply), long payout = 0L)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_007b: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: 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_01fa: 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_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: 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)
			//IL_023f: 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_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			lastStatus[client] = current;
			if (client == network.LocalClientId)
			{
				HandleStatus(current, reply, payout);
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(143, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref current.HasShop, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe(ref current.Position);
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref current.Open, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<uint>(ref current.Visit, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<long>(ref current.Balance, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref current.Target, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref current.Basket, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref current.Ordered, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref current.Active, default(ForPrimitives));
				ushort soldOut = (ushort)current.SoldOut;
				((FastBufferWriter)(ref val)).WriteValueSafe<ushort>(ref soldOut, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref current.Glow.Present, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref current.Glow.Low, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref current.Glow.High, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref current.Quiet.Present, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref current.Quiet.Low, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref current.Quiet.High, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref current.BinPending, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref current.BinOccupant, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref current.BagOwners, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref current.RoofScrap, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref current.RoofScrapValue, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref reply.Sequence, default(ForPrimitives));
				byte result = (byte)reply.Result;
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref result, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<long>(ref payout, default(ForPrimitives));
				messenger.SendNamedMessage("saltanis.zabkowysklep/12/status", client, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private void ReceiveStatus(ulong client, FastBufferReader reader)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			if (client == 0L && ((FastBufferReader)(ref reader)).Length - ((FastBufferReader)(ref reader)).Position == 143)
			{
				ShopStatus current = default(ShopStatus);
				OrderReply reply = default(OrderReply);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref current.HasShop, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe(ref current.Position);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref current.Open, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<uint>(ref current.Visit, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<long>(ref current.Balance, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref current.Target, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref current.Basket, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref current.Ordered, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref current.Active, default(ForPrimitives));
				ushort soldOut = default(ushort);
				((FastBufferReader)(ref reader)).ReadValueSafe<ushort>(ref soldOut, default(ForPrimitives));
				current.SoldOut = (ProductId)soldOut;
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref current.Glow.Present, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref current.Glow.Low, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref current.Glow.High, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref current.Quiet.Present, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref current.Quiet.Low, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref current.Quiet.High, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref current.BinPending, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref current.BinOccupant, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref current.BagOwners, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref current.RoofScrap, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref current.RoofScrapValue, default(ForPrimitives));
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref reply.Sequence, default(ForPrimitives));
				byte result = default(byte);
				((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref result, default(ForPrimitives));
				long payout = default(long);
				((FastBufferReader)(ref reader)).ReadValueSafe<long>(ref payout, default(ForPrimitives));
				reply.Result = (PurchaseResult)result;
				HandleStatus(current, reply, payout);
			}
		}

		private void HandleStatus(ShopStatus current, OrderReply reply, long payout)
		{
			receivedStatus = true;
			if (!current.HasShop || current.Visit != status.Visit)
			{
				pendingOrder = 0uL;
				feedback = null;
			}
			ApplyStatus(current);
			if (payout > 0)
			{
				walletHud.RecordPayout(payout);
			}
			if (pendingOrder != 0L && reply.Sequence == pendingOrder)
			{
				pendingOrder = 0uL;
				switch (reply.Result)
				{
				case PurchaseResult.Bought:
					feedback = ShopLanguage.T("Purchase complete. Your perk kicks in on the next work moon.");
					break;
				case PurchaseResult.Added:
					feedback = ShopLanguage.T("Added to your basket.");
					break;
				case PurchaseResult.LevelChanged:
					feedback = ShopLanguage.T("Changed the tier in your basket.");
					break;
				case PurchaseResult.Removed:
					feedback = ShopLanguage.T("Removed from your basket.");
					break;
				case PurchaseResult.AlreadyInBasket:
					feedback = ShopLanguage.T("That one's already in your basket.");
					break;
				case PurchaseResult.EmptyBasket:
					feedback = ShopLanguage.T("Your basket is empty.");
					break;
				case PurchaseResult.Closed:
					feedback = ShopLanguage.T("Checkout is locked. Meet your quota first.");
					break;
				case PurchaseResult.TooFar:
					feedback = ShopLanguage.T("Move closer to the item or the checkout.");
					break;
				case PurchaseResult.AlreadyBought:
					feedback = ShopLanguage.T("You already bought this perk for the next quota.");
					break;
				case PurchaseResult.Limit:
					feedback = ShopLanguage.T("Two products per customer, per quota. Yes, even for you.");
					break;
				case PurchaseResult.InsufficientFunds:
					feedback = ShopLanguage.T("You're short on Bummer Money.");
					break;
				case PurchaseResult.SoldOut:
					feedback = ShopLanguage.T("That item's sold out.");
					break;
				default:
					feedback = ShopLanguage.T("That item is unavailable.");
					break;
				}
			}
		}

		internal static bool IsCompany(StartOfRound current)
		{
			if (Object.op_Implicit((Object)(object)current) && Object.op_Implicit((Object)(object)current.currentLevel))
			{
				return current.currentLevel.sceneName == "CompanyBuilding";
			}
			return false;
		}

		private void Awake()
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			Instance = this;
			if (Chainloader.PluginInfos.TryGetValue("local.lethalcompany.polskiterminal", out var value))
			{
				try
				{
					ShopLanguage.LoadPolish(Path.Combine(Path.GetDirectoryName(value.Location), "Resources", "Zalka.pl"));
				}
				catch (IOException ex)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not load the Polish shop resources. " + ex.Message));
				}
				catch (ArgumentException ex2)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not load the Polish shop resources. " + ex2.Message));
				}
			}
			BindSettings();
			SceneManager.sceneLoaded += OnSceneLoaded;
			SceneManager.sceneUnloaded += OnSceneUnloaded;
			harmony = new Harmony("saltanis.zabkowysklep");
			harmony.PatchAll();
			PerkPatches.AttachHealthIntegration(harmony);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Bummer Mart loaded 0.14.0");
		}

		private void BindSettings()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			string text = (File.Exists(((BaseUnityPlugin)this).Config.ConfigFilePath) ? File.ReadAllText(((BaseUnityPlugin)this).Config.ConfigFilePath) : string.Empty);
			bool saveOnConfigSet = ((BaseUnityPlugin)this).Config.SaveOnConfigSet;
			bool flag = false;
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = false;
			try
			{
				musicVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "MusicVolume", 0.68f, new ConfigDescription(ShopLanguage.T("Music volume inside the shop. Set to 0 to mute."), (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
				chalkKey = ((BaseUnityPlugin)this).Config.Bind<Key>("Controls", "TrailMarkerKey", (Key)24, ShopLanguage.T("Key for marking a route after buying Trail Mix Crayons."));
				if (text.Contains("[Dźwięk]"))
				{
					ConfigEntry<float> val = ((BaseUnityPlugin)this).Config.Bind<float>("Dźwięk", "GlosnoscMuzyki", 0.68f, (ConfigDescription)null);
					if ((!text.Contains("Żalka v0.4.0") || !Mathf.Approximately(val.Value, 0.52f)) && (!text.Contains("Żabkowy Sklep v0.3.2") || !Mathf.Approximately(val.Value, 0.16f)) && !text.Contains("[Audio]"))
					{
						musicVolume.Value = Mathf.Clamp01(val.Value);
					}
					((BaseUnityPlugin)this).Config.Remove(((ConfigEntryBase)val).Definition);
					flag = true;
				}
				if (text.Contains("[Sterowanie]"))
				{
					ConfigEntry<Key> val2 = ((BaseUnityPlugin)this).Config.Bind<Key>("Sterowanie", "ZnacznikSladkow", (Key)24, (ConfigDescription)null);
					if (!text.Contains("[Controls]"))
					{
						chalkKey.Value = val2.Value;
					}
					((BaseUnityPlugin)this).Config.Remove(((ConfigEntryBase)val2).Definition);
					flag = true;
				}
				if (text.Contains("ZlomNaStart"))
				{
					ConfigEntry<bool> val3 = ((BaseUnityPlugin)this).Config.Bind<bool>("Testy", "ZlomNaStart", false, (ConfigDescription)null);
					((BaseUnityPlugin)this).Config.Remove(((ConfigEntryBase)val3).Definition);
					flag = true;
				}
			}
			finally
			{
				((BaseUnityPlugin)this).Config.SaveOnConfigSet = saveOnConfigSet;
			}
			if (saveOnConfigSet || flag)
			{
				((BaseUnityPlugin)this).Config.Save();
			}
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
			SceneManager.sceneUnloaded -= OnSceneUnloaded;
			shop?.Dispose();
			shop = null;
			ShopMusic.ReleaseClip();
			ResetSession();
			DisposeChalk();
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			Instance = null;
		}

		private void Update()
		{
			NetworkManager singleton = NetworkManager.Singleton;
			StartOfRound instance = StartOfRound.Instance;
			if (!Object.op_Implicit((Object)(object)singleton) || !singleton.IsListening || !Object.op_Implicit((Object)(object)instance) || !((NetworkBehaviour)instance).IsSpawned)
			{
				if ((Object)(object)network != (Object)null || (Object)(object)round != (Object)null)
				{
					ResetSession();
				}
				return;
			}
			if ((Object)(object)singleton != (Object)(object)network || (Object)(object)instance != (Object)(object)round)
			{
				ResetSession();
				network = singleton;
				round = instance;
				lanSession = Guid.NewGuid().ToString("N");
			}
			BindMessages();
			if (Time.unscaledTime >= nextTick)
			{
				nextTick = Time.unscaledTime + 0.2f;
				if (network.IsServer)
				{
					PollHost();
				}
				else
				{
					RequestInitialState();
					SyncRoofScrap();
				}
			}
			shop?.HandleInput();
			shop?.UpdateAtmosphere(LocalPlayer, musicVolume.Value);
			bagInventory.Update(round, bagOwners, network.IsServer || receivedStatus);
			UpdateWaterRegeneration(LocalPlayer, Time.deltaTime);
			UpdateDumpsterLocal();
			UpdateCandyLights();
			UpdateChalk();
		}

		private void ResetSession()
		{
			UnbindMessages();
			shop?.Close();
			shopPosition = null;
			shopVisit = 0u;
			stockReady = false;
			ResetCashierCues();
			ResetDumpster(moveOut: false);
			ClearCrewPerks();
			ClearChalk();
			bagInventory.Reset();
			bagOwners = 0uL;
			waterInterval = 0;
			waterRegenRemaining = 0f;
			baskets.Clear();
			roofScrap = null;
			syncedRoofScrap = null;
			walletHud.Clear();
			workLanding = false;
			network = null;
			round = null;
			slot = null;
			campaign = null;
			loadFailed = false;
			needsSave = false;
			nextTick = 0f;
			ResetMessages();
		}

		private bool EnsureCampaign()
		{
			GameNetworkManager instance = GameNetworkManager.Instance;
			TimeOfDay instance2 = TimeOfDay.Instance;
			if (!Object.op_Implicit((Object)(object)network) || !network.IsServer || !Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)instance2) || !Object.op_Implicit((Object)(object)round) || !((NetworkBehaviour)round).IsSpawned || round.isChallengeFile || string.IsNullOrWhiteSpace(instance.currentSaveFileName))
			{
				return false;
			}
			string currentSaveFileName = instance.currentSaveFileName;
			if (slot != currentSaveFileName)
			{
				slot = currentSaveFileName;
				stockReady = false;
				baskets.Clear();
				roofScrap = null;
				loadFailed = false;
				needsSave = false;
				try
				{
					string text = ES3.Load<string>("saltanis.zabkowysklep.campaign.v1", slot, string.Empty);
					campaign = (string.IsNullOrEmpty(text) ? new Campaign
					{
						Cycle = instance2.timesFulfilledQuota
					} : JsonUtility.FromJson<Campaign>(text));
					if (campaign == null || campaign.Wallets == null || campaign.Cycle > instance2.timesFulfilledQuota)
					{
						throw new InvalidOperationException("The wallet data does not match the campaign save.");
					}
				}
				catch (Exception ex)
				{
					loadFailed = true;
					campaign = null;
					((BaseUnityPlugin)this).Logger.LogError((object)("Could not load player wallets. " + ex));
				}
			}
			if (!loadFailed)
			{
				return campaign != null;
			}
			return false;
		}

		private void PollHost()
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			if (shop == null || !IsCompany(round) || round.shipIsLeaving)
			{
				shopPosition = null;
				stockReady = false;
				baskets.Clear();
			}
			else if (!shopPosition.HasValue)
			{
				shopPosition = shop.Position;
				shopVisit++;
			}
			if (EnsureCampaign())
			{
				SyncCycle();
				if (shopPosition.HasValue && !round.inShipPhase && !stockReady)
				{
					if (campaign.RefreshStock())
					{
						needsSave = true;
					}
					stockReady = true;
				}
				TrySpawnRoofScrap();
				if (HasLanded && !IsCompany(round) && Object.op_Implicit((Object)(object)round.currentLevel) && round.currentLevel.planetHasTime)
				{
					workLanding = true;
					if (!campaign.StartedWork)
					{
						campaign.StartWork();
						needsSave = true;
					}
					foreach (ulong connectedClientsId in network.ConnectedClientsIds)
					{
						PlayerControllerB player = PlayerFromClient(connectedClientsId);
						string text = PlayerKey(player);
						if (text != null && (campaign.Find(text)?.LastParticipation ?? (-1)) != campaign.Cycle)
						{
							campaign.RegisterWorker(text);
							needsSave = true;
						}
					}
				}
			}
			bagOwners = 0uL;
			glowGrades = default(CrewGrades);
			quietGrades = default(CrewGrades);
			if (campaign != null)
			{
				foreach (ulong connectedClientsId2 in network.ConnectedClientsIds)
				{
					PlayerControllerB val = PlayerFromClient(connectedClientsId2);
					if (!Object.op_Implicit((Object)(object)val) || val.isPlayerDead)
					{
						continue;
					}
					Wallet wallet = campaign.Find(PlayerKey(val));
					if (wallet != null)
					{
						if ((wallet.Active & 0x8000000) != 0L)
						{
							bagOwners |= BagInventory.Bit(val);
						}
						glowGrades.Add(val, Product.Find(ProductId.Candy).LevelIn(wallet.Active));
						quietGrades.Add(val, Product.Find(ProductId.Chips).LevelIn(wallet.Active));
					}
				}
			}
			PollDumpster();
			SendChangedStatus();
			PollCashierCues();
		}

		private void SyncCycle()
		{
			int timesFulfilledQuota = TimeOfDay.Instance.timesFulfilledQuota;
			if (timesFulfilledQuota > campaign.Cycle)
			{
				campaign.AdvanceTo(timesFulfilledQuota);
				needsSave = true;
			}
		}

		internal void RecordSale(int paidCredits, int crewValue)
		{
			if (IsCompany(round) && paidCredits > 0 && EnsureCampaign())
			{
				SyncCycle();
				long payout = campaign.RecordSale(paidCredits);
				int num = Mathf.Clamp((int)((float)crewValue * round.companyBuyingRate), 0, paidCredits);
				needsSave = true;
				SendSaleReceipts(payout, 5L * (long)num);
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Recorded scrap sale for " + paidCredits + " credits."));
			}
		}

		internal void EndWorkDay(StartOfRound current)
		{
			if (!((Object)(object)current != (Object)(object)round) && workLanding && EnsureCampaign())
			{
				workLanding = false;
				campaign.EndWorkDay();
				needsSave = true;
			}
		}

		internal void OnPlayerDeath(PlayerControllerB player)
		{
			if (Object.op_Implicit((Object)(object)player) && player.isPlayerDead && EnsureCampaign())
			{
				baskets.Remove(player.actualClientId);
				string text = PlayerKey(player);
				if (text != null)
				{
					campaign.OnDeath(text);
					needsSave = true;
				}
			}
		}

		internal void SaveCampaign()
		{
			if (!needsSave || !EnsureCampaign() || !round.inShipPhase || round.shipIsLeaving)
			{
				return;
			}
			SyncCycle();
			try
			{
				ES3.Save<string>("saltanis.zabkowysklep.campaign.v1", JsonUtility.ToJson((object)campaign), slot);
				needsSave = false;
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Could not save player wallets. " + ex));
			}
		}

		internal void ResetCampaign()
		{
			if (!Object.op_Implicit((Object)(object)network) || !network.IsServer || !Object.op_Implicit((Object)(object)GameNetworkManager.Instance) || !Object.op_Implicit((Object)(object)round) || round.isChallengeFile)
			{
				return;
			}
			string currentSaveFileName = GameNetworkManager.Instance.currentSaveFileName;
			if (string.IsNullOrWhiteSpace(currentSaveFileName))
			{
				return;
			}
			try
			{
				if (ES3.KeyExists("saltanis.zabkowysklep.campaign.v1", currentSaveFileName))
				{
					ES3.DeleteKey("saltanis.zabkowysklep.campaign.v1", currentSaveFileName);
				}
				slot = null;
				campaign = null;
				stockReady = false;
				workLanding = false;
				roofScrap = null;
				baskets.Clear();
				needsSave = false;
				lastStatus.Clear();
			}
			catch (Exception ex)
			{
				campaign = null;
				loadFailed = true;
				slot = currentSaveFileName;
				((BaseUnityPlugin)this).Logger.LogError((object)("Could not reset player wallets. " + ex));
			}
		}

		private static PlayerControllerB PlayerFromClient(ulong client)
		{
			PlayerControllerB[] array = StartOfRound.Instance?.allPlayerScripts;
			if (array == null)
			{
				return null;
			}
			PlayerControllerB[] array2 = array;
			foreach (PlayerControllerB val in array2)
			{
				if (Object.op_Implicit((Object)(object)val) && val.actualClientId == client && (val.isPlayerControlled || val.isPlayerDead))
				{
					return val;
				}
			}
			return null;
		}

		private string PlayerKey(PlayerControllerB player)
		{
			if (!Object.op_Implicit((Object)(object)player))
			{
				return null;
			}
			if (player.playerSteamId != 0L)
			{
				return "steam:" + player.playerSteamId;
			}
			if (!GameNetworkManager.Instance.disableSteam)
			{
				return null;
			}
			return "lan:" + lanSession + ":" + player.actualClientId;
		}

		private PurchaseResult UpdateBasket(ulong client, uint visit, int target, BasketAction action, ProductId id, byte level)
		{
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			if (!shopPosition.HasValue || !HasLanded || !IsCompany(round) || !EnsureCampaign() || !stockReady || visit != shopVisit || target != campaign.Cycle + 1)
			{
				return PurchaseResult.Closed;
			}
			PlayerControllerB player = PlayerFromClient(client);
			string text = PlayerKey(player);
			if (text == null || player.isPlayerDead || !player.isPlayerControlled)
			{
				return PurchaseResult.TooFar;
			}
			baskets.TryGetValue(client, out var value);
			Product product = Product.Find(id);
			if (action == BasketAction.Add)
			{
				if (product == null || !product.ValidLevel(level))
				{
					return PurchaseResult.Unavailable;
				}
				if (campaign.IsSoldOut(id))
				{
					return PurchaseResult.SoldOut;
				}
				if (!Array.Exists(ShopView.Displays, (ShopView.ProductDisplay display) => display.Item == id && display.Level == level && CanReach(player, shopPosition.Value + display.TouchPoint, 6.25f)))
				{
					return PurchaseResult.TooFar;
				}
				byte b = product.LevelIn(value);
				if (b == level)
				{
					return PurchaseResult.AlreadyInBasket;
				}
				ulong num = campaign.Find(text)?.OrdersFor(target) ?? 0;
				if (product.LevelIn(num) != 0)
				{
					return PurchaseResult.AlreadyBought;
				}
				ulong num2 = product.WithLevel(value, level);
				if (Product.Count(num | num2) > 2)
				{
					return PurchaseResult.Limit;
				}
				baskets[client] = num2;
				if (b != 0)
				{
					return PurchaseResult.LevelChanged;
				}
				return PurchaseResult.Added;
			}
			if (!CanReach(player, ShopView.RegisterAt(shopPosition.Value), 9f))
			{
				return PurchaseResult.TooFar;
			}
			switch (action)
			{
			case BasketAction.Remove:
				if (product == null || !product.ValidLevel(level) || product.LevelIn(value) != level)
				{
					return PurchaseResult.Unavailable;
				}
				baskets[client] = product.Without(value);
				return PurchaseResult.Removed;
			case BasketAction.Checkout:
				if (id == ProductId.None && level == 0)
				{
					if (!OpenForOrders)
					{
						return PurchaseResult.Closed;
					}
					PurchaseResult num3 = campaign.BuyBasket(text, value);
					if (num3 == PurchaseResult.Bought)
					{
						baskets.Remove(client);
						needsSave = true;
					}
					return num3;
				}
				goto default;
			default:
				return PurchaseResult.Unavailable;
			}
		}

		private bool CanReach(PlayerControllerB player, Vector3 point, float rangeSquared)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_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)
			Vector3 val = ((Component)player).transform.position - point;
			if (((Vector3)(ref val)).sqrMagnitude > rangeSquared)
			{
				return false;
			}
			return !Physics.Linecast(((Component)player).transform.position + Vector3.up * (player.isCrouching ? 0.9f : 1.5f), point, round.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1);
		}

		private Vector3? FindShopPosition(Scene scene)
		{
			//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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be