Decompiled source of SecondHotbarSwap v1.0.0

SecondHotbarSwap.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.UI;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
internal sealed class ConfigurationManagerAttributes
{
	public int? Order;
}
namespace SecondHotbarSwap
{
	[BepInPlugin("Iteravio.SecondHotbarSwap", "SecondHotbarSwap", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal sealed class HeldItem
		{
			public ItemData Item;

			public bool WasEquipped;
		}

		internal sealed class DeathState
		{
			public readonly List<HeldItem> Held = new List<HeldItem>();

			public readonly List<ItemData> Dropping = new List<ItemData>();

			public bool Dropped;
		}

		public const string PluginGuid = "Iteravio.SecondHotbarSwap";

		public const string PluginName = "SecondHotbarSwap";

		public const string PluginVersion = "1.0.0";

		private const string StoredBarKey = "Iteravio.SecondHotbarSwap.StoredBar";

		private const string ActiveBarKey = "Iteravio.SecondHotbarSwap.ActiveBar";

		private const int HotbarWidth = 8;

		private static readonly FieldRef<InventoryGui, GameObject> DragGo = AccessTools.FieldRefAccess<InventoryGui, GameObject>("m_dragGo");

		private static readonly Action<Inventory> UpdateTotalWeight = AccessTools.MethodDelegate<Action<Inventory>>(AccessTools.Method(typeof(Inventory), "UpdateTotalWeight", (Type[])null, (Type[])null), (object)null, true);

		private static ConfigEntry<KeyboardShortcut> swapKey;

		private static ConfigEntry<bool> showIndicator;

		private static ConfigEntry<bool> playSwapSound;

		private static ConfigEntry<bool> keepHotbars;

		private static ConfigEntry<bool> keepNonTeleportable;

		private static ConfigEntry<bool> keepEquipped;

		private static ConfigEntry<bool> debugLogging;

		private static ManualLogSource Log;

		private static Player cachedOwner;

		private static Inventory cachedBar;

		private RectTransform indicator;

		private Image topDot;

		private Image bottomDot;

		private static DeathState currentDeath;

		private static readonly Color DotLit = Color32.op_Implicit(new Color32((byte)32, (byte)180, (byte)30, byte.MaxValue));

		private static readonly Color DotUnlit = Color32.op_Implicit(new Color32((byte)40, (byte)40, (byte)48, (byte)170));

		private static Sprite circleSprite;

		private void Awake()
		{
			//IL_0022: 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_00b1: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Expected O, but got Unknown
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			swapKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Controls", "SwapHotbarKey", new KeyboardShortcut((KeyCode)96, Array.Empty<KeyCode>()), "Swaps your hotbar with your second hotbar. [Not synced with Server]");
			playSwapSound = ((BaseUnityPlugin)this).Config.Bind<bool>("Controls", "PlaySwapSound", true, "Plays the inventory's item-move sound when you swap hotbars. [Not synced with Server]");
			showIndicator = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "ShowActiveHotbarDots", true, "Shows two dots left of the hotbar; the lit one is the active hotbar (top for 1, bottom for 2). [Not synced with Server]");
			keepHotbars = ((BaseUnityPlugin)this).Config.Bind<bool>("Death", "KeepHotbarsOnDeath", false, new ConfigDescription("Keeps the items on both hotbars when you die. Items that can't go through portals still drop. Vanilla: everything drops. [Not synced with Server]", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 3
				}
			}));
			keepNonTeleportable = ((BaseUnityPlugin)this).Config.Bind<bool>("Death", "KeepNonTeleportableHotbarItemsOnDeath", false, new ConfigDescription("Also keeps hotbar items that can't go through portals, like ore. Only works with KeepHotbarsOnDeath enabled. [Not synced with Server]", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 2
				}
			}));
			keepEquipped = ((BaseUnityPlugin)this).Config.Bind<bool>("Death", "KeepEquippedItemsOnDeath", false, new ConfigDescription("Keeps the items you have equipped when you die. Vanilla: everything drops. [Not synced with Server]", (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					Order = 1
				}
			}));
			debugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "DebugLogging", false, "Logs what each death keeps and drops. [Not synced with Server]");
			new Harmony("Iteravio.SecondHotbarSwap").PatchAll();
		}

		private void Update()
		{
			UpdateHud();
			if (SwapKeyDown())
			{
				Player localPlayer = Player.m_localPlayer;
				if (!((Object)(object)localPlayer == (Object)null) && !((Character)localPlayer).IsDead() && !((Character)localPlayer).InAttack() && !IsTyping() && (!((Object)(object)InventoryGui.instance != (Object)null) || !((Object)(object)DragGo.Invoke(InventoryGui.instance) != (Object)null)))
				{
					Swap(localPlayer);
				}
			}
		}

		private static bool SwapKeyDown()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			KeyboardShortcut value = swapKey.Value;
			if ((int)((KeyboardShortcut)(ref value)).MainKey != 0 && UnityInput.Current.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey))
			{
				return ((KeyboardShortcut)(ref value)).Modifiers.All((Func<KeyCode, bool>)UnityInput.Current.GetKey);
			}
			return false;
		}

		private static bool IsTyping()
		{
			if (!Console.IsVisible() && !TextInput.IsVisible() && !Menu.IsVisible())
			{
				if ((Object)(object)Chat.instance != (Object)null)
				{
					return Chat.instance.HasFocus();
				}
				return false;
			}
			return true;
		}

		private static void Swap(Player player)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			Inventory inventory = ((Humanoid)player).GetInventory();
			Inventory storedBar = GetStoredBar(player);
			List<ItemData> list = new List<ItemData>();
			for (int i = 0; i < 8; i++)
			{
				ItemData itemAt = inventory.GetItemAt(i, 0);
				if (itemAt != null)
				{
					if (player.IsEquipActionQueued(itemAt))
					{
						return;
					}
					list.Add(itemAt);
				}
			}
			Inventory val = new Inventory("SecondHotbarSwap", (Sprite)null, 8, 1);
			foreach (ItemData item in list)
			{
				int x = item.m_gridPos.x;
				if (item.m_equipped)
				{
					((Humanoid)player).UnequipItem(item, true);
				}
				val.MoveItemToThis(inventory, item, item.m_stack, x, 0);
			}
			foreach (ItemData item2 in storedBar.GetAllItems().ToList())
			{
				inventory.MoveItemToThis(storedBar, item2, item2.m_stack, item2.m_gridPos.x, 0);
			}
			foreach (ItemData item3 in storedBar.GetAllItems().ToList())
			{
				Log.LogWarning((object)("Couldn't place " + item3.m_shared.m_name + " on the hotbar; adding it to the inventory instead."));
				if (!inventory.AddItem(item3))
				{
					ItemDrop.DropItem(item3, item3.m_stack, ((Component)player).transform.position + Vector3.up, Quaternion.identity);
				}
			}
			SetStoredBar(player, val);
			player.m_customData["Iteravio.SecondHotbarSwap.ActiveBar"] = ((GetActiveBar(player) == 1) ? "2" : "1");
			if (playSwapSound.Value && (Object)(object)InventoryGui.instance != (Object)null)
			{
				InventoryGui.instance.m_moveItemEffects.Create(((Component)InventoryGui.instance).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
			}
		}

		internal static Inventory GetStoredBar(Player player)
		{
			if (cachedBar == null || (Object)(object)cachedOwner != (Object)(object)player)
			{
				cachedBar = LoadStoredBar(player);
				cachedOwner = player;
			}
			return cachedBar;
		}

		private static void SetStoredBar(Player player, Inventory bar)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			cachedOwner = player;
			cachedBar = bar;
			UpdateTotalWeight(bar);
			if (bar.NrOfItems() == 0)
			{
				player.m_customData.Remove("Iteravio.SecondHotbarSwap.StoredBar");
			}
			else
			{
				ZPackage val = new ZPackage();
				bar.Save(val);
				player.m_customData["Iteravio.SecondHotbarSwap.StoredBar"] = val.GetBase64();
			}
			UpdateTotalWeight(((Humanoid)player).GetInventory());
		}

		private static Inventory LoadStoredBar(Player player)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			Inventory val = new Inventory("SecondHotbarSwap", (Sprite)null, 8, 1);
			if (player.m_customData.TryGetValue("Iteravio.SecondHotbarSwap.StoredBar", out var value) && !string.IsNullOrEmpty(value))
			{
				val.Load(new ZPackage(value));
			}
			return val;
		}

		internal static void OnPlayerLoaded(Player player)
		{
			cachedOwner = null;
			UpdateTotalWeight(((Humanoid)player).GetInventory());
		}

		internal static bool IsLocalInventory(Inventory inventory)
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null)
			{
				return inventory == ((Humanoid)localPlayer).GetInventory();
			}
			return false;
		}

		private static bool CanTeleport(ItemData item, bool allowAllItems)
		{
			if (item.m_shared.m_toolTier >= 1000)
			{
				return false;
			}
			if (!allowAllItems && !ZoneSystem.instance.GetGlobalKey((GlobalKeys)35))
			{
				return item.m_shared.m_teleportable;
			}
			return true;
		}

		internal static bool StoredBarCanTeleport(Player player, bool allowAllItems)
		{
			return GetStoredBar(player).GetAllItems().All((ItemData item) => CanTeleport(item, allowAllItems));
		}

		private static bool KeepsOnDeath(ItemData item)
		{
			if (keepHotbars.Value)
			{
				if (!keepNonTeleportable.Value)
				{
					return CanTeleport(item, allowAllItems: false);
				}
				return true;
			}
			return false;
		}

		internal static DeathState PrepareDeath(Player player)
		{
			DeathState deathState = new DeathState();
			Inventory inventory = ((Humanoid)player).GetInventory();
			List<ItemData> allItems = inventory.GetAllItems();
			foreach (ItemData item in allItems.ToList())
			{
				if ((keepEquipped.Value && item.m_equipped) || (item.m_gridPos.y == 0 && KeepsOnDeath(item)))
				{
					deathState.Held.Add(new HeldItem
					{
						Item = item,
						WasEquipped = item.m_equipped
					});
					allItems.Remove(item);
				}
			}
			Inventory storedBar = GetStoredBar(player);
			deathState.Dropping.AddRange(from item in storedBar.GetAllItems()
				where !KeepsOnDeath(item)
				select item);
			UpdateTotalWeight(inventory);
			if (debugLogging.Value)
			{
				Log.LogInfo((object)("Death: keeping " + Describe(deathState.Held.Select((HeldItem held) => held.Item)) + "; stored bar items dropping " + Describe(deathState.Dropping) + ", keeping " + Describe(storedBar.GetAllItems().Except(deathState.Dropping)) + "."));
			}
			currentDeath = deathState;
			return deathState;
		}

		private static string Describe(IEnumerable<ItemData> items)
		{
			List<string> list = items.Select((ItemData item) => $"{item.m_shared.m_name} [{item.m_gridPos.x},{item.m_gridPos.y}]").ToList();
			if (list.Count != 0)
			{
				return string.Join(", ", list);
			}
			return "nothing";
		}

		internal static void OnMoveInventoryToGrave(Inventory grave, Inventory original)
		{
			DeathState deathState = currentDeath;
			if (deathState != null && !deathState.Dropped && IsLocalInventory(original))
			{
				PutInGrave(Player.m_localPlayer, grave, deathState);
			}
		}

		private static void PutInGrave(Player player, Inventory grave, DeathState state)
		{
			//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)
			Inventory storedBar = GetStoredBar(player);
			foreach (ItemData item in state.Dropping)
			{
				storedBar.GetAllItems().Remove(item);
				item.m_gridPos = FindFreeCell(grave);
				grave.GetAllItems().Add(item);
			}
			state.Dropped = true;
			SetStoredBar(player, storedBar);
			UpdateTotalWeight(grave);
			grave.m_onChanged?.Invoke();
			if (debugLogging.Value)
			{
				Log.LogInfo((object)("Death: put " + Describe(state.Dropping) + " into the tombstone."));
			}
		}

		private static Vector2i FindFreeCell(Inventory inventory)
		{
			//IL_004b: 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)
			for (int i = 0; i < inventory.GetHeight(); i++)
			{
				for (int j = 0; j < inventory.GetWidth(); j++)
				{
					if (inventory.GetItemAt(j, i) == null)
					{
						return new Vector2i(j, i);
					}
				}
			}
			inventory.SetHeight(inventory.GetHeight() + 1);
			return new Vector2i(0, inventory.GetHeight() - 1);
		}

		internal static void RestoreAfterDeath(Player player, DeathState state)
		{
			//IL_00fa: 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)
			if (state == null)
			{
				return;
			}
			currentDeath = null;
			Inventory inventory = ((Humanoid)player).GetInventory();
			if (!state.Dropped && state.Dropping.Count > 0)
			{
				ZoneSystem instance = ZoneSystem.instance;
				if (instance.GetGlobalKey((GlobalKeys)23))
				{
					if (debugLogging.Value)
					{
						Log.LogInfo((object)"Death: keep-inventory world modifier, the stored bar stays.");
					}
				}
				else if (instance.GetGlobalKey((GlobalKeys)20) || instance.GetGlobalKey((GlobalKeys)21))
				{
					Inventory storedBar = GetStoredBar(player);
					foreach (ItemData item in state.Dropping)
					{
						storedBar.GetAllItems().Remove(item);
					}
					SetStoredBar(player, storedBar);
					if (debugLogging.Value)
					{
						Log.LogInfo((object)("Death: delete-items world modifier, deleted " + Describe(state.Dropping) + "."));
					}
				}
				else
				{
					GameObject val = Object.Instantiate<GameObject>(player.m_tombstone, ((Character)player).GetCenterPoint(), ((Component)player).transform.rotation);
					PutInGrave(player, val.GetComponent<Container>().GetInventory(), state);
					PlayerProfile playerProfile = Game.instance.GetPlayerProfile();
					val.GetComponent<TombStone>().Setup(playerProfile.GetName(), playerProfile.GetPlayerID());
				}
			}
			List<ItemData> allItems = inventory.GetAllItems();
			foreach (HeldItem item2 in state.Held)
			{
				item2.Item.m_equipped = item2.WasEquipped;
				if (!allItems.Contains(item2.Item))
				{
					allItems.Add(item2.Item);
				}
			}
			UpdateTotalWeight(inventory);
		}

		private static int GetActiveBar(Player player)
		{
			if (!player.m_customData.TryGetValue("Iteravio.SecondHotbarSwap.ActiveBar", out var value) || !(value == "2"))
			{
				return 1;
			}
			return 2;
		}

		private void UpdateHud()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)indicator == (Object)null)
			{
				if ((Object)(object)localPlayer == (Object)null || (Object)(object)Hud.instance == (Object)null)
				{
					return;
				}
				HotkeyBar componentInChildren = ((Component)Hud.instance).GetComponentInChildren<HotkeyBar>(true);
				if ((Object)(object)componentInChildren == (Object)null || (Object)(object)componentInChildren.m_elementPrefab == (Object)null)
				{
					return;
				}
				CreateIndicator(componentInChildren);
				if ((Object)(object)indicator == (Object)null)
				{
					return;
				}
			}
			bool flag = showIndicator.Value && (Object)(object)localPlayer != (Object)null && !((Character)localPlayer).IsDead();
			if (((Component)indicator).gameObject.activeSelf != flag)
			{
				((Component)indicator).gameObject.SetActive(flag);
			}
			if (flag)
			{
				bool flag2 = GetActiveBar(localPlayer) == 1;
				SetDot(topDot, flag2);
				SetDot(bottomDot, !flag2);
			}
		}

		private static void SetDot(Image dot, bool lit)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			Color val = (lit ? DotLit : DotUnlit);
			if (((Graphic)dot).color != val)
			{
				((Graphic)dot).color = val;
			}
		}

		private void CreateIndicator(HotkeyBar bar)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_008f: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = bar.m_elementPrefab.transform;
			RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			if (!((Object)(object)val == (Object)null))
			{
				Rect rect = val.rect;
				Vector2 size = ((Rect)(ref rect)).size;
				float num = size.x * 0.24f;
				float num2 = size.x * 0.08f;
				GameObject val2 = new GameObject("SecondHotbarSwapIndicator", new Type[1] { typeof(RectTransform) });
				indicator = (RectTransform)val2.transform;
				((Transform)indicator).SetParent(((Component)bar).transform, false);
				indicator.anchorMin = val.anchorMin;
				indicator.anchorMax = val.anchorMax;
				indicator.pivot = new Vector2(0.5f, 0.5f);
				indicator.sizeDelta = new Vector2(num, num * 2f + num2);
				float num3 = (0f - val.pivot.x) * size.x;
				float num4 = (0.5f - val.pivot.y) * size.y;
				((Transform)indicator).localPosition = new Vector3(num3 - size.x * 0.42f, num4, 0f);
				Sprite circle = CircleSprite();
				float num5 = (num + num2) / 2f;
				topDot = CreateDot((Transform)(object)indicator, circle, num, num5);
				bottomDot = CreateDot((Transform)(object)indicator, circle, num, 0f - num5);
			}
		}

		private static Image CreateDot(Transform parent, Sprite circle, float diameter, float y)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Dot", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val.transform.SetParent(parent, false);
			Image component = val.GetComponent<Image>();
			component.sprite = circle;
			((Graphic)component).color = DotUnlit;
			((Graphic)component).raycastTarget = false;
			((Graphic)component).rectTransform.sizeDelta = new Vector2(diameter, diameter);
			((Transform)((Graphic)component).rectTransform).localPosition = new Vector3(0f, y, 0f);
			return component;
		}

		private static Sprite CircleSprite()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: 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_008d: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)circleSprite != (Object)null)
			{
				return circleSprite;
			}
			Texture2D val = new Texture2D(128, 128, (TextureFormat)4, true)
			{
				filterMode = (FilterMode)2,
				wrapMode = (TextureWrapMode)1
			};
			Color32[] array = (Color32[])(object)new Color32[16384];
			float num = 64f;
			float num2 = num * 0.82f;
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.16f, 0.16f, 0.18f, 1f);
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num3 = Vector2.Distance(new Vector2((float)j + 0.5f, (float)i + 0.5f), new Vector2(num, num));
					float a = Mathf.Clamp01(num - num3);
					Color val3 = Color.Lerp(Color.white, val2, Mathf.Clamp01(num3 - num2 + 0.5f));
					val3.a = a;
					array[i * 128 + j] = Color32.op_Implicit(val3);
				}
			}
			val.SetPixels32(array);
			val.Apply(true, true);
			circleSprite = Sprite.Create(val, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f));
			return circleSprite;
		}
	}
	[HarmonyPatch(typeof(Inventory), "UpdateTotalWeight")]
	internal static class InventoryUpdateTotalWeightPatch
	{
		private static void Postfix(Inventory __instance, ref float ___m_totalWeight)
		{
			if (Plugin.IsLocalInventory(__instance))
			{
				___m_totalWeight += Plugin.GetStoredBar(Player.m_localPlayer).GetTotalWeight();
			}
		}
	}
	[HarmonyPatch(typeof(Inventory), "IsTeleportable")]
	internal static class InventoryIsTeleportablePatch
	{
		private static void Postfix(Inventory __instance, bool allowAllItems, ref bool __result)
		{
			if (__result && Plugin.IsLocalInventory(__instance))
			{
				__result = Plugin.StoredBarCanTeleport(Player.m_localPlayer, allowAllItems);
			}
		}
	}
	[HarmonyPatch(typeof(Player), "Load")]
	internal static class PlayerLoadPatch
	{
		private static void Postfix(Player __instance)
		{
			Plugin.OnPlayerLoaded(__instance);
		}
	}
	[HarmonyPatch(typeof(Player), "CreateTombStone")]
	internal static class PlayerCreateTombStonePatch
	{
		[HarmonyPriority(800)]
		private static void Prefix(Player __instance, out Plugin.DeathState __state)
		{
			__state = (((Object)(object)__instance == (Object)(object)Player.m_localPlayer) ? Plugin.PrepareDeath(__instance) : null);
		}

		[HarmonyPriority(0)]
		private static Exception Finalizer(Player __instance, Plugin.DeathState __state, Exception __exception)
		{
			Plugin.RestoreAfterDeath(__instance, __state);
			return __exception;
		}
	}
	[HarmonyPatch(typeof(Inventory), "MoveInventoryToGrave")]
	internal static class InventoryMoveInventoryToGravePatch
	{
		[HarmonyPriority(0)]
		private static void Postfix(Inventory __instance, Inventory original)
		{
			Plugin.OnMoveInventoryToGrave(__instance, original);
		}
	}
}