Decompiled source of CargoBackpack v1.0.23

CargoBackpack.dll

Decompiled 4 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using REPOLib.Modules;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
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 CargoBackpackMod
{
	public sealed class CargoBackpackController : MonoBehaviour
	{
		private static readonly FieldInfo OwnerId = AccessTools.Field(typeof(ItemEquippable), "ownerPlayerId");

		private static readonly FieldInfo Tumbling = AccessTools.Field(typeof(PlayerAvatar), "isTumbling");

		private static readonly FieldInfo Crawling = AccessTools.Field(typeof(PlayerAvatar), "isCrawling");

		private static readonly FieldInfo Crouching = AccessTools.Field(typeof(PlayerAvatar), "isCrouching");

		private static readonly FieldInfo GrabbedObject = AccessTools.Field(typeof(PhysGrabber), "grabbedPhysGrabObject");

		private static readonly FieldInfo InputDisabled = AccessTools.Field(typeof(PlayerController), "InputDisableTimer");

		private ItemAttributes _attributes;

		private ItemEquippable _equippable;

		private PhotonView _view;

		private readonly ItemEquippable[] _items = (ItemEquippable[])(object)new ItemEquippable[4];

		private readonly CargoSlotLedger _ledger = new CargoSlotLedger();

		private float _nextInput;

		private float _equipCheckAt;

		private int _requestedEquipSlot = -1;

		private bool _localUse;

		private GameObject _wornModel;

		private PlayerAvatar _wornOwner;

		private readonly float[] _nextRecoveryAttempt = new float[4];

		private float _recoveryReadyAt;

		private float _recoveryGiveUpAt;

		private int _activeRecoverySlot = -1;

		private GameObject _activeRecoveryObject;

		private float _activeRecoveryDeadline;

		internal ItemEquippable Equippable => _equippable;

		internal string PersistentName => CargoPersistence.GetInstanceName(_attributes);

		internal bool IsOwnedByLocalPlayer()
		{
			if ((Object)(object)_equippable == (Object)null || !_equippable.IsEquipped())
			{
				return false;
			}
			if (!SemiFunc.IsMultiplayer())
			{
				return true;
			}
			if (OwnerId == null || (Object)(object)PhysGrabber.instance == (Object)null || (Object)(object)PhysGrabber.instance.photonView == (Object)null)
			{
				return false;
			}
			return (int)OwnerId.GetValue(_equippable) == PhysGrabber.instance.photonView.ViewID;
		}

		private void Awake()
		{
			_attributes = ((Component)this).GetComponent<ItemAttributes>();
			_equippable = ((Component)this).GetComponent<ItemEquippable>();
			_view = ((Component)this).GetComponent<PhotonView>();
		}

		private void Start()
		{
			CargoPersistence.RegisterItem(_attributes);
			CargoItemFactory.ApplyRuntimeIcon(_attributes);
			_recoveryReadyAt = Time.unscaledTime + 5f;
			_recoveryGiveUpAt = Time.unscaledTime + 30f;
		}

		internal void BeginLocalUse()
		{
			_localUse = true;
		}

		internal void EndLocalUse()
		{
			_localUse = false;
		}

		internal void PrepareDrop()
		{
			_localUse = false;
		}

		internal int GetCargoHash(int slot)
		{
			if (slot < 0 || slot >= 4)
			{
				return 0;
			}
			return _ledger.Read(slot, CargoPersistence.Read(PersistentName, slot));
		}

		internal ItemEquippable GetCargoItem(int slot)
		{
			if (slot < 0 || slot >= 4)
			{
				return null;
			}
			if ((Object)(object)_items[slot] == (Object)null)
			{
				_items[slot] = CargoPersistence.FindItem(GetCargoHash(slot));
			}
			return _items[slot];
		}

		internal bool IsCargoSlotOccupied(int slot)
		{
			return GetCargoHash(slot) != 0;
		}

		internal void RuntimeTick()
		{
			UpdateWearable();
			if ((Object)(object)_wornModel != (Object)null)
			{
				CargoBackpackVisuals.UpdateSlotLights(_wornModel, IsCargoSlotOccupied);
			}
			CheckEquipAttempt();
			for (int i = 0; i < 4; i++)
			{
				ItemEquippable cargoItem = GetCargoItem(i);
				if ((Object)(object)cargoItem != (Object)null && !cargoItem.IsEquipped() && (Object)(object)((Component)cargoItem).GetComponent<CargoBackpackController>() == (Object)null)
				{
					if (CargoStoredItemState.CanAttach(cargoItem, this))
					{
						CargoStoredItemState.Store(cargoItem, this, i);
						continue;
					}
					_items[i] = null;
					RecoverMissingItem(i);
				}
				else if ((Object)(object)cargoItem == (Object)null && GetCargoHash(i) != 0)
				{
					RecoverMissingItem(i);
				}
			}
		}

		internal void ToggleVirtualCargoSlot(int slot)
		{
			if (!_localUse || slot < 0 || slot > 3 || Time.unscaledTime < _nextInput || (Object)(object)PlayerController.instance == (Object)null || SemiFunc.RunIsArena() || (InputDisabled != null && (float)InputDisabled.GetValue(PlayerController.instance) > 0f))
			{
				return;
			}
			_nextInput = Time.unscaledTime + 0.3f;
			int cargoHash = GetCargoHash(slot);
			ItemEquippable val = CargoRuntime.FindHeldItem();
			if ((cargoHash == 0 && (Object)(object)val == (Object)null) || ((Object)(object)val != (Object)null && (val.IsEquipped() || (Object)(object)((Component)val).GetComponent<CargoBackpackController>() != (Object)null || CargoStoredItemState.Contains(val))))
			{
				return;
			}
			if (SemiFunc.IsMultiplayer())
			{
				if ((Object)(object)_view != (Object)null && ((Object)(object)val == (Object)null || (Object)(object)((MonoBehaviourPun)val).photonView != (Object)null))
				{
					_view.RPC("CargoRequestSlotRPC", (RpcTarget)2, new object[3]
					{
						slot,
						cargoHash,
						((Object)(object)val != (Object)null) ? ((MonoBehaviourPun)val).photonView.ViewID : 0
					});
				}
			}
			else
			{
				CommitRequest(slot, cargoHash, val, PlayerAvatar.instance);
			}
		}

		[PunRPC]
		private void CargoRequestSlotRPC(int slot, int expected, int itemViewId, PhotonMessageInfo info)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if (!PhotonNetwork.IsMasterClient)
			{
				return;
			}
			PlayerAvatar val = ResolveOwner();
			if (!((Object)(object)val == (Object)null) && !((Object)(object)val.photonView == (Object)null) && info.Sender == val.photonView.Owner)
			{
				PhotonView val2 = ((itemViewId != 0) ? PhotonView.Find(itemViewId) : null);
				if (itemViewId == 0 || !((Object)(object)val2 == (Object)null))
				{
					ItemEquippable incoming = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<ItemEquippable>() : null);
					CommitRequest(slot, expected, incoming, val);
				}
			}
		}

		private void CommitRequest(int slot, int expected, ItemEquippable incoming, PlayerAvatar owner)
		{
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			if (slot < 0 || slot > 3 || (Object)(object)owner == (Object)null || !_equippable.IsEquipped() || expected != GetCargoHash(slot))
			{
				return;
			}
			ItemEquippable val = ((expected != 0) ? GetCargoItem(slot) : null);
			if ((expected != 0 && ((Object)(object)val == (Object)null || val.IsEquipped() || CargoPersistence.GetItemHash(val) != expected)) || ((Object)(object)incoming == (Object)null && (Object)(object)val == (Object)null))
			{
				return;
			}
			PhysGrabber val2 = (((Object)(object)owner == (Object)(object)PlayerAvatar.instance) ? PhysGrabber.instance : owner.physGrabber);
			PhysGrabObject val3 = (PhysGrabObject)(((Object)(object)val2 != (Object)null && val2.grabbed && GrabbedObject != null) ? /*isinst with value type is only supported in some contexts*/: null);
			int itemHash = CargoPersistence.GetItemHash(incoming);
			if ((Object)(object)incoming != (Object)null)
			{
				if (incoming.IsEquipped() || (Object)(object)((Component)incoming).GetComponent<CargoBackpackController>() != (Object)null || itemHash == 0 || CargoStoredItemState.Contains(incoming) || (Object)(object)val3 == (Object)null || (Object)(object)((Component)val3).GetComponent<ItemEquippable>() != (Object)(object)incoming)
				{
					return;
				}
				CargoBackpackController[] array = Object.FindObjectsOfType<CargoBackpackController>();
				foreach (CargoBackpackController cargoBackpackController in array)
				{
					for (int j = 0; j < 4; j++)
					{
						if (cargoBackpackController.GetCargoHash(j) == itemHash)
						{
							return;
						}
					}
				}
			}
			else if ((Object)(object)val3 != (Object)null)
			{
				return;
			}
			Vector3 val4 = CargoHandTransfer.ReleasePosition(owner, incoming, val);
			int num = _ledger.Revision + 1;
			if (SemiFunc.IsMultiplayer())
			{
				_view.RPC("CargoCommitSlotRPC", (RpcTarget)0, new object[7]
				{
					num,
					slot,
					itemHash,
					((Object)(object)incoming != (Object)null) ? ((MonoBehaviourPun)incoming).photonView.ViewID : 0,
					((Object)(object)val != (Object)null) ? ((MonoBehaviourPun)val).photonView.ViewID : 0,
					val4,
					owner.photonView.ViewID
				});
			}
			else
			{
				ApplyCommit(num, slot, itemHash, incoming, val, val4, owner);
			}
			CargoPersistence.WriteSlot(PersistentName, slot, incoming);
		}

		private void RecoverMissingItem(int slot)
		{
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			float unscaledTime = Time.unscaledTime;
			if (unscaledTime < _recoveryReadyAt || (_activeRecoverySlot >= 0 && _activeRecoverySlot != slot))
			{
				return;
			}
			int cargoHash = GetCargoHash(slot);
			ItemEquippable val = CargoPersistence.FindItem(cargoHash);
			if (_activeRecoverySlot < 0 && (Object)(object)val != (Object)null && CargoStoredItemState.CanAttach(val, this))
			{
				CompleteRecovery(slot, val, cargoHash);
			}
			else
			{
				if (SemiFunc.IsMultiplayer() && !PhotonNetwork.IsMasterClient)
				{
					return;
				}
				if (_activeRecoverySlot == slot)
				{
					ItemEquippable val2 = (((Object)(object)_activeRecoveryObject != (Object)null) ? _activeRecoveryObject.GetComponent<ItemEquippable>() : null);
					if ((Object)(object)val2 != (Object)null && CargoPersistence.GetItemHash(val2) != 0)
					{
						if (CompleteRecovery(slot, val2, cargoHash))
						{
							FinishRecovery();
						}
					}
					else if (unscaledTime >= _activeRecoveryDeadline)
					{
						DestroyFailedRecoveryObject();
						ClearUnrecoverableSlot(slot, "the single replacement did not initialize");
						FinishRecovery();
					}
				}
				else if (unscaledTime >= _recoveryGiveUpAt)
				{
					ClearUnrecoverableSlot(slot, "saved item could not be recreated");
				}
				else
				{
					if (unscaledTime < _nextRecoveryAttempt[slot])
					{
						return;
					}
					_nextRecoveryAttempt[slot] = unscaledTime + 4f;
					if (CargoPersistence.TrySpawnMissing(PersistentName, slot, cargoHash, ((Component)this).transform.position, out var spawned, out var reason))
					{
						_activeRecoverySlot = slot;
						_activeRecoveryObject = spawned;
						_activeRecoveryDeadline = unscaledTime + 5f;
						ItemEquippable component = spawned.GetComponent<ItemEquippable>();
						if ((Object)(object)component != (Object)null)
						{
							CargoStoredItemState.Store(component, this, slot);
						}
						CargoBackpackPlugin.Log.LogWarning((object)("CARGO creating one replacement for slot " + (slot + 4)));
					}
					else
					{
						_nextRecoveryAttempt[slot] = unscaledTime + 1f;
						CargoBackpackPlugin.Log.LogWarning((object)("CARGO recovery waiting for slot " + (slot + 4) + ": " + reason));
					}
				}
			}
		}

		private bool CompleteRecovery(int slot, ItemEquippable item, int previousHash)
		{
			//IL_00e2: 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)
			int itemHash = CargoPersistence.GetItemHash(item);
			if ((Object)(object)item == (Object)null || itemHash == 0)
			{
				return false;
			}
			PlayerAvatar val = ResolveOwner();
			int num = _ledger.Revision + 1;
			if (SemiFunc.IsMultiplayer())
			{
				if ((Object)(object)_view == (Object)null || (Object)(object)((MonoBehaviourPun)item).photonView == (Object)null)
				{
					return false;
				}
				_view.RPC("CargoCommitSlotRPC", (RpcTarget)0, new object[7]
				{
					num,
					slot,
					itemHash,
					((MonoBehaviourPun)item).photonView.ViewID,
					0,
					Vector3.zero,
					((Object)(object)val != (Object)null && (Object)(object)val.photonView != (Object)null) ? val.photonView.ViewID : 0
				});
			}
			else
			{
				ApplyCommit(num, slot, itemHash, item, null, Vector3.zero, val);
			}
			CargoPersistence.WriteSlot(PersistentName, slot, item);
			CargoBackpackPlugin.Log.LogInfo((object)("CARGO restored slot " + (slot + 4) + ": " + ((Object)item).name + "; identity " + previousHash + " -> " + itemHash));
			return true;
		}

		private void DestroyFailedRecoveryObject()
		{
			if (!((Object)(object)_activeRecoveryObject == (Object)null))
			{
				if (SemiFunc.IsMultiplayer() && PhotonNetwork.IsMasterClient)
				{
					PhotonNetwork.Destroy(_activeRecoveryObject);
				}
				else
				{
					Object.Destroy((Object)(object)_activeRecoveryObject);
				}
			}
		}

		private void FinishRecovery()
		{
			_activeRecoverySlot = -1;
			_activeRecoveryObject = null;
			_activeRecoveryDeadline = 0f;
		}

		private void ClearUnrecoverableSlot(int slot, string reason)
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			int num = _ledger.Revision + 1;
			PlayerAvatar val = ResolveOwner();
			if (SemiFunc.IsMultiplayer() && (Object)(object)_view != (Object)null)
			{
				_view.RPC("CargoCommitSlotRPC", (RpcTarget)0, new object[7]
				{
					num,
					slot,
					0,
					0,
					0,
					Vector3.zero,
					((Object)(object)val != (Object)null && (Object)(object)val.photonView != (Object)null) ? val.photonView.ViewID : 0
				});
			}
			else
			{
				_ledger.Commit(num, slot, 0);
			}
			_items[slot] = null;
			CargoPersistence.ApplyLocal(PersistentName, slot, 0);
			CargoPersistence.WriteSlot(PersistentName, slot, null);
			CargoBackpackPlugin.Log.LogWarning((object)("CARGO cleared unavailable slot " + (slot + 4) + ": " + reason));
		}

		[PunRPC]
		private void CargoCommitSlotRPC(int revision, int slot, int hash, int incomingId, int outgoingId, Vector3 releasePosition, int ownerViewId, PhotonMessageInfo info)
		{
			//IL_0000: 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)
			if (SemiFunc.MasterOnlyRPC(info))
			{
				PhotonView val = ((incomingId != 0) ? PhotonView.Find(incomingId) : null);
				PhotonView val2 = ((outgoingId != 0) ? PhotonView.Find(outgoingId) : null);
				PhotonView val3 = ((ownerViewId != 0) ? PhotonView.Find(ownerViewId) : null);
				ItemEquippable incoming = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<ItemEquippable>() : null);
				ItemEquippable outgoing = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<ItemEquippable>() : null);
				PlayerAvatar owner = (((Object)(object)val3 != (Object)null) ? ((Component)val3).GetComponent<PlayerAvatar>() : null);
				ApplyCommit(revision, slot, hash, incoming, outgoing, releasePosition, owner);
			}
		}

		private void ApplyCommit(int revision, int slot, int hash, ItemEquippable incoming, ItemEquippable outgoing, Vector3 releasePosition, PlayerAvatar owner)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (!_ledger.Commit(revision, slot, hash))
			{
				return;
			}
			_items[slot] = incoming;
			CargoPersistence.ApplyLocal(PersistentName, slot, hash);
			if ((Object)(object)incoming != (Object)null)
			{
				CargoHandTransfer.ReleaseIncoming(incoming);
				CargoStoredItemState.Store(incoming, this, slot);
			}
			if ((Object)(object)outgoing != (Object)null)
			{
				CargoStoredItemState.Unstore(outgoing, releasePosition);
				if ((Object)(object)owner == (Object)(object)PlayerAvatar.instance && (Object)(object)PhysGrabber.instance != (Object)null)
				{
					CargoHandTransfer cargoHandTransfer = ((Component)this).GetComponent<CargoHandTransfer>();
					if ((Object)(object)cargoHandTransfer == (Object)null)
					{
						cargoHandTransfer = ((Component)this).gameObject.AddComponent<CargoHandTransfer>();
					}
					cargoHandTransfer.Begin(outgoing);
				}
			}
			CargoBackpackPlugin.Log.LogInfo((object)("CARGO commit " + revision + ": slot " + (slot + 4) + (((Object)(object)incoming != (Object)null && (Object)(object)outgoing != (Object)null) ? " swapped" : ((hash == 0) ? " retrieved" : " stored")) + "; bag=" + PersistentName));
		}

		internal void TrackEquipAttempt(int slot)
		{
			_requestedEquipSlot = slot;
			_equipCheckAt = Time.unscaledTime + 0.75f;
		}

		internal void PrepareForEquip()
		{
			if ((Object)(object)_equippable == (Object)null || _equippable.IsEquipped())
			{
				return;
			}
			foreach (InventorySpot item in CargoRuntime.GetAllSpots() ?? Array.Empty<InventorySpot>())
			{
				if ((Object)(object)item != (Object)null && (Object)(object)item.CurrentItem == (Object)(object)_equippable)
				{
					item.UnequipItem();
				}
			}
			FieldInfo fieldInfo = AccessTools.Field(typeof(ItemEquippable), "currentState");
			if (fieldInfo != null)
			{
				fieldInfo.SetValue(_equippable, Enum.ToObject(fieldInfo.FieldType, 0));
			}
			SetEquipField("equippedSpot", null);
			SetEquipField("stateStart", true);
			SetEquipField("isEquipped", false);
			SetEquipField("isUnequipping", false);
			SetEquipField("isForceUnequipping", false);
			SetEquipField("isEquipping", false);
			SetEquipField("ownerPlayerId", -1);
		}

		private void SetEquipField(string name, object value)
		{
			FieldInfo fieldInfo = AccessTools.Field(typeof(ItemEquippable), name);
			if (fieldInfo != null)
			{
				fieldInfo.SetValue(_equippable, value);
			}
		}

		private void CheckEquipAttempt()
		{
			if (_requestedEquipSlot >= 0 && !(Time.unscaledTime < _equipCheckAt))
			{
				CargoBackpackPlugin.Log.LogInfo((object)("CARGO base slot " + (_requestedEquipSlot + 1) + ": equipped=" + ((Object)(object)_equippable != (Object)null && _equippable.IsEquipped())));
				_requestedEquipSlot = -1;
			}
		}

		private void LateUpdate()
		{
			UpdateWearable();
		}

		private void UpdateWearable()
		{
			if ((Object)(object)_equippable == (Object)null || !_equippable.IsEquipped())
			{
				DestroyWearable();
				return;
			}
			PlayerAvatar val = ResolveOwner();
			if (!((Object)(object)val == (Object)null))
			{
				if ((Object)(object)_wornModel == (Object)null || (Object)(object)_wornOwner != (Object)(object)val)
				{
					DestroyWearable();
					_wornOwner = val;
					_wornModel = CargoBackpackVisuals.CreateWornModel(val);
				}
				bool tumbling = Tumbling != null && (bool)Tumbling.GetValue(val);
				bool crawling = Crawling != null && (bool)Crawling.GetValue(val);
				bool crouching = Crouching != null && (bool)Crouching.GetValue(val);
				_wornModel.GetComponent<CargoWornPose>().SetFolded(CargoFoldLayout.ShouldFold(crouching, crawling, tumbling));
			}
		}

		private PlayerAvatar ResolveOwner()
		{
			if (!SemiFunc.IsMultiplayer())
			{
				return PlayerAvatar.instance;
			}
			if (OwnerId == null || (Object)(object)_equippable == (Object)null)
			{
				return null;
			}
			PhotonView val = PhotonView.Find((int)OwnerId.GetValue(_equippable));
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			PlayerAvatar component = ((Component)val).GetComponent<PlayerAvatar>();
			PhysGrabber component2 = ((Component)val).GetComponent<PhysGrabber>();
			if (!((Object)(object)component != (Object)null))
			{
				if (!((Object)(object)component2 != (Object)null))
				{
					return null;
				}
				return component2.playerAvatar;
			}
			return component;
		}

		private void DestroyWearable()
		{
			if ((Object)(object)_wornModel != (Object)null)
			{
				Object.Destroy((Object)(object)_wornModel);
			}
			_wornModel = null;
			_wornOwner = null;
		}

		private void OnDestroy()
		{
			DestroyWearable();
		}
	}
	[BepInPlugin("uz.cherdak.repo.cargobackpack", "C.A.R.G.O. Backpack", "1.0.23")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class CargoBackpackPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "uz.cherdak.repo.cargobackpack";

		public const string PluginName = "C.A.R.G.O. Backpack";

		public const string PluginVersion = "1.0.23";

		public const string BuildVariant = "1.0.23 — multiplayer ownership fix";

		internal static ManualLogSource Log;

		private bool _registered;

		private float _nextRegistrationAttempt;

		private void LateUpdate()
		{
			CargoStoredItemState.Tick();
			CargoInventoryUI.SetBackpackSlot(CargoRuntime.GetLocalBagBaseSlot());
		}

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			new Harmony("uz.cherdak.repo.cargobackpack").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"C.A.R.G.O. Backpack 1.0.23 loaded.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"1.0.23 — multiplayer ownership fix");
			if (Chainloader.PluginInfos.ContainsKey("com.Nyoh.backpack") || Chainloader.PluginInfos.ContainsKey("com.BellaModsGames.backpack"))
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Another backpack mod is enabled. Disable it to prevent its F/Z storage controls from interfering with C.A.R.G.O. slots.");
			}
		}

		private void Update()
		{
			CargoPersistence.EnsureRegistered();
			if (!_registered && Time.unscaledTime >= _nextRegistrationAttempt)
			{
				_nextRegistrationAttempt = Time.unscaledTime + 1f;
				try
				{
					_registered = CargoItemFactory.TryRegister();
				}
				catch (Exception ex)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("Could not create the C.A.R.G.O. Backpack: " + ex));
					_nextRegistrationAttempt = Time.unscaledTime + 5f;
				}
			}
			CargoRuntime.Tick();
		}
	}
	public sealed class CargoBackpackVisuals : MonoBehaviour
	{
		private static Material _yellow;

		private static Material _darkYellow;

		private static Material _black;

		private static Material _metal;

		private static Material _light;

		private static Material _lightOff;

		private static Material _healthLens;

		private CargoBackpackController _controller;

		private GameObject _groundModel;

		private float _nextLightUpdate;

		internal static void ConfigurePhysics(GameObject prefab)
		{
			//IL_0076: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Expected O, but got Unknown
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Expected O, but got Unknown
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: 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_01d7: Expected O, but got Unknown
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Expected O, but got Unknown
			//IL_0205: 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_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Expected O, but got Unknown
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Expected O, but got Unknown
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			BoxCollider val = (from collider in prefab.GetComponentsInChildren<BoxCollider>(true)
				where (Object)(object)collider != (Object)null && !((Collider)collider).isTrigger
				orderby Volume(collider.size, ((Component)collider).transform.lossyScale) descending
				select collider).FirstOrDefault();
			if ((Object)(object)val == (Object)null)
			{
				throw new InvalidOperationException("The source prefab has no physical BoxCollider.");
			}
			Vector3 val2 = prefab.transform.InverseTransformPoint(((Component)val).transform.TransformPoint(val.center));
			Collider[] componentsInChildren = prefab.GetComponentsInChildren<Collider>(true);
			foreach (Collider val3 in componentsInChildren)
			{
				if ((Object)(object)val3 != (Object)null && !val3.isTrigger)
				{
					val3.enabled = false;
				}
			}
			GameObject val4 = new GameObject("CARGO Compound Colliders")
			{
				layer = ((Component)val).gameObject.layer,
				tag = ((Component)val).gameObject.tag
			};
			val4.transform.SetParent(prefab.transform, false);
			val4.transform.localPosition = val2;
			AddBoxCollider(val4, Vector3.zero + new Vector3(0f, -0.01f, -0.05f), new Vector3(0.49f, 0.53f, 0.38f));
			AddBoxCollider(val4, Vector3.zero + new Vector3(0f, -0.01f, -0.05f), new Vector3(0.39f, 0.67f, 0.38f));
			AddBoxCollider(val4, new Vector3(-0.265f, -0.035f, 0f), new Vector3(0.12f, 0.32f, 0.23f));
			AddBoxCollider(val4, new Vector3(0.265f, -0.035f, 0f), new Vector3(0.12f, 0.32f, 0.23f));
			AddBoxCollider(val4, new Vector3(-0.13f, 0.36f, 0.03f), new Vector3(0.075f, 0.16f, 0.12f));
			AddBoxCollider(val4, new Vector3(0.13f, 0.36f, 0.03f), new Vector3(0.075f, 0.16f, 0.12f));
			AddBoxCollider(val4, new Vector3(0f, 0.43f, 0.03f), new Vector3(0.29f, 0.1f, 0.11f));
			Rigidbody component = prefab.GetComponent<Rigidbody>();
			if ((Object)(object)component != (Object)null)
			{
				component.centerOfMass = val2 + new Vector3(0f, -0.08f, 0f);
				component.maxAngularVelocity = 12f;
			}
		}

		private static void AddBoxCollider(GameObject target, Vector3 center, Vector3 size)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			GameObject val = new GameObject("CARGO Shape " + target.transform.childCount);
			val.transform.SetParent(target.transform, false);
			val.transform.localPosition = center;
			val.layer = LayerMask.NameToLayer("PhysGrabObject");
			val.tag = "Phys Grab Object";
			val.AddComponent<BoxCollider>().size = size;
			val.AddComponent<PhysGrabObjectCollider>();
		}

		private static float Volume(Vector3 size, Vector3 scale)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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)
			return Mathf.Abs(size.x * scale.x * size.y * scale.y * size.z * scale.z);
		}

		private void Start()
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			//IL_00af: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)((Component)this).transform.Find("CARGO Backpack Model") != (Object)null))
			{
				Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
				EnsureMaterials(componentsInChildren.Select((Renderer renderer) => renderer.sharedMaterial).FirstOrDefault((Func<Material, bool>)((Material material) => (Object)(object)material != (Object)null)));
				Renderer[] array = componentsInChildren;
				for (int num = 0; num < array.Length; num++)
				{
					array[num].enabled = false;
				}
				GameObject val = new GameObject("CARGO Backpack Model");
				val.transform.SetParent(((Component)this).transform, false);
				val.transform.localPosition = FindPhysicalCentre(((Component)this).transform);
				val.transform.localScale = Vector3.one * 0.34f;
				BuildPack(val.transform, groundModel: true);
				_groundModel = val;
				_controller = ((Component)this).GetComponent<CargoBackpackController>();
				UpdateSlotLights(_groundModel, ((Object)(object)_controller != (Object)null) ? new Func<int, bool>(_controller.IsCargoSlotOccupied) : null);
			}
		}

		private void Update()
		{
			if ((Object)(object)_groundModel != (Object)null && (Object)(object)_controller != (Object)null && (Object)(object)_controller.Equippable != (Object)null)
			{
				_groundModel.SetActive(!_controller.Equippable.IsEquipped());
			}
			if (!(Time.unscaledTime < _nextLightUpdate))
			{
				_nextLightUpdate = Time.unscaledTime + 0.1f;
				if ((Object)(object)_groundModel != (Object)null && (Object)(object)_controller != (Object)null)
				{
					UpdateSlotLights(_groundModel, _controller.IsCargoSlotOccupied);
				}
			}
		}

		private static Vector3 FindPhysicalCentre(Transform root)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			Transform val = root.Find("CARGO Compound Colliders");
			if ((Object)(object)val != (Object)null)
			{
				return val.localPosition;
			}
			BoxCollider val2 = (from collider in ((Component)root).GetComponentsInChildren<BoxCollider>(true)
				where (Object)(object)collider != (Object)null && ((Collider)collider).enabled && !((Collider)collider).isTrigger
				orderby Volume(collider.size, ((Component)collider).transform.lossyScale) descending
				select collider).FirstOrDefault();
			if ((Object)(object)val2 == (Object)null)
			{
				return Vector3.zero;
			}
			return root.InverseTransformPoint(((Component)val2).transform.TransformPoint(val2.center));
		}

		internal static GameObject CreateWornModel(PlayerAvatar avatar)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: 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_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			EnsureMaterials(null);
			Transform val = (((Object)(object)avatar.playerTransform != (Object)null) ? avatar.playerTransform : ((Component)avatar).transform);
			GameObject val2 = new GameObject("CARGO Backpack Worn");
			val2.transform.SetParent(val, false);
			val2.transform.localPosition = new Vector3(0f, 0.38f, -0.31f);
			val2.transform.localRotation = Quaternion.identity;
			val2.transform.localScale = Vector3.one * 0.37f;
			GameObject val3 = new GameObject("CARGO Folding Shell");
			val3.transform.SetParent(val2.transform, false);
			BuildPack(val3.transform, groundModel: false);
			GameObject val4 = new GameObject("CARGO Front Straps");
			val4.transform.SetParent(val2.transform, false);
			CreatePart("Left Front Strap", (PrimitiveType)1, val4.transform, new Vector3(-0.43f, 0.05f, 0.92f), new Vector3(0.14f, 0.79f, 0.08f), new Vector3(0f, 0f, -7f), _black);
			CreatePart("Right Front Strap", (PrimitiveType)1, val4.transform, new Vector3(0.43f, 0.05f, 0.92f), new Vector3(0.14f, 0.79f, 0.08f), new Vector3(0f, 0f, 7f), _black);
			CreatePart("Left Strap Safety Edge", (PrimitiveType)3, val4.transform, new Vector3(-0.43f, 0.05f, 0.965f), new Vector3(0.045f, 1.48f, 0.025f), new Vector3(0f, 0f, -7f), _yellow);
			CreatePart("Right Strap Safety Edge", (PrimitiveType)3, val4.transform, new Vector3(0.43f, 0.05f, 0.965f), new Vector3(0.045f, 1.48f, 0.025f), new Vector3(0f, 0f, 7f), _yellow);
			CreatePart("Chest Strap", (PrimitiveType)1, val4.transform, new Vector3(0f, -0.12f, 0.97f), new Vector3(0.08f, 0.39f, 0.07f), new Vector3(0f, 0f, 90f), _black);
			CreatePart("Chest Buckle", (PrimitiveType)3, val4.transform, new Vector3(0f, -0.12f, 1.025f), new Vector3(0.22f, 0.19f, 0.07f), Vector3.zero, _yellow);
			CreatePart("Buckle Centre", (PrimitiveType)3, val4.transform, new Vector3(0f, -0.12f, 1.07f), new Vector3(0.11f, 0.1f, 0.04f), Vector3.zero, _black);
			val2.AddComponent<CargoWornPose>().Initialize(val3.transform, val4.transform, avatar);
			val2.AddComponent<CargoHealthLights>().Initialize(avatar, val3.transform);
			return val2;
		}

		private static void BuildPack(Transform root, bool groundModel)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: 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_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_030b: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0354: Unknown result type (might be due to invalid IL or missing references)
			//IL_0368: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0431: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0461: Unknown result type (might be due to invalid IL or missing references)
			//IL_0475: Unknown result type (might be due to invalid IL or missing references)
			//IL_047a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0617: Unknown result type (might be due to invalid IL or missing references)
			//IL_062b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0630: Unknown result type (might be due to invalid IL or missing references)
			//IL_0655: Unknown result type (might be due to invalid IL or missing references)
			//IL_0669: Unknown result type (might be due to invalid IL or missing references)
			//IL_0673: Unknown result type (might be due to invalid IL or missing references)
			//IL_052a: Unknown result type (might be due to invalid IL or missing references)
			//IL_053e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0548: Unknown result type (might be due to invalid IL or missing references)
			//IL_0568: Unknown result type (might be due to invalid IL or missing references)
			//IL_057c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0590: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0707: Unknown result type (might be due to invalid IL or missing references)
			//IL_071b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0720: Unknown result type (might be due to invalid IL or missing references)
			//IL_0753: Unknown result type (might be due to invalid IL or missing references)
			//IL_0767: Unknown result type (might be due to invalid IL or missing references)
			//IL_0771: Unknown result type (might be due to invalid IL or missing references)
			//IL_0797: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0831: Unknown result type (might be due to invalid IL or missing references)
			//IL_0845: Unknown result type (might be due to invalid IL or missing references)
			//IL_084a: Unknown result type (might be due to invalid IL or missing references)
			//IL_087c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0890: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_08fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0921: Unknown result type (might be due to invalid IL or missing references)
			//IL_0935: Unknown result type (might be due to invalid IL or missing references)
			//IL_0949: Unknown result type (might be due to invalid IL or missing references)
			//IL_0985: Unknown result type (might be due to invalid IL or missing references)
			//IL_0999: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a00: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a14: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a19: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a59: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a6d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a72: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b02: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b16: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b65: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b79: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b7e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ba8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bbc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bc1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c0d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c21: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c2b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c62: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c76: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c8a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cc3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cd7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cdc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d02: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d16: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d1b: Unknown result type (might be due to invalid IL or missing references)
			CreateBevelledBox("Hard Shell", root, Vector3.zero, new Vector3(1.38f, 1.92f, 0.78f), 0.15f, Vector3.zero, _black);
			CreateBevelledBox("CARGO Header Panel", root, new Vector3(0f, 0.69f, -0.45f), new Vector3(1.1f, 0.43f, 0.16f), 0.1f, Vector3.zero, _yellow);
			CreatePaintedPanel("C.A.R.G.O. Painted Header", root, "C.A.R.G.O.", new Vector3(0f, 0.69f, -0.536f), new Vector2(0.92f, 0.25f), 31);
			float[] array = new float[4] { 0.32f, 0.01f, -0.3f, -0.61f };
			for (int i = 0; i < array.Length; i++)
			{
				CreateBevelledBox("Module Frame " + (i + 1), root, new Vector3(0.06f, array[i], -0.46f), new Vector3(1.02f, 0.285f, 0.15f), 0.055f, Vector3.zero, _metal);
				CreateBevelledBox("Cargo Module " + (i + 1), root, new Vector3(0.02f, array[i], -0.565f), new Vector3(0.88f, 0.225f, 0.13f), 0.045f, Vector3.zero, _yellow);
				CreateBevelledBox("Module Light Housing " + (i + 1), root, new Vector3(0.39f, array[i], -0.655f), new Vector3(0.13f, 0.15f, 0.055f), 0.025f, Vector3.zero, _black);
				CreatePart("Module Light " + (i + 1), (PrimitiveType)3, root, new Vector3(0.39f, array[i], -0.692f), new Vector3(0.055f, 0.105f, 0.018f), Vector3.zero, _lightOff);
				CreatePaintedPanel("Painted Module Face " + (i + 1), root, (i + 1).ToString(), new Vector3(0f, array[i], -0.637f), new Vector2(0.68f, 0.145f), 80 + i);
				CreatePart("Module Left Bolt " + (i + 1), (PrimitiveType)2, root, new Vector3(-0.35f, array[i] + 0.065f, -0.65f), new Vector3(0.022f, 0.014f, 0.022f), new Vector3(90f, 0f, 0f), _metal);
				CreatePart("Module Right Bolt " + (i + 1), (PrimitiveType)2, root, new Vector3(0.28f, array[i] - 0.065f, -0.65f), new Vector3(0.022f, 0.014f, 0.022f), new Vector3(90f, 0f, 0f), _metal);
			}
			CreateBevelledBox("Left Side Container", root, new Vector3(-0.78f, -0.1f, 0.02f), new Vector3(0.34f, 0.9f, 0.59f), 0.08f, Vector3.zero, _yellow);
			CreateBevelledBox("Right Side Container", root, new Vector3(0.78f, -0.1f, 0.02f), new Vector3(0.34f, 0.9f, 0.59f), 0.08f, Vector3.zero, _yellow);
			CreateBevelledBox("Left Side Container Inset", root, new Vector3(-0.955f, -0.1f, 0.01f), new Vector3(0.035f, 0.58f, 0.34f), 0.012f, Vector3.zero, _darkYellow);
			CreateBevelledBox("Right Side Container Inset", root, new Vector3(0.955f, -0.1f, 0.01f), new Vector3(0.035f, 0.58f, 0.34f), 0.012f, Vector3.zero, _darkYellow);
			CreatePart("Left Side Spine", (PrimitiveType)3, root, new Vector3(-0.66f, -0.05f, -0.05f), new Vector3(0.1f, 1.55f, 0.62f), Vector3.zero, _metal);
			CreatePart("Right Side Spine", (PrimitiveType)3, root, new Vector3(0.66f, -0.05f, -0.05f), new Vector3(0.1f, 1.55f, 0.62f), Vector3.zero, _metal);
			float[] array2 = new float[2] { -0.57f, 0.57f };
			float[] array3 = new float[2] { -0.76f, 0.78f };
			float[] array4 = array2;
			foreach (float num in array4)
			{
				float[] array5 = array3;
				foreach (float num2 in array5)
				{
					CreateBevelledBox("Front Corner Armour", root, new Vector3(num, num2, -0.445f), new Vector3(0.2f, 0.28f, 0.13f), 0.045f, Vector3.zero, _metal);
					CreatePart("Corner Armour Rivet", (PrimitiveType)2, root, new Vector3(num, num2, -0.523f), new Vector3(0.025f, 0.012f, 0.025f), new Vector3(90f, 0f, 0f), _black);
				}
			}
			CreatePart("Left Retention Webbing", (PrimitiveType)3, root, new Vector3(-0.805f, -0.1f, -0.305f), new Vector3(0.22f, 0.055f, 0.055f), Vector3.zero, _black);
			CreatePart("Right Retention Webbing", (PrimitiveType)3, root, new Vector3(0.805f, -0.1f, -0.305f), new Vector3(0.22f, 0.055f, 0.055f), Vector3.zero, _black);
			CreateBevelledBox("Top Rail", root, new Vector3(0f, 0.91f, 0f), new Vector3(1.1f, 0.17f, 0.7f), 0.045f, Vector3.zero, _metal);
			for (int l = 0; l < 6; l++)
			{
				float num3 = CargoHealthGauge.LampX(l);
				CreatePart("Health Socket " + (l + 1), (PrimitiveType)2, root, new Vector3(num3, 1.001f, -0.21f), new Vector3(0.078f, 0.009f, 0.078f), Vector3.zero, _metal);
				CreatePart("Health Lens " + (l + 1), (PrimitiveType)0, root, new Vector3(num3, 1.011f, -0.21f), new Vector3(0.055f, 0.035f, 0.055f), Vector3.zero, _healthLens);
			}
			CreateBevelledBox("Bottom Rail", root, new Vector3(0f, -0.91f, 0f), new Vector3(1.12f, 0.16f, 0.7f), 0.045f, Vector3.zero, _metal);
			CreatePart("Left Shell Wear Strip", (PrimitiveType)3, root, new Vector3(-0.53f, -0.08f, -0.422f), new Vector3(0.055f, 1.46f, 0.025f), Vector3.zero, _darkYellow);
			CreatePart("Right Shell Wear Strip", (PrimitiveType)3, root, new Vector3(0.53f, -0.08f, -0.422f), new Vector3(0.055f, 1.46f, 0.025f), Vector3.zero, _darkYellow);
			for (int m = 0; m < array.Length; m++)
			{
				CreatePart("Module Lower Lip " + (m + 1), (PrimitiveType)3, root, new Vector3(0.02f, array[m] - 0.105f, -0.642f), new Vector3(0.74f, 0.025f, 0.025f), Vector3.zero, _metal);
			}
			CreateBevelledBox("Handle Left Mount", root, new Vector3(-0.38f, 1.09f, 0.08f), new Vector3(0.18f, 0.4f, 0.22f), 0.045f, new Vector3(0f, 0f, -15f), _metal);
			CreateBevelledBox("Handle Right Mount", root, new Vector3(0.38f, 1.09f, 0.08f), new Vector3(0.18f, 0.4f, 0.22f), 0.045f, new Vector3(0f, 0f, 15f), _metal);
			CreatePart("Rubber Carry Handle", (PrimitiveType)1, root, new Vector3(0f, 1.26f, 0.08f), new Vector3(0.14f, 0.39f, 0.16f), new Vector3(0f, 0f, 90f), _black);
			for (int n = -3; n <= 3; n++)
			{
				CreatePart("Handle Grip Rib " + n, (PrimitiveType)2, root, new Vector3((float)n * 0.075f, 1.26f, 0.08f), new Vector3(0.152f, 0.013f, 0.172f), new Vector3(0f, 0f, 90f), _black);
			}
			for (int num4 = -1; num4 <= 1; num4 += 2)
			{
				CreatePart(((num4 < 0) ? "Left" : "Right") + " Upper Hinge", (PrimitiveType)2, root, new Vector3((float)num4 * 0.67f, 0.48f, -0.2f), new Vector3(0.055f, 0.1f, 0.055f), Vector3.zero, _metal);
				CreatePart(((num4 < 0) ? "Left" : "Right") + " Lower Hinge", (PrimitiveType)2, root, new Vector3((float)num4 * 0.67f, -0.5f, -0.2f), new Vector3(0.055f, 0.1f, 0.055f), Vector3.zero, _metal);
			}
			float[] array6 = new float[2] { -0.46f, 0.46f };
			float[] array7 = new float[2] { 0.82f, 0.56f };
			array4 = array6;
			foreach (float num5 in array4)
			{
				float[] array5 = array7;
				foreach (float num6 in array5)
				{
					CreatePart("Header Bolt", (PrimitiveType)2, root, new Vector3(num5, num6, -0.555f), new Vector3(0.032f, 0.018f, 0.032f), new Vector3(90f, 0f, 0f), _metal);
				}
			}
			for (int num7 = -5; num7 <= 5; num7++)
			{
				CreatePart("Header Reinforced Stitch", (PrimitiveType)3, root, new Vector3((float)num7 * 0.082f, 0.515f, -0.542f), new Vector3(0.044f, 0.01f, 0.01f), Vector3.zero, _darkYellow);
				CreatePart("Lower Reinforced Stitch", (PrimitiveType)3, root, new Vector3((float)num7 * 0.082f, -0.805f, -0.423f), new Vector3(0.044f, 0.01f, 0.01f), Vector3.zero, _metal);
			}
			for (int num8 = 0; num8 < array.Length; num8++)
			{
				CreateBevelledBox("Module Release Latch " + (num8 + 1), root, new Vector3(-0.34f, array[num8], -0.657f), new Vector3(0.115f, 0.115f, 0.035f), 0.025f, Vector3.zero, _darkYellow);
				CreatePart("Module Latch Pin " + (num8 + 1), (PrimitiveType)2, root, new Vector3(-0.34f, array[num8], -0.683f), new Vector3(0.022f, 0.013f, 0.022f), new Vector3(90f, 0f, 0f), _metal);
			}
			if (groundModel)
			{
				CreatePart("Left Back Strap", (PrimitiveType)1, root, new Vector3(-0.38f, 0f, 0.48f), new Vector3(0.17f, 0.78f, 0.12f), Vector3.zero, _black);
				CreatePart("Right Back Strap", (PrimitiveType)1, root, new Vector3(0.38f, 0f, 0.48f), new Vector3(0.17f, 0.78f, 0.12f), Vector3.zero, _black);
			}
		}

		private static GameObject CreatePart(string name, PrimitiveType primitive, Transform parent, Vector3 position, Vector3 scale, Vector3 rotation, Material material)
		{
			//IL_0000: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive(primitive);
			((Object)obj).name = name;
			obj.transform.SetParent(parent, false);
			obj.transform.localPosition = position;
			obj.transform.localScale = scale;
			obj.transform.localRotation = Quaternion.Euler(rotation);
			Renderer component = obj.GetComponent<Renderer>();
			if ((Object)(object)component != (Object)null)
			{
				component.sharedMaterial = material;
			}
			Collider component2 = obj.GetComponent<Collider>();
			if ((Object)(object)component2 != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)component2);
			}
			return obj;
		}

		private static GameObject CreateBevelledBox(string name, Transform parent, Vector3 position, Vector3 size, float bevel, Vector3 rotation, Material material)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: 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_024d: 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_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Expected O, but got Unknown
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: 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_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_037d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Expected O, but got Unknown
			float num = size.x * 0.5f;
			float num2 = size.y * 0.5f;
			float num3 = size.z * 0.5f;
			bevel = Mathf.Clamp(bevel, 0.001f, Mathf.Min(num, num2) * 0.8f);
			Vector2[] array = (Vector2[])(object)new Vector2[8]
			{
				new Vector2(0f - num + bevel, 0f - num2),
				new Vector2(num - bevel, 0f - num2),
				new Vector2(num, 0f - num2 + bevel),
				new Vector2(num, num2 - bevel),
				new Vector2(num - bevel, num2),
				new Vector2(0f - num + bevel, num2),
				new Vector2(0f - num, num2 - bevel),
				new Vector2(0f - num, 0f - num2 + bevel)
			};
			List<Vector3> list = new List<Vector3>();
			List<int> list2 = new List<int>();
			for (int i = 1; i < array.Length - 1; i++)
			{
				AddTriangle(list, list2, new Vector3(array[0].x, array[0].y, 0f - num3), new Vector3(array[i + 1].x, array[i + 1].y, 0f - num3), new Vector3(array[i].x, array[i].y, 0f - num3));
				AddTriangle(list, list2, new Vector3(array[0].x, array[0].y, num3), new Vector3(array[i].x, array[i].y, num3), new Vector3(array[i + 1].x, array[i + 1].y, num3));
			}
			for (int j = 0; j < array.Length; j++)
			{
				int num4 = (j + 1) % array.Length;
				AddQuad(list, list2, new Vector3(array[j].x, array[j].y, 0f - num3), new Vector3(array[num4].x, array[num4].y, 0f - num3), new Vector3(array[num4].x, array[num4].y, num3), new Vector3(array[j].x, array[j].y, num3));
			}
			Mesh val = new Mesh
			{
				name = "CARGO " + name + " Mesh"
			};
			val.SetVertices(list);
			val.SetTriangles(list2, 0);
			List<Vector2> list3 = new List<Vector2>(list.Count);
			foreach (Vector3 item in list)
			{
				list3.Add(new Vector2(item.x / size.x + 0.5f, item.y / size.y + 0.5f));
			}
			val.SetUVs(0, list3);
			val.RecalculateNormals();
			val.RecalculateBounds();
			GameObject val2 = new GameObject(name, new Type[2]
			{
				typeof(MeshFilter),
				typeof(MeshRenderer)
			});
			val2.transform.SetParent(parent, false);
			val2.transform.localPosition = position;
			val2.transform.localRotation = Quaternion.Euler(rotation);
			val2.GetComponent<MeshFilter>().sharedMesh = val;
			((Renderer)val2.GetComponent<MeshRenderer>()).sharedMaterial = material;
			return val2;
		}

		private static GameObject CreatePaintedPanel(string name, Transform parent, string text, Vector3 position, Vector2 size, int seed)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_0017: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: 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_0175: Expected O, but got Unknown
			Mesh val = new Mesh
			{
				name = name + " Mesh"
			};
			float num = size.x * 0.5f;
			float num2 = size.y * 0.5f;
			val.vertices = (Vector3[])(object)new Vector3[4]
			{
				new Vector3(0f - num, 0f - num2, 0f),
				new Vector3(num, 0f - num2, 0f),
				new Vector3(num, num2, 0f),
				new Vector3(0f - num, num2, 0f)
			};
			val.uv = (Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, 0f),
				new Vector2(1f, 0f),
				new Vector2(1f, 1f),
				new Vector2(0f, 1f)
			};
			val.triangles = new int[6] { 0, 2, 1, 0, 3, 2 };
			val.RecalculateNormals();
			val.RecalculateBounds();
			GameObject val2 = new GameObject(name, new Type[2]
			{
				typeof(MeshFilter),
				typeof(MeshRenderer)
			});
			val2.transform.SetParent(parent, false);
			val2.transform.localPosition = position;
			val2.GetComponent<MeshFilter>().sharedMesh = val;
			((Renderer)val2.GetComponent<MeshRenderer>()).sharedMaterial = CreatePaintedPanelMaterial(text, seed);
			return val2;
		}

		internal static void UpdateSlotLights(GameObject model, Func<int, bool> occupied)
		{
			if (!((Object)(object)model == (Object)null) && !((Object)(object)_light == (Object)null) && !((Object)(object)_lightOff == (Object)null))
			{
				Renderer[] array = (from renderer in model.GetComponentsInChildren<Renderer>(true)
					where (Object)(object)renderer != (Object)null && ((Object)((Component)renderer).gameObject).name.StartsWith("Module Light ", StringComparison.Ordinal) && !((Object)((Component)renderer).gameObject).name.Contains("Housing")
					orderby ((Object)((Component)renderer).gameObject).name
					select renderer).ToArray();
				CargoWornPose component = model.GetComponent<CargoWornPose>();
				bool flag = (Object)(object)component != (Object)null && component.Folded;
				bool flag2 = occupied != null && (occupied(0) || occupied(1) || occupied(2) || occupied(3));
				for (int num = 0; num < array.Length && num < 4; num++)
				{
					array[num].sharedMaterial = ((occupied != null && ((flag && num == 0) ? flag2 : occupied(num))) ? _light : _lightOff);
				}
			}
		}

		private static void AddTriangle(List<Vector3> vertices, List<int> triangles, Vector3 a, Vector3 b, Vector3 c)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			int count = vertices.Count;
			vertices.Add(a);
			vertices.Add(b);
			vertices.Add(c);
			triangles.Add(count);
			triangles.Add(count + 1);
			triangles.Add(count + 2);
		}

		private static void AddQuad(List<Vector3> vertices, List<int> triangles, Vector3 a, Vector3 b, Vector3 c, Vector3 d)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			int count = vertices.Count;
			vertices.Add(a);
			vertices.Add(b);
			vertices.Add(c);
			vertices.Add(d);
			triangles.Add(count);
			triangles.Add(count + 1);
			triangles.Add(count + 2);
			triangles.Add(count);
			triangles.Add(count + 2);
			triangles.Add(count + 3);
		}

		private static void EnsureMaterials(Material fallback)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_yellow != (Object)null))
			{
				Shader val = Shader.Find("Standard") ?? Shader.Find("Universal Render Pipeline/Lit");
				if ((Object)(object)val == (Object)null && (Object)(object)fallback != (Object)null)
				{
					val = fallback.shader;
				}
				if ((Object)(object)val == (Object)null)
				{
					throw new InvalidOperationException("No compatible shader was found for the backpack.");
				}
				_yellow = MakeMaterial(val, "Safety Fabric Yellow", new Color(0.95f, 0.61f, 0.025f, 1f), 0.06f);
				_darkYellow = MakeMaterial(val, "Dark Fabric Yellow", new Color(0.58f, 0.3f, 0.012f, 1f), 0.04f);
				_black = MakeMaterial(val, "Woven Black", new Color(0.012f, 0.015f, 0.018f, 1f), 0.03f);
				_metal = MakeMaterial(val, "Gunmetal", new Color(0.075f, 0.085f, 0.09f, 1f), 0.8f);
				_light = MakeMaterial(val, "Amber Module Light", new Color(1f, 0.42f, 0.015f, 1f), 0.15f);
				_lightOff = MakeMaterial(val, "Unlit Module Light", new Color(0.12f, 0.055f, 0.008f, 1f), 0.05f);
				_healthLens = MakeMaterial(val, "Health Indicator Light", new Color(0.025f, 0.032f, 0.028f, 1f), 0.08f);
				_healthLens.EnableKeyword("_EMISSION");
				if (_healthLens.HasProperty("_EmissionColor"))
				{
					_healthLens.SetColor("_EmissionColor", Color.black);
				}
				if (_healthLens.HasProperty("_Glossiness"))
				{
					_healthLens.SetFloat("_Glossiness", 0.72f);
				}
				if (_healthLens.HasProperty("_Smoothness"))
				{
					_healthLens.SetFloat("_Smoothness", 0.72f);
				}
				if (_light.HasProperty("_EmissionColor"))
				{
					_light.EnableKeyword("_EMISSION");
					_light.SetColor("_EmissionColor", new Color(1f, 0.18f, 0.005f, 1f) * 2.2f);
				}
			}
		}

		private static Material MakeMaterial(Shader shader, string name, Color color, float metallic)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: 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_00a3: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(shader)
			{
				name = "CARGO " + name
			};
			if (name.IndexOf("Light", StringComparison.OrdinalIgnoreCase) < 0)
			{
				Texture2D val2 = CreateSurfaceTexture(color, StableSeed(name), metallic > 0.5f);
				if (val.HasProperty("_MainTex"))
				{
					val.SetTexture("_MainTex", (Texture)(object)val2);
				}
				if (val.HasProperty("_BaseMap"))
				{
					val.SetTexture("_BaseMap", (Texture)(object)val2);
				}
				if (val.HasProperty("_Color"))
				{
					val.SetColor("_Color", Color.white);
				}
				if (val.HasProperty("_BaseColor"))
				{
					val.SetColor("_BaseColor", Color.white);
				}
				if (val.HasProperty("_BumpMap"))
				{
					val.SetTexture("_BumpMap", (Texture)(object)CreateNormalTexture(StableSeed(name), metallic));
					if (val.HasProperty("_BumpScale"))
					{
						val.SetFloat("_BumpScale", (metallic > 0.5f) ? 0.34f : 0.62f);
					}
					val.EnableKeyword("_NORMALMAP");
				}
			}
			else
			{
				if (val.HasProperty("_Color"))
				{
					val.SetColor("_Color", color);
				}
				if (val.HasProperty("_BaseColor"))
				{
					val.SetColor("_BaseColor", color);
				}
			}
			if (val.HasProperty("_Metallic"))
			{
				val.SetFloat("_Metallic", metallic);
			}
			float num = ((metallic > 0.5f) ? 0.42f : 0.16f);
			if (val.HasProperty("_Glossiness"))
			{
				val.SetFloat("_Glossiness", num);
			}
			if (val.HasProperty("_Smoothness"))
			{
				val.SetFloat("_Smoothness", num);
			}
			return val;
		}

		private static Material CreatePaintedPanelMaterial(string text, int seed)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(((Object)(object)_yellow != (Object)null) ? _yellow.shader : Shader.Find("Standard"))
			{
				name = "CARGO Painted " + text
			};
			Texture2D val2 = CreatePaintedTexture(text, seed);
			if (val.HasProperty("_MainTex"))
			{
				val.SetTexture("_MainTex", (Texture)(object)val2);
			}
			if (val.HasProperty("_BaseMap"))
			{
				val.SetTexture("_BaseMap", (Texture)(object)val2);
			}
			if (val.HasProperty("_Color"))
			{
				val.SetColor("_Color", Color.white);
			}
			if (val.HasProperty("_BaseColor"))
			{
				val.SetColor("_BaseColor", Color.white);
			}
			if (val.HasProperty("_Metallic"))
			{
				val.SetFloat("_Metallic", 0.12f);
			}
			if (val.HasProperty("_Glossiness"))
			{
				val.SetFloat("_Glossiness", 0.19f);
			}
			if (val.HasProperty("_Smoothness"))
			{
				val.SetFloat("_Smoothness", 0.19f);
			}
			Object.DontDestroyOnLoad((Object)(object)val);
			return val;
		}

		private static Texture2D CreatePaintedTexture(string text, int seed)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			//IL_00b0: Expected O, but got Unknown
			int num = ((text.Length > 2) ? 256 : 128);
			int num2 = ((text.Length > 2) ? 80 : 64);
			Texture2D val = new Texture2D(num, num2, (TextureFormat)4, false)
			{
				name = "CARGO Painted Panel " + text,
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)1
			};
			Color32[] array = CreateSurfacePixels(num, num2, new Color(0.96f, 0.6f, 0.018f, 1f), seed, metal: false, bordered: true);
			int scale = ((text.Length > 2) ? 5 : 6);
			DrawBitmapText(array, num, num2, text, scale, new Color32((byte)19, (byte)17, (byte)13, byte.MaxValue));
			val.SetPixels32(array);
			val.Apply(false, true);
			Object.DontDestroyOnLoad((Object)val);
			return val;
		}

		private static Texture2D CreateSurfaceTexture(Color baseColor, int seed, bool metal)
		{
			//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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_0046: Expected O, but got Unknown
			Texture2D val = new Texture2D(96, 96, (TextureFormat)4, false)
			{
				name = "CARGO Worn Surface",
				wrapMode = (TextureWrapMode)0,
				filterMode = (FilterMode)1
			};
			val.SetPixels32(CreateSurfacePixels(96, 96, baseColor, seed, metal, bordered: false));
			val.Apply(false, true);
			Object.DontDestroyOnLoad((Object)val);
			return val;
		}

		private static Texture2D CreateNormalTexture(int seed, float metallic)
		{
			//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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(96, 96, (TextureFormat)4, false)
			{
				name = "CARGO Micro Surface Normal",
				wrapMode = (TextureWrapMode)0,
				filterMode = (FilterMode)1
			};
			Color32[] array = (Color32[])(object)new Color32[9216];
			float num = ((metallic > 0.5f) ? 0.16f : 0.3f);
			for (int i = 0; i < 96; i++)
			{
				for (int j = 0; j < 96; j++)
				{
					float num2 = (float)(PixelHash((j + 96 - 1) % 96, i, seed) & 0xFF) / 255f;
					float num3 = (float)(PixelHash((j + 1) % 96, i, seed) & 0xFF) / 255f;
					float num4 = (float)(PixelHash(j, (i + 96 - 1) % 96, seed) & 0xFF) / 255f;
					float num5 = (float)(PixelHash(j, (i + 1) % 96, seed) & 0xFF) / 255f;
					Vector3 val2 = new Vector3((num2 - num3) * num, (num4 - num5) * num, 1f);
					Vector3 normalized = ((Vector3)(ref val2)).normalized;
					array[i * 96 + j] = new Color32((byte)((normalized.x * 0.5f + 0.5f) * 255f), (byte)((normalized.y * 0.5f + 0.5f) * 255f), (byte)((normalized.z * 0.5f + 0.5f) * 255f), byte.MaxValue);
				}
			}
			val.SetPixels32(array);
			val.Apply(false, true);
			Object.DontDestroyOnLoad((Object)(object)val);
			return val;
		}

		private static Color32[] CreateSurfacePixels(int width, int height, Color baseColor, int seed, bool metal, bool bordered)
		{
			//IL_017b: 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_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			Color32[] array = (Color32[])(object)new Color32[width * height];
			for (int i = 0; i < height; i++)
			{
				for (int j = 0; j < width; j++)
				{
					uint num = PixelHash(j, i, seed);
					float num2 = ((float)(num & 0xFF) / 255f - 0.5f) * (metal ? 0.14f : 0.1f);
					float num3 = Mathf.Sin((float)(j + seed) * 0.075f) * 0.025f + Mathf.Cos((float)(i - seed) * 0.093f) * 0.025f;
					float num4 = Mathf.PerlinNoise((float)(j + (seed & 0x1F)) * 0.055f, (float)(i + ((seed >> 5) & 0x1F)) * 0.055f);
					float num5 = Mathf.Lerp(0.78f, 1.08f, (float)i / Mathf.Max(1f, (float)height - 1f));
					float num6 = 1f - Mathf.Clamp01((float)i / Mathf.Max(1f, (float)height * 0.42f));
					float num7 = num5 + num2 + num3 + (num4 - 0.5f) * 0.34f - num6 * 0.12f;
					float num8 = Mathf.Min(Mathf.Min(j, width - 1 - j), Mathf.Min(i, height - 1 - i));
					if (bordered && num8 < 5f)
					{
						num7 *= Mathf.Lerp(0.55f, 0.88f, num8 / 5f);
					}
					if (num % 283 < 4)
					{
						num7 *= 0.32f;
					}
					if ((j * 5 + i * 2 + seed * 11) % 173 == 0)
					{
						num7 *= 1.22f;
					}
					array[i * width + j] = ToColor32(baseColor * num7);
				}
			}
			int num9 = (bordered ? 14 : 9);
			for (int k = 0; k < num9; k++)
			{
				int num10 = (int)(PixelHash(k, seed, 17) % (uint)width);
				int num11 = (int)(PixelHash(seed, k, 29) % (uint)height);
				int num12 = (int)(6 + PixelHash(k, 31, seed) % (uint)Mathf.Max(7, width / 4));
				for (int l = 0; l < num12; l++)
				{
					int num13 = num10 + l;
					int num14 = num11 + l / 5;
					if (num13 >= 0 && num13 < width && num14 >= 0 && num14 < height)
					{
						array[num14 * width + num13] = ToColor32(baseColor * (metal ? 1.42f : 0.25f));
					}
				}
			}
			return array;
		}

		private static void DrawBitmapText(Color32[] pixels, int width, int height, string text, int scale, Color32 ink)
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			for (int i = 0; i < text.Length; i++)
			{
				string[] array = Glyph(text[i]);
				num += array[0].Length * scale;
				if (i + 1 < text.Length)
				{
					num += scale;
				}
			}
			int num2 = (width - num) / 2;
			int num3 = (height - 7 * scale) / 2;
			int num4 = num2;
			for (int j = 0; j < text.Length; j++)
			{
				string[] array2 = Glyph(text[j]);
				for (int k = 0; k < array2.Length; k++)
				{
					for (int l = 0; l < array2[k].Length; l++)
					{
						if (array2[k][l] != '1')
						{
							continue;
						}
						for (int m = 0; m < scale; m++)
						{
							for (int n = 0; n < scale; n++)
							{
								int num5 = num4 + l * scale + n;
								int num6 = num3 + (6 - k) * scale + m;
								if (num5 >= 0 && num5 < width && num6 >= 0 && num6 < height)
								{
									pixels[num6 * width + num5] = ink;
								}
							}
						}
					}
				}
				num4 += (array2[0].Length + 1) * scale;
			}
		}

		private static string[] Glyph(char character)
		{
			return character switch
			{
				'A' => new string[7] { "01110", "10001", "10001", "11111", "10001", "10001", "10001" }, 
				'C' => new string[7] { "01111", "10000", "10000", "10000", "10000", "10000", "01111" }, 
				'G' => new string[7] { "01110", "10001", "10000", "10111", "10001", "10001", "01110" }, 
				'O' => new string[7] { "01110", "10001", "10001", "10001", "10001", "10001", "01110" }, 
				'R' => new string[7] { "11110", "10001", "10001", "11110", "10100", "10010", "10001" }, 
				'1' => new string[7] { "00100", "01100", "00100", "00100", "00100", "00100", "01110" }, 
				'2' => new string[7] { "01110", "10001", "00001", "00010", "00100", "01000", "11111" }, 
				'3' => new string[7] { "11110", "00001", "00001", "01110", "00001", "00001", "11110" }, 
				'4' => new string[7] { "00010", "00110", "01010", "10010", "11111", "00010", "00010" }, 
				'.' => new string[7] { "0", "0", "0", "0", "0", "1", "1" }, 
				_ => new string[7] { "000", "000", "000", "000", "000", "000", "000" }, 
			};
		}

		private static uint PixelHash(int x, int y, int seed)
		{
			int num = x * 374761393 + y * 668265263 + seed * 1442695041;
			int num2 = (num ^ (num >>> 13)) * 1274126177;
			return (uint)(num2 ^ (num2 >>> 16));
		}

		private static int StableSeed(string value)
		{
			int num = 23;
			foreach (char c in value)
			{
				num = num * 31 + c;
			}
			return num;
		}

		private static Color32 ToColor32(Color color)
		{
			//IL_0000: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			return Color32.op_Implicit(new Color(Mathf.Clamp01(color.r), Mathf.Clamp01(color.g), Mathf.Clamp01(color.b), Mathf.Clamp01(color.a)));
		}

		internal static Sprite CreateInventoryIcon()
		{
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Expected O, but got Unknown
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_0078: 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_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("CargoBackpack.InventoryConcept.png"))
			{
				if (stream != null)
				{
					using (MemoryStream memoryStream = new MemoryStream())
					{
						stream.CopyTo(memoryStream);
						Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
						if (!ImageConversion.LoadImage(val, memoryStream.ToArray()))
						{
							throw new InvalidOperationException("CARGO concept icon could not be decoded.");
						}
						((Object)val).name = "CARGO Concept Icon";
						((Texture)val).filterMode = (FilterMode)1;
						Sprite obj = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), (float)((Texture)val).width);
						Object.DontDestroyOnLoad((Object)(object)val);
						Object.DontDestroyOnLoad((Object)(object)obj);
						return obj;
					}
				}
			}
			Texture2D val2 = new Texture2D(128, 128, (TextureFormat)4, false);
			Color32[] array = (Color32[])(object)new Color32[16384];
			Color val3 = default(Color);
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					bool flag = j >= 30 && j <= 97 && i >= 10 && i <= 108;
					bool flag2 = j >= 45 && j <= 82 && i >= 108 && i <= 120 && (j < 51 || j > 76 || i > 114);
					bool flag3 = ((j >= 16 && j < 30) || (j > 97 && j <= 111)) && i >= 32 && i <= 78;
					if (!flag && !flag2 && !flag3)
					{
						continue;
					}
					((Color)(ref val3))..ctor(0.085f, 0.092f, 0.09f, 1f);
					if (flag && j >= 37 && j <= 90 && i >= 16 && i <= 103)
					{
						int num = (i - 16) % 19;
						if (i >= 93 || num < 15)
						{
							float num2 = ((num < 2) ? 0.48f : ((num > 12) ? 1.15f : 1f));
							float num3 = Mathf.Lerp(0.8f, 1f, (90f - (float)j) / 53f) * num2;
							((Color)(ref val3))..ctor(0.9f * num3, 0.57f * num3, 0.065f * num3, 1f);
							if (j >= 82 && j <= 86 && i < 93 && num > 3 && num < 12)
							{
								((Color)(ref val3))..ctor(0.19f, 0.14f, 0.065f, 1f);
							}
						}
					}
					if (flag3)
					{
						((Color)(ref val3))..ctor(0.58f, 0.37f, 0.065f, 1f);
					}
					if ((j == 31 || j == 96) && flag)
					{
						((Color)(ref val3))..ctor(0.3f, 0.32f, 0.28f, 1f);
					}
					float num4 = 0.94f + (float)(PixelHash(j, i, 21) & 0x1F) / 255f;
					array[i * 128 + j] = Color32.op_Implicit(new Color(val3.r * num4, val3.g * num4, val3.b * num4, 1f));
				}
			}
			val2.SetPixels32(array);
			val2.Apply();
			((Object)val2).name = "CARGO Backpack Icon";
			Object.DontDestroyOnLoad((Object)(object)val2);
			Sprite obj2 = Sprite.Create(val2, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f), 128f);
			((Object)obj2).name = "CARGO Backpack Icon";
			Object.DontDestroyOnLoad((Object)(object)obj2);
			return obj2;
		}
	}
	internal static class CargoFoldLayout
	{
		internal static float BackZ => 0.39f;

		internal static bool ShouldFold(bool crouching, bool crawling, bool tumbling)
		{
			return crouching || crawling || tumbling;
		}

		internal static float BottomY(float fold)
		{
			return -0.99f + 0.465f * Math.Max(0f, Math.Min(1f, fold));
		}

		internal static bool IsModule(string name)
		{
			if (!name.StartsWith("Module ", StringComparison.Ordinal) && !name.StartsWith("Cargo Module ", StringComparison.Ordinal))
			{
				return name.StartsWith("Painted Module Face ", StringComparison.Ordinal);
			}
			return true;
		}

		internal static bool HiddenWhenFolded(string name)
		{
			if (IsModule(name))
			{
				if (name.EndsWith(" 1", StringComparison.Ordinal))
				{
					return name == "Painted Module Face 1";
				}
				return true;
			}
			return false;
		}

		internal static float Y(string name, float y)
		{
			if (IsModule(name))
			{
				return y - 0.465f;
			}
			if (y > 0.48f)
			{
				return y - 0.465f;
			}
			if (y < -0.48f)
			{
				return y + 0.465f;
			}
			return y * (33f / 64f);
		}

		internal static float HeightScale(string name)
		{
			if (!(name == "Hard Shell") && !name.Contains("Side Container") && !name.Contains("Side Spine") && !name.Contains("Shell Wear Strip"))
			{
				return 1f;
			}
			return 33f / 64f;
		}
	}
	public sealed class CargoHandTransfer : MonoBehaviour
	{
		private static readonly FieldInfo Held = AccessTools.Field(typeof(PhysGrabber), "grabbedPhysGrabObject");

		private static readonly FieldInfo Disabled = AccessTools.Field(typeof(PhysGrabber), "grabDisableTimer");

		private static readonly FieldInfo Offset = AccessTools.Field(typeof(PhysGrabObject), "midPointOffset");

		private static readonly FieldInfo Midpoint = AccessTools.Field(typeof(PhysGrabObject), "midPoint");

		private static readonly MethodInfo Release = AccessTools.Method(typeof(PhysGrabber), "ReleaseObject", (Type[])null, (Type[])null);

		private static readonly MethodInfo Grab = AccessTools.Method(typeof(PhysGrabber), "ForceGrabPhysObject", (Type[])null, (Type[])null);

		private Coroutine _pending;

		private static Vector3 Centre(ItemEquippable item)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			PhysGrabObject val = (((Object)(object)item != (Object)null) ? ((Component)item).GetComponent<PhysGrabObject>() : null);
			if (!((Object)(object)val != (Object)null))
			{
				return Vector3.zero;
			}
			return ((Component)item).transform.TransformPoint((Vector3)Offset.GetValue(val));
		}

		internal static Vector3 ReleasePosition(PlayerAvatar owner, ItemEquippable incoming, ItemEquippable outgoing)
		{
			//IL_0009: 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_003b: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)outgoing == (Object)null)
			{
				return Vector3.zero;
			}
			Transform val = (((Object)(object)owner.localCamera != (Object)null) ? owner.localCamera.GetOverrideTransform() : ((Component)owner).transform);
			Vector3 val2 = (((Object)(object)incoming != (Object)null) ? Centre(incoming) : (val.position + val.forward * 1.25f));
			return ((Component)outgoing).transform.position + val2 - Centre(outgoing);
		}

		internal static void RefreshCentre(ItemEquippable item)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			PhysGrabObject val = (((Object)(object)item != (Object)null) ? ((Component)item).GetComponent<PhysGrabObject>() : null);
			if ((Object)(object)val != (Object)null)
			{
				Midpoint.SetValue(val, Centre(item));
			}
		}

		internal static void ReleaseIncoming(ItemEquippable incoming)
		{
			PhysGrabber instance = PhysGrabber.instance;
			PhysGrabObject val = (((Object)(object)incoming != (Object)null) ? ((Component)incoming).GetComponent<PhysGrabObject>() : null);
			if (!((Object)(object)instance == (Object)null) && !((Object)(object)val == (Object)null) && instance.grabbed && !((Object)/*isinst with value type is only supported in some contexts*/ != (Object)(object)val))
			{
				Release.Invoke(instance, new object[2]
				{
					((Object)(object)((MonoBehaviourPun)incoming).photonView != (Object)null) ? ((MonoBehaviourPun)incoming).photonView.ViewID : (-1),
					0.15f
				});
			}
		}

		internal void Begin(ItemEquippable item)
		{
			if (_pending != null)
			{
				((MonoBehaviour)this).StopCoroutine(_pending);
			}
			_pending = ((MonoBehaviour)this).StartCoroutine(Acquire(item));
		}

		private IEnumerator Acquire(ItemEquippable item)
		{
			yield return null;
			PhysGrabber grabber = PhysGrabber.instance;
			PhysGrabObject physical = (((Object)(object)item != (Object)null) ? ((Component)item).GetComponent<PhysGrabObject>() : null);
			float deadline = Time.unscaledTime + 1f;
			while ((Object)(object)grabber != (Object)null && (Object)(object)physical != (Object)null && Time.unscaledTime < deadline && !CargoStoredItemState.Contains(item) && !item.IsEquipped())
			{
				object? value = Held.GetValue(grabber);
				PhysGrabObject val = (PhysGrabObject)((value is PhysGrabObject) ? value : null);
				if (grabber.grabbed)
				{
					if ((Object)(object)val == (Object)(object)physical)
					{
						CargoBackpackPlugin.Log.LogInfo((object)("CARGO handoff confirmed: " + ((Object)item).name));
					}
					break;
				}
				if ((float)Disabled.GetValue(grabber) <= 0f)
				{
					RefreshCentre(item);
					Physics.SyncTransforms();
					Grab.Invoke(grabber, new object[1] { physical });
					if (grabber.grabbed && (Object)/*isinst with value type is only supported in some contexts*/ == (Object)(object)physical)
					{
						CargoBackpackPlugin.Log.LogInfo((object)("CARGO handoff confirmed: " + ((Object)item).name));
						break;
					}
				}
				yield return null;
			}
			_pending = null;
		}
	}
	internal static class CargoHealthGauge
	{
		internal const int LampCount = 6;

		internal const float LensDiameter = 0.055f;

		internal const float SocketDiameter = 0.078f;

		internal static int LitCount(int health, int maximum)
		{
			if (maximum <= 0 || health <= 0)
			{
				return 0;
			}
			return (int)(((long)Math.Min(health, maximum) * 6L + maximum - 1) / maximum);
		}

		internal static float Fraction(int health, int maximum)
		{
			if (maximum <= 0)
			{
				return 0f;
			}
			return (float)Math.Max(0, Math.Min(health, maximum)) / (float)maximum;
		}

		internal static float LampX(int index)
		{
			return ((float)index - 2.5f) * 0.16f;
		}
	}
	public sealed class CargoHealthLights : MonoBehaviour
	{
		private static readonly FieldInfo Current = AccessTools.Field(typeof(PlayerHealth), "health");

		private static readonly FieldInfo Maximum = AccessTools.Field(typeof(PlayerHealth), "maxHealth");

		private static readonly FieldInfo Palette = AccessTools.Field(typeof(PlayerHealth), "healthMaterialColor");

		private static readonly Color Off = new Color(0.025f, 0.032f, 0.028f, 1f);

		private PlayerAvatar _owner;

		private Renderer[] _lenses;

		private MaterialPropertyBlock _properties;

		private float _nextUpdate;

		internal void Initialize(PlayerAvatar owner, Transform body)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			_owner = owner;
			_lenses = (from renderer in ((Component)body).GetComponentsInChildren<Renderer>(true)
				where ((Object)renderer).name.StartsWith("Health Lens ", StringComparison.Ordinal)
				orderby ((Object)renderer).name
				select renderer).ToArray();
			_properties = new MaterialPropertyBlock();
			Refresh();
		}

		private void Update()
		{
			if (_properties != null && !(Time.unscaledTime < _nextUpdate))
			{
				_nextUpdate = Time.unscaledTime + 0.1f;
				Refresh();
			}
		}

		private void Refresh()
		{
			//IL_00bc: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: 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)
			PlayerHealth val = (((Object)(object)_owner != (Object)null) ? _owner.playerHealth : null);
			int health = (((Object)(object)val != (Object)null && Current != null) ? ((int)Current.GetValue(val)) : 0);
			int maximum = (((Object)(object)val != (Object)null && Maximum != null) ? ((int)Maximum.GetValue(val)) : 0);
			Gradient val2 = (Gradient)(((Object)(object)val != (Object)null && Palette != null) ? /*isinst with value type is only supported in some contexts*/: null);
			int num = ((val2 != null) ? CargoHealthGauge.LitCount(health, maximum) : 0);
			Color val3 = ((val2 != null) ? val2.Evaluate(CargoHealthGauge.Fraction(health, maximum)) : Off);
			val3.a = 1f;
			for (int i = 0; i < _lenses.Length; i++)
			{
				if (!((Object)(object)_lenses[i] == (Object)null))
				{
					bool flag = i < num;
					_properties.Clear();
					_properties.SetColor("_Color", flag ? val3 : Off);
					_properties.SetColor("_BaseColor", flag ? val3 : Off);
					_properties.SetColor("_EmissionColor", flag ? (val3 * 2.2f) : Color.black);
					_lenses[i].SetPropertyBlock(_properties);
				}
			}
		}
	}
	internal static class CargoInventoryUI
	{
		private static RectTransform _root;

		private static readonly RectTransform[] Slots = (RectTransform[])(object)new RectTransform[4];

		private static readonly Image[] Icons = (Image[])(object)new Image[4];

		private static readonly TextMeshProUGUI[] Numbers = (TextMeshProUGUI[])(object)new TextMeshProUGUI[4];

		private static readonly RectTransform[] Lines = (RectTransform[])(object)new RectTransform[3];

		private static readonly Color Gold = new Color(1f, 0.72f, 0.12f, 0.9f);

		internal static void EnsureBuilt()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing re