Decompiled source of BetterBeginnings v1.0.1

BepInEx/plugins/BetterBeginnings.dll

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BetterBeginnings
{
	internal static class AdrenalineGainConfig
	{
		internal static ConfigEntry<float> DaggerAttackMultiplier;

		internal static ConfigEntry<float> FastOneHandedAttackMultiplier;

		internal static ConfigEntry<float> StandardOneHandedAttackMultiplier;

		internal static ConfigEntry<float> PolearmAttackMultiplier;

		internal static ConfigEntry<float> HeavyTwoHandedAttackMultiplier;

		internal static ConfigEntry<float> BlockAndParryMultiplier;

		internal static ConfigEntry<float> ShieldBlockAndParryMultiplier;

		internal static void Initialize(ConfigFile config)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: 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
			AcceptableValueRange<float> val = new AcceptableValueRange<float>(0f, 10f);
			DaggerAttackMultiplier = config.Bind<float>("Adrenaline Multipliers", "DaggerHit", 2f, new ConfigDescription("Adrenaline multiplier for dagger hits. Range: 0 to 10. Restart the game after changing this value.", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			FastOneHandedAttackMultiplier = config.Bind<float>("Adrenaline Multipliers", "FastOneHandedHit", 2.5f, new ConfigDescription("Adrenaline multiplier for fast one-handed weapon hits, including swords and spears. Range: 0 to 10. Restart the game after changing this value.", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			StandardOneHandedAttackMultiplier = config.Bind<float>("Adrenaline Multipliers", "StandardOneHandedHit", 3f, new ConfigDescription("Adrenaline multiplier for standard one-handed weapon hits, including one-handed axes and clubs. Range: 0 to 10. Restart the game after changing this value.", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			PolearmAttackMultiplier = config.Bind<float>("Adrenaline Multipliers", "PolearmHit", 3.5f, new ConfigDescription("Adrenaline multiplier for polearm hits, such as atgeirs. Range: 0 to 10. Restart the game after changing this value.", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			HeavyTwoHandedAttackMultiplier = config.Bind<float>("Adrenaline Multipliers", "HeavyTwoHandedHit", 4f, new ConfigDescription("Adrenaline multiplier for two-handed weapon hits. Range: 0 to 10. Restart the game after changing this value.", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			BlockAndParryMultiplier = config.Bind<float>("Adrenaline Multipliers", "WeaponBlockAndParry", 1f, new ConfigDescription("Adrenaline multiplier gained from blocking and parrying with weapons. Range: 0 to 10. Restart the game after changing this value.", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			ShieldBlockAndParryMultiplier = config.Bind<float>("Adrenaline Multipliers", "ShieldBlockAndParry", 2f, new ConfigDescription("Adrenaline multiplier gained from blocking and parrying with shields. Range: 0 to 10. Restart the game after changing this value.", (AcceptableValueBase)(object)val, Array.Empty<object>()));
		}
	}
	internal static class CombatStateTracker
	{
		[HarmonyPatch(typeof(Player), "RPC_OnTargeted")]
		private static class PlayerTargetedPatch
		{
			private static void Postfix(bool alerted)
			{
				if (alerted)
				{
					MarkCombat();
				}
			}
		}

		[HarmonyPatch(typeof(Player), "OnDamaged")]
		private static class PlayerDamagedPatch
		{
			private static void Postfix(Player __instance, HitData hit)
			{
				Character val = ((hit != null) ? hit.GetAttacker() : null);
				if ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)__instance && BaseAI.IsEnemy((Character)(object)__instance, val))
				{
					MarkCombat();
				}
			}
		}

		[HarmonyPatch(typeof(Character), "Damage")]
		private static class CharacterDamagePatch
		{
			private static void Postfix(Character __instance, HitData hit)
			{
				Character obj = ((hit != null) ? hit.GetAttacker() : null);
				Player val = (Player)(object)((obj is Player) ? obj : null);
				if ((Object)(object)val != (Object)null && (Object)(object)val == (Object)(object)Player.m_localPlayer && BaseAI.IsEnemy(__instance, (Character)(object)val))
				{
					MarkCombat();
				}
			}
		}

		[HarmonyPatch(typeof(MonsterAI), "UpdateTarget")]
		private static class MonsterTargetPatch
		{
			private static void Postfix(MonsterAI __instance)
			{
				if ((Object)(object)((BaseAI)__instance).GetTargetCreature() == (Object)(object)Player.m_localPlayer)
				{
					MarkCombat();
				}
			}
		}

		private static float _combatUntil;

		private const float CombatGracePeriod = 10f;

		internal static void MarkCombat()
		{
			_combatUntil = Time.time + 10f;
		}

		internal static bool IsInCombat()
		{
			return Time.time < _combatUntil;
		}
	}
	internal static class HudLayout
	{
		[HarmonyPatch]
		private static class UpdateGuardianPowerPatch
		{
			private static MethodBase TargetMethod()
			{
				return (from assembly in AppDomain.CurrentDomain.GetAssemblies()
					select assembly.GetType("Hud")).FirstOrDefault((Type type) => type != null)?.GetMethod("UpdateGuardianPower", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}

			private static void Postfix(Component __instance)
			{
				if (IsAppliedFor(__instance))
				{
					KeepStaminaBesideHealth(__instance);
					KeepStaminaVisible(__instance);
				}
			}
		}

		[HarmonyPatch]
		private static class UpdateStaminaPatch
		{
			private static MethodBase TargetMethod()
			{
				return (from assembly in AppDomain.CurrentDomain.GetAssemblies()
					select assembly.GetType("Hud")).FirstOrDefault((Type type) => type != null)?.GetMethod("UpdateStamina", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}

			private static void Postfix(Component __instance)
			{
				if (IsAppliedFor(__instance))
				{
					SyncStaminaBarWidths(__instance, ((object)__instance).GetType());
					if (!_staminaDiagnosticLogged && _logger != null)
					{
						GuiBar fieldComponent = HudLayout.GetFieldComponent<GuiBar>(__instance, ((object)__instance).GetType(), "m_staminaBar2Slow");
						GuiBar fieldComponent2 = HudLayout.GetFieldComponent<GuiBar>(__instance, ((object)__instance).GetType(), "m_staminaBar2Fast");
						_logger.LogInfo((object)("体力条运行时诊断: 慢条=" + DescribeGuiBar(fieldComponent) + ", 快条=" + DescribeGuiBar(fieldComponent2)));
						_staminaDiagnosticLogged = true;
					}
					KeepStaminaBesideHealth(__instance);
					KeepStaminaVisible(__instance);
				}
			}
		}

		private static bool _layoutApplied;

		private static Component _appliedHud;

		private static RectTransform[] _adjacentHudGroupRoots;

		private static readonly FieldInfo GuiBarWidthField = typeof(GuiBar).GetField("m_width", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo GuiBarValueField = typeof(GuiBar).GetField("m_value", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo GuiBarMaxValueField = typeof(GuiBar).GetField("m_maxValue", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo GuiBarSmoothValueField = typeof(GuiBar).GetField("m_smoothValue", BindingFlags.Instance | BindingFlags.NonPublic);

		private static ManualLogSource _logger;

		private static bool _staminaDiagnosticLogged;

		private static Image _virtualHealthImage;

		internal static bool TryApply(Component hud, Type hudType, ManualLogSource logger)
		{
			if ((Object)(object)hud == (Object)null || hudType == null)
			{
				return false;
			}
			_logger = logger;
			Transform fieldComponent = HudLayout.GetFieldComponent<Transform>(hud, hudType, "m_healthBarRoot");
			Transform fieldComponent2 = HudLayout.GetFieldComponent<Transform>(hud, hudType, "m_staminaBar2Root");
			TMP_Text fieldComponent3 = HudLayout.GetFieldComponent<TMP_Text>(hud, hudType, "m_healthText");
			TMP_Text fieldComponent4 = HudLayout.GetFieldComponent<TMP_Text>(hud, hudType, "m_staminaText");
			if ((Object)(object)fieldComponent == (Object)null || (Object)(object)fieldComponent2 == (Object)null || (Object)(object)fieldComponent3 == (Object)null || (Object)(object)fieldComponent4 == (Object)null)
			{
				return false;
			}
			if (!ApplyStaminaLayout(hud, fieldComponent, fieldComponent2, fieldComponent3, fieldComponent4, logger))
			{
				_layoutApplied = false;
				return false;
			}
			if ((Object)(object)_appliedHud != (Object)(object)hud)
			{
				_staminaDiagnosticLogged = false;
				_virtualHealthImage = null;
			}
			_appliedHud = hud;
			_layoutApplied = true;
			return true;
		}

		internal static bool IsAppliedFor(Component hud)
		{
			if (!_layoutApplied || (Object)(object)hud == (Object)null || (Object)(object)_appliedHud != (Object)(object)hud)
			{
				return false;
			}
			Type type = ((object)hud).GetType();
			RectTransform fieldComponent = HudLayout.GetFieldComponent<RectTransform>(hud, type, "m_healthBarRoot");
			RectTransform fieldComponent2 = HudLayout.GetFieldComponent<RectTransform>(hud, type, "m_staminaBar2Root");
			Transform val = ((fieldComponent != null) ? ((Transform)fieldComponent).parent : null);
			if ((Object)(object)fieldComponent != (Object)null && (Object)(object)fieldComponent2 != (Object)null && (Object)(object)val != (Object)null && (Object)(object)((Transform)fieldComponent2).parent == (Object)(object)val)
			{
				return (Object)(object)((Transform)fieldComponent2).Find("Stamina") != (Object)null;
			}
			return false;
		}

		private static bool ApplyStaminaLayout(Component hud, Transform healthRoot, Transform staminaRoot, TMP_Text healthText, TMP_Text staminaText, ManualLogSource logger)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: 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_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: 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_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = (RectTransform)(object)((healthRoot is RectTransform) ? healthRoot : null);
			RectTransform val2 = (RectTransform)(object)((staminaRoot is RectTransform) ? staminaRoot : null);
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				return false;
			}
			Transform parent = healthRoot.parent;
			Transform val3 = staminaRoot.Find("Stamina");
			RectTransform val4 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			RectTransform val5 = (RectTransform)(object)((val3 is RectTransform) ? val3 : null);
			if ((Object)(object)parent == (Object)null || (Object)(object)val4 == (Object)null || (Object)(object)val5 == (Object)null)
			{
				return false;
			}
			Canvas.ForceUpdateCanvases();
			staminaRoot.SetParent(parent, false);
			val2.anchorMin = val4.anchorMin;
			val2.anchorMax = val4.anchorMax;
			val2.pivot = val.pivot;
			val2.sizeDelta = val.sizeDelta;
			((Transform)val2).localRotation = healthRoot.localRotation;
			((Transform)val2).localScale = healthRoot.localScale;
			val2.anchoredPosition = val.anchoredPosition;
			val5.anchorMin = Vector2.zero;
			val5.anchorMax = Vector2.one;
			val5.pivot = new Vector2(0.5f, 0.5f);
			val5.anchoredPosition = Vector2.zero;
			val5.sizeDelta = Vector2.zero;
			CopyHealthVisuals(parent, healthRoot, val3);
			SyncStaminaBarWidths(hud, ((object)hud).GetType());
			CopyTextStyle(healthText, staminaText);
			((Transform)staminaText.rectTransform).localRotation = Quaternion.Euler(0f, 0f, -90f);
			staminaText.rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
			staminaText.rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
			staminaText.rectTransform.anchoredPosition = Vector2.zero;
			staminaText.rectTransform.sizeDelta = healthText.rectTransform.sizeDelta;
			Canvas.ForceUpdateCanvases();
			Rect val6 = RectInParent(val, parent);
			Rect val7 = RectInParent(val2, parent);
			PositionStaminaBesideHealth(val, val2, parent);
			val7 = RectInParent(val2, parent);
			MoveHudGroupRightOfStamina(hud, val2);
			logger.LogInfo((object)($"体力条布局诊断: 血条根={val6}, 体力条根={val7}; " + "血条背景=" + DescribeRect((RectTransform)/*isinst with value type is only supported in some contexts*/) + ", 体力背景=" + DescribeRect((RectTransform)/*isinst with value type is only supported in some contexts*/) + ", 血条填充=" + DescribeRect((RectTransform)/*isinst with value type is only supported in some contexts*/) + ", 体力填充=" + DescribeRect((RectTransform)/*isinst with value type is only supported in some contexts*/)));
			return true;
		}

		private static Rect ScreenRect(RectTransform rect, Camera uiCamera)
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			rect.GetWorldCorners(array);
			Vector2[] source = array.Select((Vector3 corner) => RectTransformUtility.WorldToScreenPoint(uiCamera, corner)).ToArray();
			return Rect.MinMaxRect(source.Min((Vector2 point) => point.x), source.Min((Vector2 point) => point.y), source.Max((Vector2 point) => point.x), source.Max((Vector2 point) => point.y));
		}

		private static RectTransform[] GetAdjacentHudGroupRoots(Component hud, Type hudType)
		{
			List<RectTransform> candidates = new List<RectTransform>();
			object obj = hudType.GetField("m_gpRoot", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(hud);
			GameObject val = (GameObject)((obj is GameObject) ? obj : null);
			object obj3;
			if (val == null)
			{
				object obj2 = ((obj is Component) ? obj : null);
				obj3 = ((obj2 != null) ? ((Component)obj2).transform : null);
			}
			else
			{
				obj3 = val.transform;
			}
			RectTransform val2 = (RectTransform)((obj3 is RectTransform) ? obj3 : null);
			if (val2 != null)
			{
				candidates.Add(val2);
			}
			string[] array = new string[4] { "m_gpIcon", "m_gpName", "m_gpCooldown", "m_gpTouchButton" };
			foreach (string name in array)
			{
				object obj4 = hudType.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(hud);
				GameObject val3 = (GameObject)((obj4 is GameObject) ? obj4 : null);
				object obj6;
				if (val3 == null)
				{
					object obj5 = ((obj4 is Component) ? obj4 : null);
					obj6 = ((obj5 != null) ? ((Component)obj5).transform : null);
				}
				else
				{
					obj6 = val3.transform;
				}
				RectTransform val4 = (RectTransform)((obj6 is RectTransform) ? obj6 : null);
				if (val4 != null)
				{
					candidates.Add(val4);
				}
			}
			Transform val5 = hud.transform.Find("hudroot");
			if ((Object)(object)val5 != (Object)null)
			{
				for (int j = 0; j < val5.childCount; j++)
				{
					Transform child = val5.GetChild(j);
					if (((Object)child).name == "CDEV_QuickSlots" || ((Object)child).name == "CDEV_QuickSlot1" || ((Object)child).name == "CDEV_QuickSlot2" || ((Object)child).name == "CDEV_QuickSlot3" || ((Object)child).name == "CDEV_QuickSlot4" || ((Object)child).name == "CDEV_QuickSlot5" || ((Object)child).name == "CDEV_QuickSlot6")
					{
						RectTransform val6 = (RectTransform)(object)((child is RectTransform) ? child : null);
						if (val6 != null)
						{
							candidates.Add(val6);
						}
					}
				}
			}
			RectTransform healthRect = HudLayout.GetFieldComponent<RectTransform>(hud, hudType, "m_healthBarRoot");
			RectTransform staminaRect = HudLayout.GetFieldComponent<RectTransform>(hud, hudType, "m_staminaBar2Root");
			candidates.RemoveAll((RectTransform candidate) => ((Object)(object)healthRect != (Object)null && ((Transform)healthRect).IsChildOf((Transform)(object)candidate)) || ((Object)(object)staminaRect != (Object)null && ((Transform)staminaRect).IsChildOf((Transform)(object)candidate)));
			return (from candidate in candidates.Distinct()
				where !candidates.Any((RectTransform other) => (Object)(object)other != (Object)(object)candidate && ((Transform)candidate).IsChildOf((Transform)(object)other))
				select candidate).ToArray();
		}

		private static void MoveHudGroupRightOfStamina(Component hud, RectTransform staminaRect)
		{
			//IL_0042: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: 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_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: 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_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			_adjacentHudGroupRoots = GetAdjacentHudGroupRoots(hud, ((object)hud).GetType());
			if (_adjacentHudGroupRoots == null || _adjacentHudGroupRoots.Length == 0)
			{
				return;
			}
			Canvas.ForceUpdateCanvases();
			Canvas componentInParent = ((Component)_adjacentHudGroupRoots[0]).GetComponentInParent<Canvas>();
			Camera uiCamera = (((Object)(object)componentInParent != (Object)null && (int)componentInParent.rootCanvas.renderMode != 0) ? componentInParent.rootCanvas.worldCamera : null);
			Rect first = ScreenRect(_adjacentHudGroupRoots[0], uiCamera);
			foreach (RectTransform item in _adjacentHudGroupRoots.Skip(1))
			{
				Canvas componentInParent2 = ((Component)item).GetComponentInParent<Canvas>();
				Camera uiCamera2 = (((Object)(object)componentInParent2 != (Object)null && (int)componentInParent2.rootCanvas.renderMode != 0) ? componentInParent2.rootCanvas.worldCamera : null);
				first = Union(first, ScreenRect(item, uiCamera2));
			}
			Canvas componentInParent3 = ((Component)staminaRect).GetComponentInParent<Canvas>();
			Camera uiCamera3 = (((Object)(object)componentInParent3 != (Object)null && (int)componentInParent3.rootCanvas.renderMode != 0) ? componentInParent3.rootCanvas.worldCamera : null);
			Rect val = ScreenRect(staminaRect, uiCamera3);
			float num = ((Rect)(ref val)).xMax + 8f - ((Rect)(ref first)).xMin;
			RectTransform[] adjacentHudGroupRoots = _adjacentHudGroupRoots;
			Vector3 val7 = default(Vector3);
			Vector3 val8 = default(Vector3);
			foreach (RectTransform val2 in adjacentHudGroupRoots)
			{
				Canvas componentInParent4 = ((Component)val2).GetComponentInParent<Canvas>();
				Camera val3 = (((Object)(object)componentInParent4 != (Object)null && (int)componentInParent4.rootCanvas.renderMode != 0) ? componentInParent4.rootCanvas.worldCamera : null);
				Rect val4 = ScreenRect(val2, val3);
				Vector2 center = ((Rect)(ref val4)).center;
				Vector2 val5 = center + Vector2.right * num;
				Transform parent = ((Transform)val2).parent;
				RectTransform val6 = (RectTransform)(object)((parent is RectTransform) ? parent : null);
				if ((Object)(object)val6 != (Object)null && RectTransformUtility.ScreenPointToWorldPointInRectangle(val6, val5, val3, ref val7) && RectTransformUtility.ScreenPointToWorldPointInRectangle(val6, center, val3, ref val8))
				{
					((Transform)val2).position = ((Transform)val2).position + (val7 - val8);
				}
			}
		}

		private static Rect Union(Rect first, Rect second)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			return Rect.MinMaxRect(Mathf.Min(((Rect)(ref first)).xMin, ((Rect)(ref second)).xMin), Mathf.Min(((Rect)(ref first)).yMin, ((Rect)(ref second)).yMin), Mathf.Max(((Rect)(ref first)).xMax, ((Rect)(ref second)).xMax), Mathf.Max(((Rect)(ref first)).yMax, ((Rect)(ref second)).yMax));
		}

		internal static void KeepStaminaBesideHealth(Component hud)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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)
			if (!IsAppliedFor(hud))
			{
				return;
			}
			Type type = ((object)hud).GetType();
			RectTransform fieldComponent = HudLayout.GetFieldComponent<RectTransform>(hud, type, "m_healthBarRoot");
			RectTransform fieldComponent2 = HudLayout.GetFieldComponent<RectTransform>(hud, type, "m_staminaBar2Root");
			if (!((Object)(object)fieldComponent == (Object)null) && !((Object)(object)fieldComponent2 == (Object)null))
			{
				Transform parent = ((Transform)fieldComponent).parent;
				RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
				if (val != null)
				{
					fieldComponent2.anchorMin = val.anchorMin;
					fieldComponent2.anchorMax = val.anchorMax;
					fieldComponent2.pivot = fieldComponent.pivot;
					fieldComponent2.sizeDelta = fieldComponent.sizeDelta;
					((Transform)fieldComponent2).localRotation = ((Transform)fieldComponent).localRotation;
					((Transform)fieldComponent2).localScale = ((Transform)fieldComponent).localScale;
					PositionStaminaBesideHealth(fieldComponent, fieldComponent2, parent);
					MoveHudGroupRightOfStamina(hud, fieldComponent2);
				}
			}
		}

		private static void PositionStaminaBesideHealth(RectTransform healthRect, RectTransform staminaRect, Transform healthPanel)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			Canvas.ForceUpdateCanvases();
			Rect val = RectInParent(healthRect, healthPanel);
			Rect val2 = RectInParent(staminaRect, healthPanel);
			staminaRect.anchoredPosition += new Vector2(((Rect)(ref val)).xMax + 8f - ((Rect)(ref val2)).xMin, ((Rect)(ref val)).center.y - ((Rect)(ref val2)).center.y);
			staminaRect.ForceUpdateRectTransforms();
		}

		internal static void KeepStaminaVisible(Component hud)
		{
			Animator fieldComponent = HudLayout.GetFieldComponent<Animator>(hud, ((object)hud).GetType(), "m_staminaAnimator");
			if ((Object)(object)fieldComponent != (Object)null)
			{
				fieldComponent.SetBool("Visible", true);
			}
		}

		internal static void UpdateVirtualHealth(Component hud)
		{
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)hud == (Object)null)
			{
				return;
			}
			Transform fieldComponent = HudLayout.GetFieldComponent<Transform>(hud, ((object)hud).GetType(), "m_healthBarRoot");
			if ((Object)(object)fieldComponent == (Object)null)
			{
				return;
			}
			if ((Object)(object)_virtualHealthImage == (Object)null)
			{
				Transform val = fieldComponent.Find("fast/bar");
				Image val2 = (((Object)(object)val == (Object)null) ? null : ((Component)val).GetComponent<Image>());
				if ((Object)(object)val2 == (Object)null)
				{
					return;
				}
				GameObject val3 = new GameObject("VirtualHealth", new Type[2]
				{
					typeof(RectTransform),
					typeof(Image)
				});
				val3.transform.SetParent(fieldComponent, false);
				_virtualHealthImage = val3.GetComponent<Image>();
				CopyImage(val2, _virtualHealthImage, copyColor: false);
				((Graphic)_virtualHealthImage).color = new Color(1f, 0.55f, 0.1f, 0.9f);
				((Graphic)_virtualHealthImage).raycastTarget = false;
			}
			Transform obj = ((fieldComponent is RectTransform) ? fieldComponent : null);
			RectTransform rectTransform = ((Graphic)_virtualHealthImage).rectTransform;
			float maxHealth = ((Character)localPlayer).GetMaxHealth();
			float virtualHealth = VirtualHealthTracker.GetVirtualHealth();
			float health = ((Character)localPlayer).GetHealth();
			if ((Object)(object)obj == (Object)null || maxHealth <= 0f || virtualHealth <= 0f)
			{
				((Behaviour)_virtualHealthImage).enabled = false;
				return;
			}
			float num = Mathf.Clamp01(health / maxHealth);
			float num2 = Mathf.Clamp01((health + virtualHealth) / maxHealth);
			rectTransform.anchorMin = new Vector2(num, 0f);
			rectTransform.anchorMax = new Vector2(num2, 1f);
			rectTransform.offsetMin = Vector2.zero;
			rectTransform.offsetMax = Vector2.zero;
			((Behaviour)_virtualHealthImage).enabled = num2 > num;
		}

		private static void CopyHealthVisuals(Transform healthPanel, Transform healthRoot, Transform staminaVisual)
		{
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			CopyHealthVisual(healthPanel.Find("darken"), staminaVisual.Find("darken"));
			CopyHealthVisual(healthRoot.Find("border"), staminaVisual.Find("border"));
			CopyHealthVisual(healthRoot.Find("bkg"), staminaVisual.Find("bkg"));
			CopyHealthVisual(healthRoot.Find("slow"), staminaVisual.Find("stamina_slow"));
			CopyHealthVisual(healthRoot.Find("fast"), staminaVisual.Find("stamina_fast"));
			CopyHealthVisual(healthRoot.Find("slow/bar"), staminaVisual.Find("stamina_slow/bar"), copySize: false, copyColor: false);
			CopyHealthVisual(healthRoot.Find("fast/bar"), staminaVisual.Find("stamina_fast/bar"), copySize: false, copyColor: false);
			Transform obj = healthRoot.Find("slow/bar");
			RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			Transform obj2 = healthRoot.Find("fast/bar");
			RectTransform val2 = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null);
			Transform obj3 = staminaVisual.Find("stamina_slow/bar");
			RectTransform val3 = (RectTransform)(object)((obj3 is RectTransform) ? obj3 : null);
			Transform obj4 = staminaVisual.Find("stamina_fast/bar");
			RectTransform val4 = (RectTransform)(object)((obj4 is RectTransform) ? obj4 : null);
			Rect rect;
			if ((Object)(object)val != (Object)null && (Object)(object)val3 != (Object)null)
			{
				rect = val.rect;
				val3.SetSizeWithCurrentAnchors((Axis)1, ((Rect)(ref rect)).height);
			}
			if ((Object)(object)val2 != (Object)null && (Object)(object)val4 != (Object)null)
			{
				rect = val2.rect;
				val4.SetSizeWithCurrentAnchors((Axis)1, ((Rect)(ref rect)).height);
			}
		}

		private static void SyncStaminaBarWidths(Component hud, Type hudType)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if (GuiBarWidthField == null)
			{
				return;
			}
			Transform fieldComponent = HudLayout.GetFieldComponent<Transform>(hud, hudType, "m_staminaBar2Root");
			Transform obj = ((fieldComponent != null) ? fieldComponent.Find("Stamina/bkg") : null);
			RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			GuiBar fieldComponent2 = HudLayout.GetFieldComponent<GuiBar>(hud, hudType, "m_staminaBar2Slow");
			GuiBar fieldComponent3 = HudLayout.GetFieldComponent<GuiBar>(hud, hudType, "m_staminaBar2Fast");
			if (!((Object)(object)val == (Object)null))
			{
				Rect rect = val.rect;
				float width = ((Rect)(ref rect)).width;
				if ((Object)(object)fieldComponent2 != (Object)null)
				{
					fieldComponent2.SetWidth(width);
				}
				if ((Object)(object)fieldComponent3 != (Object)null)
				{
					fieldComponent3.SetWidth(width);
				}
			}
		}

		private static void CopyHealthVisual(Transform source, Transform target, bool copySize = true, bool copyColor = true)
		{
			//IL_0035: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)source == (Object)null || (Object)(object)target == (Object)null)
			{
				return;
			}
			RectTransform val = (RectTransform)(object)((source is RectTransform) ? source : null);
			RectTransform val2 = (RectTransform)(object)((target is RectTransform) ? target : null);
			if ((Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null)
			{
				val2.anchorMin = val.anchorMin;
				val2.anchorMax = val.anchorMax;
				val2.pivot = val.pivot;
				val2.anchoredPosition = val.anchoredPosition;
				((Transform)val2).localRotation = ((Transform)val).localRotation;
				if (copySize)
				{
					val2.sizeDelta = val.sizeDelta;
				}
			}
			Image component = ((Component)source).GetComponent<Image>();
			Image component2 = ((Component)target).GetComponent<Image>();
			CopyImage(component, component2, copyColor);
		}

		private static string DescribeRect(RectTransform rect)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)rect == (Object)null))
			{
				Rect rect2 = rect.rect;
				return $"size={((Rect)(ref rect2)).size}, delta={rect.sizeDelta}, pos={rect.anchoredPosition}, " + $"anchor=({rect.anchorMin.x:F2},{rect.anchorMin.y:F2})-({rect.anchorMax.x:F2},{rect.anchorMax.y:F2})";
			}
			return "missing";
		}

		private static void CopyImage(Image source, Image target, bool copyColor = true)
		{
			//IL_002d: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)source == (Object)null) && !((Object)(object)target == (Object)null))
			{
				target.sprite = source.sprite;
				((Graphic)target).material = ((Graphic)source).material;
				target.type = source.type;
				target.preserveAspect = source.preserveAspect;
				target.fillMethod = source.fillMethod;
				target.fillOrigin = source.fillOrigin;
				target.fillClockwise = source.fillClockwise;
				target.pixelsPerUnitMultiplier = source.pixelsPerUnitMultiplier;
				if (copyColor)
				{
					((Graphic)target).color = ((Graphic)source).color;
				}
			}
		}

		private static void CopyTextStyle(TMP_Text source, TMP_Text target)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			target.font = source.font;
			target.fontSharedMaterial = source.fontSharedMaterial;
			target.fontSize = source.fontSize;
			target.fontStyle = source.fontStyle;
			target.alignment = source.alignment;
			((Graphic)target).color = ((Graphic)source).color;
			target.enableAutoSizing = source.enableAutoSizing;
			target.fontSizeMin = source.fontSizeMin;
			target.fontSizeMax = source.fontSizeMax;
			target.characterSpacing = source.characterSpacing;
			target.wordSpacing = source.wordSpacing;
			target.lineSpacing = source.lineSpacing;
			target.outlineWidth = source.outlineWidth;
			target.outlineColor = source.outlineColor;
		}

		private static Rect RectInParent(RectTransform rect, Transform parent)
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			rect.GetWorldCorners(array);
			Vector3[] source = ((IEnumerable<Vector3>)array).Select((Func<Vector3, Vector3>)parent.InverseTransformPoint).ToArray();
			return Rect.MinMaxRect(source.Min((Vector3 corner) => corner.x), source.Min((Vector3 corner) => corner.y), source.Max((Vector3 corner) => corner.x), source.Max((Vector3 corner) => corner.y));
		}

		internal static T GetFieldComponent<T>(Component hud, Type hudType, string fieldName) where T : Component
		{
			object? obj = hudType.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(hud);
			return (T)((obj is T) ? obj : null);
		}

		private static string DescribeGuiBar(GuiBar bar)
		{
			if ((Object)(object)bar == (Object)null)
			{
				return "missing";
			}
			Transform obj = ((Component)bar).transform.Find("bar");
			RectTransform rect = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			return $"value={GuiBarValueField?.GetValue(bar)}, max={GuiBarMaxValueField?.GetValue(bar)}, " + $"smooth={GuiBarSmoothValueField?.GetValue(bar)}, width={GuiBarWidthField?.GetValue(bar)}, " + "fill=" + DescribeRect(rect);
		}
	}
	internal static class InventoryLayout
	{
		private sealed class DeathLoadoutEntry
		{
			internal Vector2i Position;

			internal string SharedName;

			internal ItemType ItemType;

			internal int Quality;

			internal int Variant;

			internal int WorldLevel;

			internal float Durability;

			internal long CrafterId;

			internal string CrafterName;

			internal int Stack;

			internal Dictionary<string, string> CustomData;
		}

		private sealed class NetworkAccessoryEntry
		{
			internal int Slot;

			internal string PrefabName;

			internal int Variant;

			internal int Quality;
		}

		[HarmonyPatch]
		private static class InventorySetHeightPatch
		{
			private static MethodBase TargetMethod()
			{
				return typeof(Inventory).GetMethod("SetHeight", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(int) }, null);
			}

			private static void Prefix(Inventory __instance)
			{
				if (IsCurrentPlayerInventory(__instance))
				{
					EnsureDedicatedStorageRow(__instance);
				}
			}

			private static void Postfix(Inventory __instance, int height)
			{
				if (IsCurrentPlayerInventory(__instance))
				{
					UpdateNativeInventoryHeight(__instance, height);
				}
			}
		}

		[HarmonyPatch]
		private static class GetButtonPosPatch
		{
			private static MethodBase TargetMethod()
			{
				return FindType("InventoryGrid")?.GetMethod("GetButtonPos", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}

			private static void Postfix(Component __instance, GameObject go, ref Vector2i __result)
			{
				//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)
				if (IsPlayerGrid(__instance))
				{
					int num = FindElementIndex(__instance, go);
					if (num >= 0)
					{
						int originalInventoryWidth = GetOriginalInventoryWidth(__instance);
						__result = new Vector2i(num % originalInventoryWidth, num / originalInventoryWidth);
					}
				}
			}
		}

		[HarmonyPatch]
		private static class GetElementPosPatch
		{
			private static MethodBase TargetMethod()
			{
				return FindType("InventoryGrid")?.GetMethod("GetElementPos", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}

			private static void Postfix(Component __instance, InventoryElement element, ref Vector2i __result)
			{
				//IL_0032: 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)
				if (IsPlayerGrid(__instance) && !((Object)(object)element == (Object)null))
				{
					int num = FindElementIndex(__instance, ((Component)element).gameObject);
					if (num >= 0)
					{
						int originalInventoryWidth = GetOriginalInventoryWidth(__instance);
						__result = new Vector2i(num % originalInventoryWidth, num / originalInventoryWidth);
					}
				}
			}
		}

		[HarmonyPatch]
		private static class InventoryGridDropItemPatch
		{
			private sealed class DropState
			{
				internal Vector2i SourcePosition;

				internal ItemData TargetItem;

				internal bool SourceWasSpecial;

				internal bool TargetWasSpecial;
			}

			private static MethodBase TargetMethod()
			{
				return typeof(InventoryGrid).GetMethod("DropItem", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[4]
				{
					typeof(Inventory),
					typeof(ItemData),
					typeof(int),
					typeof(Vector2i)
				}, null);
			}

			private static bool Prefix(InventoryGrid __instance, Inventory fromInventory, ItemData item, ref Vector2i pos, ref bool __result, ref DropState __state)
			{
				//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00da: Unknown result type (might be due to invalid IL or missing references)
				//IL_0229: Unknown result type (might be due to invalid IL or missing references)
				//IL_022e: Unknown result type (might be due to invalid IL or missing references)
				Inventory inventory = __instance.GetInventory();
				if (IsPlayerInventory(inventory) && IsArmorSlot(pos.x, pos.y) && !IsArmorClothing(item))
				{
					__result = false;
					return false;
				}
				if (IsPlayerInventory(inventory) && IsAccessorySlot(pos.x, pos.y) && !IsAccessoryItem(item))
				{
					__result = false;
					return false;
				}
				bool flag = IsPlayerInventory(fromInventory);
				ItemData val = ((inventory != null) ? inventory.GetItemAt(pos.x, pos.y) : null);
				if (flag && IsPlayerInventory(inventory) && IsAccessorySlot(pos.x, pos.y) && IsTrinketItem(item) && !IsAccessorySlot(item.m_gridPos.x, item.m_gridPos.y) && CountEnabledTrinkets(inventory) >= 2 && !IsTrinketItem(val))
				{
					if (!TryFindSecondTrinketSlot(inventory, out var position))
					{
						__result = false;
						return false;
					}
					pos = position;
					val = inventory.GetItemAt(pos.x, pos.y);
				}
				if (IsPlayerInventory(inventory) && (IsArmorSlot(pos.x, pos.y) || IsAccessorySlot(pos.x, pos.y)) && val != null && (!flag || (!IsArmorSlot(item.m_gridPos.x, item.m_gridPos.y) && !IsAccessorySlot(item.m_gridPos.x, item.m_gridPos.y))))
				{
					__state = new DropState
					{
						TargetItem = val,
						TargetWasSpecial = true
					};
					UnequipItemFromSpecialSlot(inventory, val);
				}
				bool flag2 = flag && IsArmorSlot(item.m_gridPos.x, item.m_gridPos.y);
				bool flag3 = flag && IsAccessorySlot(item.m_gridPos.x, item.m_gridPos.y);
				if (flag && !IsArmorSlot(pos.x, pos.y) && !IsAccessorySlot(pos.x, pos.y) && (IsArmorClothing(item) || IsAccessoryItem(item)))
				{
					UnequipSpecialItem((Humanoid)(object)Player.m_localPlayer, item);
				}
				if (!flag || (!flag2 && !flag3))
				{
					return true;
				}
				__state = new DropState
				{
					SourcePosition = item.m_gridPos,
					TargetItem = val,
					SourceWasSpecial = true
				};
				if (val != null && (!flag2 || !IsArmorClothing(val)) && (!flag3 || !IsAccessoryItem(val)))
				{
					__result = false;
					return false;
				}
				if ((flag2 && !IsArmorSlot(pos.x, pos.y)) || (flag3 && !IsAccessorySlot(pos.x, pos.y)))
				{
					UnequipSpecialItem((Humanoid)(object)Player.m_localPlayer, item);
				}
				return true;
			}

			private static void Postfix(InventoryGrid __instance, ItemData item, Vector2i pos, bool __result, DropState __state)
			{
				//IL_0031: 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_0044: 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)
				Inventory inventory = __instance.GetInventory();
				if (item == null || !IsPlayerInventory(inventory))
				{
					return;
				}
				if (!__result)
				{
					if (__state != null && __state.TargetWasSpecial)
					{
						EquipSpecialItem(inventory, __state.TargetItem);
					}
					return;
				}
				if (IsArmorSlot(pos.x, pos.y) || IsAccessorySlot(pos.x, pos.y))
				{
					EquipSpecialItem(inventory, item);
					return;
				}
				if (__state != null && __state.SourceWasSpecial)
				{
					UnequipSpecialItem((Humanoid)(object)Player.m_localPlayer, item);
				}
				if (__state != null && __state.SourceWasSpecial && __state.TargetItem != null && inventory.GetItemAt(__state.SourcePosition.x, __state.SourcePosition.y) == __state.TargetItem)
				{
					EquipSpecialItem(inventory, __state.TargetItem);
				}
			}
		}

		[HarmonyPatch]
		private static class PlayerUseItemPatch
		{
			private static MethodBase TargetMethod()
			{
				return typeof(Player).GetMethod("UseItem", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[3]
				{
					typeof(Inventory),
					typeof(ItemData),
					typeof(bool)
				}, null);
			}

			private static bool Prefix(Player __instance, Inventory inventory, ItemData item)
			{
				//IL_007e: 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)
				if ((Object)(object)__instance == (Object)null || !IsPlayerInventory(inventory) || item == null)
				{
					return true;
				}
				if (IsArmorClothing(item))
				{
					if (IsArmorSlot(item.m_gridPos.x, item.m_gridPos.y))
					{
						if (((Humanoid)__instance).IsItemEquiped(item))
						{
							ManuallyDisabledSpecialItems.Add(item);
							((Humanoid)__instance).UnequipItem(item, true);
							RefreshEquipmentState((Humanoid)(object)__instance);
							RefreshPlayerVisualEquipment(__instance);
						}
						else
						{
							EquipSpecialItem(inventory, item);
						}
						return false;
					}
					if (!TryFindArmorActivationSlot(inventory, item, out var position))
					{
						return false;
					}
					if (!MoveItemToSpecialSlot(inventory, item, position))
					{
						return false;
					}
					EquipSpecialItem(inventory, item);
					return false;
				}
				if (!IsAccessoryItem(item))
				{
					return true;
				}
				if (IsAccessorySlot(item.m_gridPos.x, item.m_gridPos.y))
				{
					HashSet<ItemData> independentEquippedItems = GetIndependentEquippedItems((Humanoid)(object)__instance, create: false);
					if ((independentEquippedItems != null && independentEquippedItems.Contains(item)) || item.m_equipped)
					{
						ManuallyDisabledSpecialItems.Add(item);
						StoreOrDropReplacedItem(inventory, item);
					}
					else
					{
						EquipSpecialItem(inventory, item);
					}
					return false;
				}
				if (!TryFindAccessoryActivationSlot(inventory, item, out var position2))
				{
					return false;
				}
				if (!MoveItemToSpecialSlot(inventory, item, position2))
				{
					return false;
				}
				EquipSpecialItem(inventory, item);
				return false;
			}
		}

		[HarmonyPatch]
		private static class InventoryGuiRightClickItemPatch
		{
			private static MethodBase TargetMethod()
			{
				return typeof(InventoryGui).GetMethod("OnRightClickItem", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[3]
				{
					typeof(InventoryGrid),
					typeof(ItemData),
					typeof(Vector2i)
				}, null);
			}

			private static bool Prefix(InventoryGrid grid, ItemData item, Vector2i pos)
			{
				//IL_0024: 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_0083: 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)
				if (!IsPlayerGrid((Component)(object)grid) || item == null)
				{
					return true;
				}
				Player localPlayer = Player.m_localPlayer;
				Inventory val = ((localPlayer != null) ? ((Humanoid)localPlayer).GetInventory() : null);
				if (val == null)
				{
					return true;
				}
				if (IsArmorSlot(pos.x, pos.y) && IsArmorClothing(item))
				{
					if (((Humanoid)Player.m_localPlayer).IsItemEquiped(item))
					{
						ManuallyDisabledSpecialItems.Add(item);
						((Humanoid)Player.m_localPlayer).UnequipItem(item, true);
						RefreshEquipmentState((Humanoid)(object)Player.m_localPlayer);
						RefreshPlayerVisualEquipment(Player.m_localPlayer);
					}
					else
					{
						EquipSpecialItem(val, item);
					}
					return false;
				}
				if (IsAccessorySlot(pos.x, pos.y) && IsAccessoryItem(item))
				{
					HashSet<ItemData> independentEquippedItems = GetIndependentEquippedItems((Humanoid)(object)Player.m_localPlayer, create: false);
					if ((independentEquippedItems != null && independentEquippedItems.Contains(item)) || item.m_equipped)
					{
						ManuallyDisabledSpecialItems.Add(item);
						UnequipIndependentAccessory((Humanoid)(object)Player.m_localPlayer, item);
					}
					else
					{
						EquipSpecialItem(val, item);
					}
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch]
		private static class InventoryGuiOnSelectedItemPatch
		{
			private sealed class SelectState
			{
				internal ItemData Item;

				internal bool SourceWasSpecial;
			}

			private static MethodBase TargetMethod()
			{
				Type nestedType = typeof(InventoryGrid).GetNestedType("Modifier", BindingFlags.Public | BindingFlags.NonPublic);
				return typeof(InventoryGui).GetMethod("OnSelectedItem", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[4]
				{
					typeof(InventoryGrid),
					typeof(ItemData),
					typeof(Vector2i),
					nestedType
				}, null);
			}

			private static void Prefix(InventoryGrid grid, ItemData item, ref SelectState __state)
			{
				if (IsPlayerInventory((grid != null) ? grid.GetInventory() : null) && item != null)
				{
					__state = new SelectState
					{
						Item = item,
						SourceWasSpecial = (IsArmorSlot(item.m_gridPos.x, item.m_gridPos.y) || IsAccessorySlot(item.m_gridPos.x, item.m_gridPos.y))
					};
				}
			}

			private static void Postfix(Vector2i pos, SelectState __state)
			{
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				if (__state != null && __state.SourceWasSpecial && __state.Item != null && !IsArmorSlot(pos.x, pos.y) && !IsAccessorySlot(pos.x, pos.y))
				{
					UnequipSpecialItem((Humanoid)(object)Player.m_localPlayer, __state.Item);
				}
			}
		}

		[HarmonyPatch]
		private static class HumanoidEquipItemPatch
		{
			private static MethodBase TargetMethod()
			{
				return typeof(Humanoid).GetMethod("EquipItem", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2]
				{
					typeof(ItemData),
					typeof(bool)
				}, null);
			}

			private static bool Prefix(Humanoid __instance, ItemData item, bool triggerEquipEffects, ref bool __result)
			{
				if (!(__instance is Player) || !IsPlayerInventory(__instance.GetInventory()) || !IsIndependentAccessoryItem(item))
				{
					return true;
				}
				if (!IsAccessorySlot(item.m_gridPos.x, item.m_gridPos.y))
				{
					item.m_equipped = false;
					__result = false;
					return false;
				}
				HashSet<ItemData> independentEquippedItems = GetIndependentEquippedItems(__instance, create: false);
				if (independentEquippedItems != null && independentEquippedItems.Contains(item))
				{
					__result = false;
					return false;
				}
				EquipIndependentAccessory(__instance, item);
				if (triggerEquipEffects)
				{
					HumanoidTriggerEquipEffectMethod?.Invoke(__instance, new object[1] { item });
				}
				__result = true;
				return false;
			}
		}

		[HarmonyPatch]
		private static class HumanoidUnequipItemPatch
		{
			private static MethodBase TargetMethod()
			{
				return typeof(Humanoid).GetMethod("UnequipItem", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2]
				{
					typeof(ItemData),
					typeof(bool)
				}, null);
			}

			private static bool Prefix(Humanoid __instance, ItemData item)
			{
				if (!(__instance is Player) || !IsPlayerInventory(__instance.GetInventory()) || !IsIndependentAccessoryItem(item))
				{
					return true;
				}
				UnequipIndependentAccessory(__instance, item);
				return false;
			}
		}

		[HarmonyPatch]
		private static class PlayerCreateTombStonePatch
		{
			private static MethodBase TargetMethod()
			{
				return FindMethod("Player", "CreateTombStone");
			}

			private static void Prefix(Player __instance)
			{
				CaptureDeathLoadout(__instance);
			}
		}

		[HarmonyPatch]
		private static class HumanoidUnequipAllItemsPatch
		{
			private static MethodBase TargetMethod()
			{
				return FindMethod("Humanoid", "UnequipAllItems");
			}

			private static void Postfix(Humanoid __instance)
			{
				Player val = (Player)(object)((__instance is Player) ? __instance : null);
				if (val != null)
				{
					UnequipIndependentItemsForDeath(val);
				}
			}
		}

		[HarmonyPatch]
		private static class InventoryChangedPatch
		{
			private static MethodBase TargetMethod()
			{
				return typeof(Inventory).GetMethod("Changed", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2]
				{
					typeof(bool),
					typeof(bool)
				}, null);
			}

			private static void Postfix(Inventory __instance)
			{
				if (IsPlayerInventory(__instance))
				{
					RestorePendingDeathLoadout();
				}
			}
		}

		[HarmonyPatch]
		private static class TombStoneTakeAllSuccessPatch
		{
			private static MethodBase TargetMethod()
			{
				return FindMethod("TombStone", "OnTakeAllSuccess");
			}

			private static void Postfix()
			{
				RestorePendingDeathLoadout();
			}
		}

		[HarmonyPatch]
		private static class HumanoidIsItemEquipedPatch
		{
			private static MethodBase TargetMethod()
			{
				return typeof(Humanoid).GetMethod("IsItemEquiped", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(ItemData) }, null);
			}

			private static bool Prefix(Humanoid __instance, ItemData item, ref bool __result)
			{
				if (IsIndependentAccessoryItem(item))
				{
					HashSet<ItemData> independentEquippedItems = GetIndependentEquippedItems(__instance, create: false);
					if (independentEquippedItems != null && independentEquippedItems.Contains(item))
					{
						__result = true;
						return false;
					}
				}
				return true;
			}
		}

		[HarmonyPatch]
		private static class HumanoidIsItemTypeEquipedPatch
		{
			private static MethodBase TargetMethod()
			{
				return typeof(Humanoid).GetMethod("IsItemTypeEquiped", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(ItemData) }, null);
			}

			private static bool Prefix(Humanoid __instance, ItemData item, ref bool __result)
			{
				if (!IsIndependentAccessoryItem(item))
				{
					return true;
				}
				HashSet<ItemData> independentEquippedItems = GetIndependentEquippedItems(__instance, create: false);
				if (independentEquippedItems == null)
				{
					return true;
				}
				foreach (ItemData item2 in independentEquippedItems)
				{
					if (item2?.m_shared != null && item2.m_shared.m_name == item.m_shared.m_name)
					{
						__result = true;
						return false;
					}
				}
				return true;
			}
		}

		[HarmonyPatch]
		private static class HumanoidUpdateEquipmentStatusEffectsPatch
		{
			private static MethodBase TargetMethod()
			{
				return FindMethod("Humanoid", "UpdateEquipmentStatusEffects");
			}

			private static void Postfix(Humanoid __instance)
			{
				HashSet<ItemData> independentEquippedItems = GetIndependentEquippedItems(__instance, create: false);
				if (independentEquippedItems == null)
				{
					return;
				}
				HashSet<int> hashSet = new HashSet<int>();
				Dictionary<int, ItemData> dictionary = new Dictionary<int, ItemData>();
				foreach (ItemData item in independentEquippedItems)
				{
					StatusEffect val = item?.m_shared?.m_equipStatusEffect;
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					if (IsDemisterItem(item) && ((object)val).GetType() == typeof(SE_Demister))
					{
						int num = item.m_gridPos.x - 4;
						if (num >= 0 && num < 4)
						{
							hashSet.Add(num);
							dictionary[num] = item;
						}
					}
					else if (!((Character)__instance).GetSEMan().HaveStatusEffect(val))
					{
						((Character)__instance).GetSEMan().AddStatusEffect(val, true, 0, 0f, (short)0);
					}
				}
				if (hashSet.Count > 0)
				{
					StatusEffect val2 = ((IEnumerable<StatusEffect>)ObjectDB.instance?.m_StatusEffects).FirstOrDefault((Func<StatusEffect, bool>)((StatusEffect effect) => ((object)effect)?.GetType() == typeof(SE_Demister)));
					if ((Object)(object)val2 != (Object)null)
					{
						((Character)__instance).GetSEMan().RemoveStatusEffect(val2, true);
					}
				}
				for (int num2 = 0; num2 < 4; num2++)
				{
					StatusEffect val3 = DemisterStatusEffects[num2];
					if ((Object)(object)val3 == (Object)null)
					{
						continue;
					}
					if (hashSet.Contains(num2))
					{
						if (!((Character)__instance).GetSEMan().HaveStatusEffect(val3))
						{
							((Character)__instance).GetSEMan().AddStatusEffect(val3, true, 0, 0f, (short)0);
						}
					}
					else if (((Character)__instance).GetSEMan().HaveStatusEffect(val3))
					{
						((Character)__instance).GetSEMan().RemoveStatusEffect(val3, true);
					}
				}
				RefreshDemisterCoverage(__instance, dictionary);
			}
		}

		[HarmonyPatch]
		private static class ObjectDBRegisterDemisterEffectsPatch
		{
			private static MethodBase TargetMethod()
			{
				return FindMethod("ObjectDB", "UpdateRegisters");
			}

			private static void Postfix(ObjectDB __instance)
			{
				//IL_0125: 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_013e: Unknown result type (might be due to invalid IL or missing references)
				//IL_016e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0173: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)DemisterStatusEffectDatabase == (Object)(object)__instance && DemisterStatusEffects.All((StatusEffect effect) => (Object)(object)effect != (Object)null && __instance.m_StatusEffects.Contains(effect)))
				{
					return;
				}
				if (StatusEffectNameHashField == null)
				{
					ManualLogSource logger = _logger;
					if (logger != null)
					{
						logger.LogError((object)"未找到 StatusEffect.m_nameHash,无法注册多冥火效果。");
					}
					return;
				}
				StatusEffect val = ((IEnumerable<StatusEffect>)__instance.m_StatusEffects).FirstOrDefault((Func<StatusEffect, bool>)((StatusEffect effect) => ((object)effect)?.GetType() == typeof(SE_Demister)));
				if ((Object)(object)val == (Object)null)
				{
					ManualLogSource logger2 = _logger;
					if (logger2 != null)
					{
						logger2.LogWarning((object)"未找到原版 SE_Demister,无法注册多冥火效果。");
					}
					return;
				}
				for (int num = 0; num < 4; num++)
				{
					string effectName = "MyFirstMod_SE_Demister_Slot" + (num + 1);
					StatusEffect val2 = ((IEnumerable<StatusEffect>)__instance.m_StatusEffects).FirstOrDefault((Func<StatusEffect, bool>)((StatusEffect candidate) => (Object)(object)candidate != (Object)null && ((Object)candidate).name == effectName));
					if ((Object)(object)val2 == (Object)null)
					{
						val2 = Object.Instantiate<StatusEffect>(val);
						((Object)val2).name = effectName;
						StatusEffectNameHashField.SetValue(val2, 0);
						SE_Demister val3 = (SE_Demister)val2;
						val3.m_noiseSpeed = 0.75f + (float)num * 0.17f;
						val3.m_offset = new Vector3((num % 2 == 0) ? (-0.65f) : 0.65f, 2f + (float)num * 0.12f, (num < 2) ? (-0.55f) : 0.55f);
						val3.m_offsetInterior = new Vector3((num % 2 == 0) ? (-0.65f) : 0.65f, 1.8f + (float)num * 0.12f, (num < 2) ? (-0.55f) : 0.55f);
						__instance.m_StatusEffects.Add(val2);
					}
					DemisterStatusEffects[num] = val2;
				}
				DemisterStatusEffectDatabase = __instance;
				ManualLogSource logger3 = _logger;
				if (logger3 != null)
				{
					logger3.LogInfo((object)"已注册 4 个冥火之光专用状态效果。");
				}
			}
		}

		[HarmonyPatch]
		private static class DemisterMovementPatch
		{
			private static MethodBase TargetMethod()
			{
				return typeof(SE_Demister).GetMethod("UpdateStatusEffect", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(float) }, null);
			}

			private static bool TryGetDemisterSlot(SE_Demister effect, out int slot)
			{
				slot = -1;
				if ((Object)(object)effect == (Object)null || string.IsNullOrEmpty(((Object)effect).name))
				{
					return false;
				}
				if (!((Object)effect).name.StartsWith("MyFirstMod_SE_Demister_Slot", StringComparison.Ordinal) || !int.TryParse(((Object)effect).name.Substring("MyFirstMod_SE_Demister_Slot".Length), out var result))
				{
					return false;
				}
				slot = result - 1;
				if (slot >= 0)
				{
					return slot < 4;
				}
				return false;
			}

			private static void Postfix(SE_Demister __instance, float dt)
			{
				//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_01ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
				if (!TryGetDemisterSlot(__instance, out var slot))
				{
					return;
				}
				if (DemisterDesiredRanges.TryGetValue(__instance, out var value) && (!DemisterAppliedRanges.TryGetValue(__instance, out var value2) || !Mathf.Approximately(value2, value)))
				{
					ApplyDemisterForceFieldRange(__instance, value);
				}
				if (!(dt <= 0f) && !(DemisterBallVelocityField == null) && DemisterBallVelocityField.GetValue(__instance) is Vector3 val)
				{
					float time = Time.time;
					Vector3 val2 = default(Vector3);
					switch (slot)
					{
					case 0:
						((Vector3)(ref val2))..ctor(Mathf.Sin(time * 0.71f) * 0.72f, Mathf.Cos(time * 1.17f) * 0.48f, Mathf.Sin(time * 1.53f) * 0.68f);
						break;
					case 1:
						((Vector3)(ref val2))..ctor(Mathf.Cos(time * 1.31f + 1.4f) * 0.58f, Mathf.Sin(time * 0.83f + 0.7f) * 0.72f, Mathf.Cos(time * 1.67f + 2.1f) * 0.44f);
						break;
					case 2:
						((Vector3)(ref val2))..ctor(Mathf.Sin(time * 1.47f + 2.8f) * 0.64f, Mathf.Cos(time * 0.63f + 1.9f) * 0.55f, Mathf.Sin(time * 1.09f + 0.4f) * 0.76f);
						break;
					default:
						((Vector3)(ref val2))..ctor(Mathf.Cos(time * 0.59f + 4.2f) * 0.76f, Mathf.Sin(time * 1.41f + 3.3f) * 0.46f, Mathf.Cos(time * 1.83f + 5.1f) * 0.62f);
						break;
					}
					Vector3 val3 = val + val2 * dt;
					DemisterBallVelocityField.SetValue(__instance, Vector3.ClampMagnitude(val3, __instance.m_ballMaxSpeed));
				}
			}
		}

		[HarmonyPatch]
		private static class HumanoidGetEquipmentWeightPatch
		{
			private static MethodBase TargetMethod()
			{
				return typeof(Humanoid).GetMethod("GetEquipmentWeight", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}

			private static void Postfix(Humanoid __instance, ref float __result)
			{
				HashSet<ItemData> independentEquippedItems = GetIndependentEquippedItems(__instance, create: false);
				if (independentEquippedItems == null)
				{
					return;
				}
				foreach (ItemData item in independentEquippedItems)
				{
					if (item?.m_shared != null)
					{
						__result += item.m_shared.m_weight;
					}
				}
			}
		}

		[HarmonyPatch]
		private static class PlayerUpdateModifiersPatch
		{
			private static MethodBase TargetMethod()
			{
				return FindMethod("Player", "UpdateModifiers");
			}

			private static void Postfix(Player __instance)
			{
				HashSet<ItemData> independentEquippedItems = GetIndependentEquippedItems((Humanoid)(object)__instance, create: false);
				float[] array = PlayerEquipmentModifierValuesField?.GetValue(__instance) as float[];
				FieldInfo[] array2 = PlayerEquipmentModifierSourceFieldsField?.GetValue(null) as FieldInfo[];
				if (independentEquippedItems == null || array == null)
				{
					return;
				}
				int num = ((array2 != null) ? Math.Min(array.Length, array2.Length) : 0);
				float num2 = 0f;
				foreach (ItemData item in independentEquippedItems)
				{
					if (item?.m_shared == null)
					{
						continue;
					}
					if (IsTrinketItem(item))
					{
						num2 = Math.Max(num2, item.m_shared.m_maxAdrenaline);
					}
					for (int i = 0; i < num; i++)
					{
						if (array2[i]?.GetValue(item.m_shared) is float num3)
						{
							array[i] += num3;
						}
					}
				}
				if (array.Length > 10)
				{
					array[10] += num2;
				}
			}
		}

		[HarmonyPatch]
		private static class PlayerAdrenalineTrinketActivationPatch
		{
			private sealed class ActivationState
			{
				internal float AdrenalineBefore;

				internal float MaxAdrenaline;

				internal bool PreserveFullAdrenaline;

				internal ItemData SelectedTrinket;

				internal bool ForceActivation;

				internal readonly List<ItemData> SuppressedTrinkets = new List<ItemData>();
			}

			private static MethodBase TargetMethod()
			{
				return FindMethod("Player", "AddAdrenaline");
			}

			private static void Prefix(Player __instance, float __0, out ActivationState __state)
			{
				__state = new ActivationState
				{
					AdrenalineBefore = __instance.GetAdrenaline(),
					MaxAdrenaline = ((Character)__instance).GetMaxAdrenaline()
				};
				Inventory inventory = ((Humanoid)__instance).GetInventory();
				HashSet<ItemData> independentEquippedItems = GetIndependentEquippedItems((Humanoid)(object)__instance, create: false);
				if (inventory == null || independentEquippedItems == null)
				{
					return;
				}
				int dedicatedStorageRow = GetDedicatedStorageRow(inventory);
				HashSet<ItemData> activatedAdrenalineTrinkets = GetActivatedAdrenalineTrinkets((Humanoid)(object)__instance, create: false);
				activatedAdrenalineTrinkets?.RemoveWhere((ItemData item) => (Object)(object)item?.m_shared?.m_fullAdrenalineSE == (Object)null || !((Character)__instance).GetSEMan().HaveStatusEffect(item.m_shared.m_fullAdrenalineSE));
				ItemData val = null;
				bool flag = false;
				for (int num = 4; num < 8 && num < inventory.GetWidth(); num++)
				{
					ItemData itemAt = inventory.GetItemAt(num, dedicatedStorageRow);
					if (IsTrinketItem(itemAt) && independentEquippedItems.Contains(itemAt) && itemAt.m_equipped && !((Object)(object)itemAt.m_shared.m_fullAdrenalineSE == (Object)null))
					{
						flag = true;
						if (val == null && (activatedAdrenalineTrinkets == null || !activatedAdrenalineTrinkets.Contains(itemAt)))
						{
							val = itemAt;
						}
					}
				}
				__state.PreserveFullAdrenaline = flag && val == null;
				__state.SelectedTrinket = val;
				if (val != null && __0 > 0f)
				{
					float maxAdrenaline = val.m_shared.m_maxAdrenaline;
					__state.ForceActivation = __state.AdrenalineBefore + __0 >= maxAdrenaline;
					if (__state.ForceActivation && PlayerAdrenalineField != null)
					{
						float num2 = Math.Max(0f, __state.MaxAdrenaline - __0);
						PlayerAdrenalineField.SetValue(__instance, num2);
					}
				}
				for (int num3 = 4; num3 < 8 && num3 < inventory.GetWidth(); num3++)
				{
					ItemData itemAt2 = inventory.GetItemAt(num3, dedicatedStorageRow);
					if (IsTrinketItem(itemAt2) && independentEquippedItems.Contains(itemAt2) && itemAt2.m_equipped && !((Object)(object)itemAt2.m_shared.m_fullAdrenalineSE == (Object)null) && itemAt2 != val)
					{
						itemAt2.m_equipped = false;
						__state.SuppressedTrinkets.Add(itemAt2);
					}
				}
			}

			private static void Postfix(Player __instance, float __0, ActivationState __state)
			{
				RestoreSuppressedTrinkets(__state);
				if (!(__0 <= 0f) && __instance.GetAdrenaline() == 0f)
				{
					if (__state.PreserveFullAdrenaline)
					{
						PlayerAdrenalineField?.SetValue(__instance, __state.MaxAdrenaline);
					}
					else if (__state.SelectedTrinket != null)
					{
						GetActivatedAdrenalineTrinkets((Humanoid)(object)__instance, create: true).Add(__state.SelectedTrinket);
					}
				}
			}

			private static Exception Finalizer(Exception __exception, ActivationState __state)
			{
				RestoreSuppressedTrinkets(__state);
				return __exception;
			}

			private static void RestoreSuppressedTrinkets(ActivationState state)
			{
				if (state == null)
				{
					return;
				}
				foreach (ItemData suppressedTrinket in state.SuppressedTrinkets)
				{
					suppressedTrinket.m_equipped = true;
				}
				state.SuppressedTrinkets.Clear();
			}
		}

		[HarmonyPatch]
		private static class PlayerEquipInventoryItemsPatch
		{
			private static MethodBase TargetMethod()
			{
				return typeof(Player).GetMethod("EquipInventoryItems", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}

			private static void Postfix(Player __instance)
			{
				Inventory inventory = ((__instance != null) ? ((Humanoid)__instance).GetInventory() : null);
				if (IsPlayerInventory(inventory))
				{
					ReconcileSpecialSlots(inventory);
					DisableOrdinarySpecialItems(inventory);
					EnableSpecialSlotItems(inventory);
					RefreshEquipmentState((Humanoid)(object)__instance);
					RefreshPlayerVisualEquipment(__instance);
				}
			}
		}

		[HarmonyPatch]
		private static class PlayerOnSpawnedPatch
		{
			private static MethodBase TargetMethod()
			{
				return typeof(Player).GetMethod("OnSpawned", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(bool) }, null);
			}

			private static void Postfix(Player __instance)
			{
				Inventory inventory = ((__instance != null) ? ((Humanoid)__instance).GetInventory() : null);
				if (IsPlayerInventory(inventory))
				{
					_reconciledInventory = null;
					EnsureDedicatedStorageRow(inventory);
					ReconcileSpecialSlots(inventory);
					DisableOrdinarySpecialItems(inventory);
					EnableSpecialSlotItems(inventory);
					RefreshEquipmentState((Humanoid)(object)__instance);
					RefreshPlayerVisualEquipment(__instance);
					PublishedNetworkStates.Remove(__instance);
					PublishNetworkEquipmentState(__instance);
				}
			}
		}

		[HarmonyPatch]
		private static class PlayerOnDestroyNetworkStatePatch
		{
			private static MethodBase TargetMethod()
			{
				return typeof(Player).GetMethod("OnDestroy", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null);
			}

			private static void Postfix(Player __instance)
			{
				ClearNetworkEquipmentState(__instance);
			}
		}

		[HarmonyPatch]
		private static class InventoryFindEmptySlotPatch
		{
			private static MethodBase TargetMethod()
			{
				return typeof(Inventory).GetMethod("FindEmptySlot", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(bool) }, null);
			}

			private static bool Prefix(Inventory __instance, bool topFirst, ref Vector2i __result)
			{
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				if (!IsPlayerInventory(__instance))
				{
					return true;
				}
				if (TryFindOrdinaryEmptySlot(__instance, topFirst, out var position))
				{
					__result = position;
					return false;
				}
				__result = new Vector2i(-1, -1);
				return false;
			}
		}

		[HarmonyPatch]
		private static class InventoryGridUpdateInventoryPatch
		{
			private static MethodBase TargetMethod()
			{
				return typeof(InventoryGrid).GetMethod("UpdateInventory", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[3]
				{
					typeof(Inventory),
					typeof(Player),
					typeof(ItemData)
				}, null);
			}

			private static void Prefix(Inventory inventory)
			{
				if (IsPlayerInventory(inventory))
				{
					EnsureDedicatedStorageRow(inventory);
				}
			}
		}

		[HarmonyPatch]
		private static class ItemDropCanPickupPatch
		{
			private static MethodBase TargetMethod()
			{
				return typeof(ItemDrop).GetMethod("CanPickup", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(bool) }, null);
			}

			private static bool Prefix(ItemDrop __instance, ref bool __result)
			{
				Player localPlayer = Player.m_localPlayer;
				Inventory val = ((localPlayer != null) ? ((Humanoid)localPlayer).GetInventory() : null);
				object? obj = ItemDropItemDataField?.GetValue(__instance);
				ItemData val2 = (ItemData)((obj is ItemData) ? obj : null);
				if (val == null || val2 == null || HasOrdinaryInventorySpace(val, val2))
				{
					return true;
				}
				__result = false;
				return false;
			}
		}

		[HarmonyPatch]
		private static class InventoryAddItemAtPositionPatch
		{
			private static MethodBase TargetMethod()
			{
				return typeof(Inventory).GetMethod("AddItem", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[5]
				{
					typeof(ItemData),
					typeof(int),
					typeof(int),
					typeof(int),
					typeof(bool)
				}, null);
			}

			private static bool Prefix(Inventory __instance, ItemData item, int x, int y, bool skipValidPositionCheck, ref bool __result)
			{
				if (skipValidPositionCheck || !IsPlayerInventory(__instance))
				{
					return true;
				}
				if (IsArmorSlot(x, y) && !IsArmorClothing(item))
				{
					__result = false;
					return false;
				}
				if (IsAccessorySlot(x, y) && !IsAccessoryItem(item))
				{
					__result = false;
					return false;
				}
				return true;
			}

			private static void Postfix(Inventory __instance, ItemData item, int x, int y, bool __result)
			{
				if (__result && IsPlayerInventory(__instance) && (IsArmorSlot(x, y) || IsAccessorySlot(x, y)))
				{
					EquipSpecialItem(__instance, item);
				}
			}
		}

		[HarmonyPatch]
		private static class UpdateGuiPatch
		{
			private static MethodBase TargetMethod()
			{
				return FindType("InventoryGrid")?.GetMethod("UpdateGui", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}

			private static void Postfix(Component __instance)
			{
				if (IsPlayerGrid(__instance))
				{
					if (!_diagnosticLogged && _logger != null)
					{
						_logger.LogInfo((object)"物品栏布局补丁已命中玩家 InventoryGrid.UpdateGui。将插入两行专用槽,并保留原版普通槽位行数。");
						_diagnosticLogged = true;
					}
					object? obj = InventoryField?.GetValue(__instance);
					object? inventory = ((obj is Inventory) ? obj : null);
					IsPlayerInventory((Inventory)inventory);
					int layoutHeight = GetLayoutHeight((Inventory)inventory);
					ReconcileSpecialSlots((Inventory)inventory);
					EnableSpecialSlotItems((Inventory)inventory);
					object? obj2 = GridRootField?.GetValue(__instance);
					RectTransform val = (RectTransform)((obj2 is RectTransform) ? obj2 : null);
					float num = ((ElementSpaceField?.GetValue(__instance) is float num2) ? num2 : 0f);
					if ((Object)(object)val != (Object)null && num > 0f)
					{
						RepositionElements(__instance, num);
						val.SetSizeWithCurrentAnchors((Axis)1, (float)layoutHeight * num);
						EnsureLabels(__instance, val, num);
					}
					ResizeInventoryPanel(layoutHeight);
				}
			}

			private static void ResizeInventoryPanel(int height)
			{
				//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_0097: Unknown result type (might be due to invalid IL or missing references)
				InventoryGui instance = InventoryGui.instance;
				if (!((Object)(object)instance == (Object)null))
				{
					object? obj = InventoryGuiPlayerField?.GetValue(instance);
					RectTransform val = (RectTransform)((obj is RectTransform) ? obj : null);
					if (!((Object)(object)val == (Object)null) && InventoryGuiPlayerHeightField?.GetValue(instance) is float num && InventoryGuiGridHeightField?.GetValue(instance) is float num2)
					{
						Vector2 sizeDelta = val.sizeDelta;
						sizeDelta.y = num + (float)(height - 4) * num2;
						val.sizeDelta = sizeDelta;
					}
				}
			}

			private static void EnsureLabels(Component grid, RectTransform gridRoot, float elementSpace)
			{
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
				if (!(ElementsField?.GetValue(grid) is IList { Count: not 0 } list))
				{
					return;
				}
				object? obj = list[0];
				InventoryElement val = (InventoryElement)((obj is InventoryElement) ? obj : null);
				if (!((Object)(object)val == (Object)null))
				{
					object? obj2 = InventoryElementAmountField?.GetValue(val);
					TMP_Text val2 = (TMP_Text)((obj2 is TMP_Text) ? obj2 : null);
					RectTransform val3 = ((val != null) ? val.GetElementRectTransform() : null);
					if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val3 == (Object)null))
					{
						Vector2 anchoredPosition = val3.anchoredPosition;
						_armorLabel = EnsureLabel(_armorLabel, GetEquipmentLabel("Armor & Clothing", "护甲服饰"), gridRoot, val2);
						_amuletLabel = EnsureLabel(_amuletLabel, GetEquipmentLabel("Accessories", "饰品护符"), gridRoot, val2);
						PositionLabel(_armorLabel, val3, anchoredPosition, elementSpace, 1);
						PositionLabel(_amuletLabel, val3, anchoredPosition, elementSpace, 2);
					}
				}
			}

			private static TMP_Text EnsureLabel(TMP_Text label, string text, RectTransform gridRoot, TMP_Text template)
			{
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_009c: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)label != (Object)null && (Object)(object)label.transform.parent != (Object)(object)gridRoot)
				{
					Object.Destroy((Object)(object)((Component)label).gameObject);
					label = null;
				}
				if ((Object)(object)label == (Object)null)
				{
					GameObject obj = Object.Instantiate<GameObject>(((Component)template).gameObject, (Transform)(object)gridRoot, false);
					((Object)obj).name = "MyFirstMod_" + text;
					label = obj.GetComponent<TMP_Text>();
				}
				if ((Object)(object)label != (Object)null)
				{
					((Component)label).gameObject.SetActive(true);
					((Behaviour)label).enabled = true;
					label.text = text;
					((Graphic)label).raycastTarget = false;
					label.alignment = (TextAlignmentOptions)4097;
					label.textWrappingMode = (TextWrappingModes)0;
					Color color = ((Graphic)label).color;
					((Graphic)label).color = new Color(color.r, color.g, color.b, 1f);
				}
				return label;
			}

			private static void PositionLabel(TMP_Text label, RectTransform templateRect, Vector2 origin, float elementSpace, int row)
			{
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)label == (Object)null) && !((Object)(object)templateRect == (Object)null))
				{
					RectTransform rectTransform = label.rectTransform;
					rectTransform.anchorMin = templateRect.anchorMin;
					rectTransform.anchorMax = templateRect.anchorMax;
					rectTransform.pivot = templateRect.pivot;
					((Transform)rectTransform).localScale = Vector3.one;
					((Transform)rectTransform).localRotation = Quaternion.identity;
					rectTransform.sizeDelta = new Vector2(elementSpace * 4f, elementSpace);
					rectTransform.anchoredPosition = origin + new Vector2(elementSpace * 4f, (0f - elementSpace) * (float)row);
				}
			}

			private static void RepositionElements(Component grid, float elementSpace)
			{
				//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_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_00a0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b6: 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)
				if (!(ElementsField?.GetValue(grid) is IList { Count: not 0 } list))
				{
					return;
				}
				object? obj = InventoryField?.GetValue(grid);
				Inventory val = (Inventory)((obj is Inventory) ? obj : null);
				if (val == null)
				{
					return;
				}
				object? obj2 = list[0];
				object? obj3 = ((obj2 is InventoryElement) ? obj2 : null);
				RectTransform val2 = ((obj3 != null) ? ((InventoryElement)obj3).GetElementRectTransform() : null);
				if ((Object)(object)val2 == (Object)null)
				{
					return;
				}
				Vector2 anchoredPosition = val2.anchoredPosition;
				for (int i = 0; i < list.Count; i++)
				{
					object? obj4 = list[i];
					object? obj5 = ((obj4 is InventoryElement) ? obj4 : null);
					RectTransform val3 = ((obj5 != null) ? ((InventoryElement)obj5).GetElementRectTransform() : null);
					if (!((Object)(object)val3 == (Object)null))
					{
						Vector2i layoutPosition = GetLayoutPosition(i, val);
						val3.anchoredPosition = anchoredPosition + new Vector2((float)layoutPosition.x * elementSpace, (float)(-layoutPosition.y) * elementSpace);
					}
				}
			}
		}

		private const int SlotsPerRow = 8;

		private const int DedicatedStorageRowCount = 1;

		private const int LegacyDedicatedStorageRow = 1;

		private static readonly FieldInfo InventoryField = FindField("InventoryGrid", "m_inventory");

		private static readonly FieldInfo ElementsField = FindField("InventoryGrid", "m_elements");

		private static readonly FieldInfo GridRootField = FindField("InventoryGrid", "m_gridRoot");

		private static readonly FieldInfo ElementSpaceField = FindField("InventoryGrid", "m_elementSpace");

		private static readonly FieldInfo InventoryGuiPlayerField = FindField("InventoryGui", "m_player");

		private static readonly FieldInfo InventoryGuiPlayerHeightField = FindField("InventoryGui", "m_playerHeight");

		private static readonly FieldInfo InventoryGuiGridHeightField = FindField("InventoryGui", "m_invGridHeight");

		private static readonly FieldInfo InventoryHeightField = FindField("Inventory", "m_height");

		private static readonly FieldInfo InventoryElementAmountField = FindField("InventoryElement", "m_amount");

		private static readonly FieldInfo HumanoidUtilityItemField = FindField("Humanoid", "m_utilityItem");

		private static readonly FieldInfo HumanoidTrinketItemField = FindField("Humanoid", "m_trinketItem");

		private static readonly FieldInfo PlayerEquipmentModifierValuesField = FindField("Player", "m_equipmentModifierValues");

		private static readonly FieldInfo PlayerEquipmentModifierSourceFieldsField = FindField("Player", "s_equipmentModifierSourceFields");

		private const int MaxAdrenalineModifierIndex = 10;

		private static readonly FieldInfo PlayerAdrenalineField = FindField("Player", "m_adrenaline");

		private static readonly MethodInfo HumanoidSetupEquipmentMethod = FindMethod("Humanoid", "SetupEquipment");

		private static readonly MethodInfo HumanoidTriggerEquipEffectMethod = FindMethod("Humanoid", "TriggerEquipEffect");

		private static readonly MethodInfo PlayerUpdateModifiersMethod = FindMethod("Player", "UpdateModifiers");

		private static readonly MethodInfo PlayerOnInventoryChangedMethod = FindMethod("Player", "OnInventoryChanged");

		private static readonly MethodInfo HumanoidGetVisEquipmentMethod = FindMethod("Humanoid", "GetVisEquipment");

		private static readonly MethodInfo PlayerSetupVisEquipmentMethod = FindMethod("Player", "SetupVisEquipment");

		private static readonly MethodInfo VisEquipmentUpdateVisualsMethod = FindMethod("VisEquipment", "UpdateVisuals");

		private static readonly MethodInfo InventoryGuiUpdateInventoryMethod = FindMethod("InventoryGui", "UpdateInventory");

		private static readonly FieldInfo ItemDropPrefabField = typeof(ItemData).GetField("m_dropPrefab", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		private static readonly FieldInfo ItemDropItemDataField = FindField("ItemDrop", "m_itemData");

		private static ManualLogSource _logger;

		private static bool _diagnosticLogged;

		private static TMP_Text _armorLabel;

		private static TMP_Text _amuletLabel;

		private static bool _languageChangeRegistered;

		private static readonly Dictionary<Inventory, int> NativeInventoryHeights = new Dictionary<Inventory, int>();

		private static Inventory _reconciledInventory;

		private static readonly Dictionary<Humanoid, HashSet<ItemData>> IndependentEquippedItems = new Dictionary<Humanoid, HashSet<ItemData>>();

		private static readonly Dictionary<Humanoid, List<ItemData>> DemisterEquipOrder = new Dictionary<Humanoid, List<ItemData>>();

		private static readonly Dictionary<Humanoid, HashSet<ItemData>> ActivatedAdrenalineTrinkets = new Dictionary<Humanoid, HashSet<ItemData>>();

		private static readonly HashSet<ItemData> ManuallyDisabledSpecialItems = new HashSet<ItemData>();

		private static readonly StatusEffect[] DemisterStatusEffects = (StatusEffect[])(object)new StatusEffect[4];

		private static ObjectDB DemisterStatusEffectDatabase;

		private static readonly FieldInfo StatusEffectNameHashField = FindField("StatusEffect", "m_nameHash");

		private static readonly FieldInfo DemisterBallVelocityField = FindField("SE_Demister", "m_ballVel");

		private static readonly FieldInfo DemisterBallInstanceField = FindField("SE_Demister", "m_ballInstance");

		private static readonly float[] DemisterCoverageRanges = new float[4] { 15f, 25.5f, 32.85f, 37.995f };

		private static readonly Dictionary<SE_Demister, float> DemisterDesiredRanges = new Dictionary<SE_Demister, float>();

		private static readonly Dictionary<SE_Demister, float> DemisterAppliedRanges = new Dictionary<SE_Demister, float>();

		private static readonly List<DeathLoadoutEntry> PendingDeathLoadout = new List<DeathLoadoutEntry>();

		private static Player PendingDeathLoadoutPlayer;

		private static bool _restoringDeathLoadout;

		private static float _deathLoadoutRetryTimer;

		private const int ArmorSlotCount = 4;

		private const int AccessoryFirstColumn = 4;

		private const int AccessorySlotCount = 4;

		private const int MaxEnabledTrinketCount = 2;

		private static readonly HashSet<string> ExtraAccessoryNames = new HashSet<string>(StringComparer.Ordinal) { "$item_wishbone", "$item_beltstrength", "$item_demister" };

		private const string NetworkSpecialEquipmentKey = "MyFirstMod_SpecialEquipment";

		private const byte NetworkSpecialEquipmentVersion = 1;

		private const float NetworkSyncInterval = 0.25f;

		private static float _networkSyncTimer;

		private static readonly Dictionary<Player, string> PublishedNetworkStates = new Dictionary<Player, string>();

		private static readonly Dictionary<Player, string> AppliedNetworkStates = new Dictionary<Player, string>();

		private static readonly Dictionary<Player, HashSet<ItemData>> RemoteNetworkItems = new Dictionary<Player, HashSet<ItemData>>();

		internal static void Initialize(ManualLogSource logger)
		{
			_logger = logger;
			if (!_languageChangeRegistered)
			{
				Localization.OnLanguageChange = (Action)Delegate.Combine(Localization.OnLanguageChange, new Action(UpdateEquipmentLabels));
				_languageChangeRegistered = true;
			}
		}

		internal static void Update()
		{
			if (PendingDeathLoadout.Count > 0)
			{
				_deathLoadoutRetryTimer += Time.unscaledDeltaTime;
				if (_deathLoadoutRetryTimer >= 0.25f)
				{
					_deathLoadoutRetryTimer = 0f;
					RestorePendingDeathLoadout();
				}
			}
			_networkSyncTimer += Time.unscaledDeltaTime;
			if (!(_networkSyncTimer < 0.25f))
			{
				_networkSyncTimer = 0f;
				UpdateNetworkEquipmentState();
			}
		}

		private static void UpdateEquipmentLabels()
		{
			if ((Object)(object)_armorLabel != (Object)null)
			{
				_armorLabel.text = GetEquipmentLabel("Armor & Clothing", "护甲服饰");
			}
			if ((Object)(object)_amuletLabel != (Object)null)
			{
				_amuletLabel.text = GetEquipmentLabel("Accessories", "饰品护符");
			}
		}

		private static string GetEquipmentLabel(string englishText, string chineseText)
		{
			Localization instance = Localization.instance;
			if (!string.Equals((instance != null) ? instance.GetSelectedLanguage() : null, "Chinese", StringComparison.OrdinalIgnoreCase))
			{
				return englishText;
			}
			return chineseText;
		}

		private static void UpdateNetworkEquipmentState()
		{
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer != (Object)null)
			{
				PublishNetworkEquipmentState(localPlayer);
			}
			List<Player> allPlayers = Player.GetAllPlayers();
			if (allPlayers == null)
			{
				return;
			}
			foreach (Player item in allPlayers)
			{
				if ((Object)(object)item == (Object)null || (Object)(object)item == (Object)(object)localPlayer)
				{
					continue;
				}
				ZNetView component = ((Component)item).GetComponent<ZNetView>();
				ZDO val = ((component != null) ? component.GetZDO() : null);
				if (val == null)
				{
					continue;
				}
				byte[] byteArray = val.GetByteArray("MyFirstMod_SpecialEquipment", (byte[])null);
				if (byteArray != null)
				{
					string text = Convert.ToBase64String(byteArray);
					if ((!AppliedNetworkStates.TryGetValue(item, out var value) || !string.Equals(value, text, StringComparison.Ordinal)) && TryReadNetworkEquipmentState(byteArray, out var entries) && ApplyRemoteNetworkEquipment(item, entries))
					{
						AppliedNetworkStates[item] = text;
					}
				}
			}
		}

		private static void PublishNetworkEquipmentState(Player player)
		{
			if (!IsPlayerInventory((player != null) ? ((Humanoid)player).GetInventory() : null))
			{
				return;
			}
			ZNetView component = ((Component)player).GetComponent<ZNetView>();
			ZDO val = ((component != null) ? component.GetZDO() : null);
			if (val != null && component.IsOwner())
			{
				byte[] array = BuildNetworkEquipmentState(player);
				string text = Convert.ToBase64String(array);
				if (!PublishedNetworkStates.TryGetValue(player, out var value) || !string.Equals(value, text, StringComparison.Ordinal))
				{
					val.Set("MyFirstMod_SpecialEquipment", array);
					PublishedNetworkStates[player] = text;
				}
			}
		}

		private static byte[] BuildNetworkEquipmentState(Player player)
		{
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Expected O, but got Unknown
			List<NetworkAccessoryEntry> list = new List<NetworkAccessoryEntry>();
			Inventory val = ((player != null) ? ((Humanoid)player).GetInventory() : null);
			HashSet<ItemData> independentEquippedItems = GetIndependentEquippedItems((Humanoid)(object)player, create: false);
			if (val != null && independentEquippedItems != null)
			{
				foreach (ItemData allItem in val.GetAllItems())
				{
					if (allItem != null && IsAccessorySlot(allItem.m_gridPos.x, allItem.m_gridPos.y) && IsAccessoryItem(allItem) && independentEquippedItems.Contains(allItem))
					{
						object? obj = ItemDropPrefabField?.GetValue(allItem);
						GameObject val2 = (GameObject)((obj is GameObject) ? obj : null);
						if (!((Object)(object)val2 == (Object)null))
						{
							list.Add(new NetworkAccessoryEntry
							{
								Slot = allItem.m_gridPos.x - 4,
								PrefabName = ((Object)val2).name,
								Variant = allItem.m_variant,
								Quality = allItem.m_quality
							});
						}
					}
				}
			}
			list = list.OrderBy((NetworkAccessoryEntry entry) => entry.Slot).ToList();
			ZPackage val3 = new ZPackage();
			val3.Write((byte)1);
			val3.Write((byte)Math.Min(list.Count, 4));
			foreach (NetworkAccessoryEntry item in list.Take(4))
			{
				val3.Write((byte)item.Slot);
				val3.Write(item.PrefabName ?? string.Empty);
				val3.Write(item.Variant);
				val3.Write(item.Quality);
			}
			return val3.GetArray();
		}

		private static bool TryReadNetworkEquipmentState(byte[] state, out List<NetworkAccessoryEntry> entries)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			entries = new List<NetworkAccessoryEntry>();
			if (state == null || state.Length == 0)
			{
				return false;
			}
			try
			{
				ZPackage val = new ZPackage(state);
				if (val.ReadByte() != 1)
				{
					return false;
				}
				int num = val.ReadByte();
				if (num < 0 || num > 4)
				{
					return false;
				}
				HashSet<int> hashSet = new HashSet<int>();
				for (int i = 0; i < num; i++)
				{
					int num2 = val.ReadByte();
					string text = val.ReadString();
					int variant = val.ReadInt();
					int quality = val.ReadInt();
					if (num2 < 0 || num2 >= 4 || !hashSet.Add(num2) || string.IsNullOrEmpty(text))
					{
						return false;
					}
					entries.Add(new NetworkAccessoryEntry
					{
						Slot = num2,
						PrefabName = text,
						Variant = variant,
						Quality = quality
					});
				}
				return true;
			}
			catch (Exception ex)
			{
				ManualLogSource logger = _logger;
				if (logger != null)
				{
					logger.LogWarning((object)("独立饰品网络快照解析失败: " + ex.GetType().Name));
				}
				return false;
			}
		}

		private static bool ApplyRemoteNetworkEquipment(Player player, List<NetworkAccessoryEntry> entries)
		{
			RemoveRemoteNetworkEquipment(player, refreshEquipment: true);
			HashSet<ItemData> independentEquippedItems = GetIndependentEquippedItems((Humanoid)(object)player, create: true);
			HashSet<ItemData> hashSet = new HashSet<ItemData>();
			RemoteNetworkItems[player] = hashSet;
			foreach (NetworkAccessoryEntry entry in entries)
			{
				ItemData val = CreateRemoteNetworkItem(entry);
				if (val == null)
				{
					RemoveRemoteNetworkEquipment(player, refreshEquipment: false);
					return false;
				}
				independentEquippedItems.Add(val);
				hashSet.Add(val);
				RecordDemisterEquip((Humanoid)(object)player, val);
			}
			HumanoidSetupEquipmentMethod?.Invoke(player, null);
			return true;
		}

		private static ItemData CreateRemoteNetworkItem(NetworkAccessoryEntry entry)
		{
			//IL_005f: 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)
			ObjectDB instance = ObjectDB.instance;
			GameObject obj = ((instance != null) ? instance.GetItemPrefab(entry.PrefabName) : null);
			ItemDrop obj2 = ((obj != null) ? obj.GetComponent<ItemDrop>() : null);
			object? obj3 = ItemDropItemDataField?.GetValue(obj2);
			object? obj4 = ((obj3 is ItemData) ? obj3 : null);
			ItemData val = ((obj4 != null) ? ((ItemData)obj4).Clone() : null);
			if (val == null || val.m_shared == null)
			{
				return null;
			}
			val.m_gridPos = new Vector2i(4 + entry.Slot, 0);
			val.m_variant = entry.Variant;
			val.m_quality = entry.Quality;
			val.m_equipped = true;
			return val;
		}

		private static void RemoveRemoteNetworkEquipment(Player player, bool refreshEquipment)
		{
			if (!RemoteNetworkItems.TryGetValue(player, out var value))
			{
				return;
			}
			HashSet<ItemData> independentEquippedItems = GetIndependentEquippedItems((Humanoid)(object)player, create: false);
			foreach (ItemData item in value)
			{
				independentEquippedItems?.Remove(item);
				ForgetDemisterEquip((Humanoid)(object)player, item);
				GetActivatedAdrenalineTrinkets((Humanoid)(object)player, create: false)?.Remove(item);
			}
			RemoteNetworkItems.Remove(player);
			if (independentEquippedItems != null && independentEquippedItems.Count == 0)
			{
				IndependentEquippedItems.Remove((Humanoid)(object)player);
			}
			if (refreshEquipment)
			{
				HumanoidSetupEquipmentMethod?.Invoke(player, null);
				RefreshDemisterCoverage((Humanoid)(object)player, new Dictionary<int, ItemData>());
			}
		}

		private static void ClearNetworkEquipmentState(Player player)
		{
			if (!((Object)(object)player == (Object)null))
			{
				RemoteNetworkItems.Remove(player);
				PublishedNetworkStates.Remove(player);
				AppliedNetworkStates.Remove(player);
				IndependentEquippedItems.Remove((Humanoid)(object)player);
				DemisterEquipOrder.Remove((Humanoid)(object)player);
				ActivatedAdrenalineTrinkets.Remove((Humanoid)(object)player);
			}
		}

		private static FieldInfo FindField(string typeName, string fiel