Decompiled source of CircletExtended v1.0.19

CircletExtended.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AzuExtendedPlayerInventory;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using ExtraSlotsAPI;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using ServerSync;
using TMPro;
using UnityEngine;

[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: Guid("01429425-f577-46f2-bba7-6faf98d54110")]
[assembly: ComVisible(false)]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyProduct("CircletExtended")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyTitle("CircletExtended")]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[<7a51c868-c999-499a-9cc8-d7fbd64a70fc>Embedded]
	internal sealed class <7a51c868-c999-499a-9cc8-d7fbd64a70fc>EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[<7a51c868-c999-499a-9cc8-d7fbd64a70fc>Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class <3bc42957-5b01-49c9-a099-7de2bdf94cbc>NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public <3bc42957-5b01-49c9-a099-7de2bdf94cbc>NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public <3bc42957-5b01-49c9-a099-7de2bdf94cbc>NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[<7a51c868-c999-499a-9cc8-d7fbd64a70fc>Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class <24af0362-d3e2-4b19-9f69-d307c048a969>NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public <24af0362-d3e2-4b19-9f69-d307c048a969>NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
internal class CustomPrefabs
{
	[HarmonyPatch(typeof(ZNetView), "Awake")]
	public static class ZNetView_Awake_AddPrefab
	{
		[HarmonyPriority(800)]
		private static bool Prefix()
		{
			return !prefabInit;
		}
	}

	[HarmonyPatch(typeof(ZSyncTransform), "Awake")]
	public static class ZSyncTransform_Awake_AddPrefab
	{
		[HarmonyPriority(800)]
		private static bool Prefix()
		{
			return !prefabInit;
		}
	}

	[HarmonyPatch(typeof(ZSyncTransform), "OnEnable")]
	public static class ZSyncTransform_OnEnable_AddPrefab
	{
		[HarmonyPriority(800)]
		private static bool Prefix()
		{
			return !prefabInit;
		}
	}

	[HarmonyPatch(typeof(ItemDrop), "Awake")]
	public static class ItemDrop_Awake_AddPrefab
	{
		[HarmonyPriority(800)]
		private static bool Prefix()
		{
			return !prefabInit;
		}
	}

	[HarmonyPatch(typeof(ItemDrop), "Start")]
	public static class ItemDrop_Start_AddPrefab
	{
		[HarmonyPriority(800)]
		private static bool Prefix()
		{
			return !prefabInit;
		}
	}

	[HarmonyPatch(typeof(Piece), "Awake")]
	public static class Piece_Awake_AddPrefab
	{
		[HarmonyPriority(800)]
		private static bool Prefix()
		{
			return !prefabInit;
		}
	}

	[HarmonyPatch(typeof(WearNTear), "Awake")]
	public static class WearNTear_Awake_AddPrefab
	{
		[HarmonyPriority(800)]
		private static bool Prefix()
		{
			return !prefabInit;
		}
	}

	[HarmonyPatch(typeof(WearNTear), "Start")]
	public static class WearNTear_Start_AddPrefab
	{
		[HarmonyPriority(800)]
		private static bool Prefix()
		{
			return !prefabInit;
		}
	}

	[HarmonyPatch(typeof(GuidePoint), "Start")]
	public static class GuidePoint_Start_AddPrefab
	{
		[HarmonyPriority(800)]
		private static bool Prefix()
		{
			return !prefabInit;
		}
	}

	private const string c_rootObjectName = "_shudnalRoot";

	private const string c_rootPrefabsName = "Prefabs";

	private static GameObject rootObject;

	private static GameObject rootPrefabs;

	public static bool prefabInit;

	private static void InitRootObject()
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_008c: Expected O, but got Unknown
		if ((Object)(object)rootObject == (Object)null)
		{
			rootObject = (GameObject)(((object)GameObject.Find("_shudnalRoot")) ?? ((object)new GameObject("_shudnalRoot")));
		}
		Object.DontDestroyOnLoad((Object)(object)rootObject);
		if ((Object)(object)rootPrefabs == (Object)null)
		{
			Transform obj = rootObject.transform.Find("Prefabs");
			rootPrefabs = ((obj != null) ? ((Component)obj).gameObject : null);
			if ((Object)(object)rootPrefabs == (Object)null)
			{
				rootPrefabs = new GameObject("Prefabs");
				rootPrefabs.transform.SetParent(rootObject.transform, false);
				rootPrefabs.SetActive(false);
			}
		}
	}

	internal static GameObject InitPrefabClone(GameObject prefabToClone, string prefabName)
	{
		InitRootObject();
		if ((Object)(object)rootPrefabs.transform.Find(prefabName) != (Object)null)
		{
			return ((Component)rootPrefabs.transform.Find(prefabName)).gameObject;
		}
		prefabInit = true;
		GameObject val = Object.Instantiate<GameObject>(prefabToClone, rootPrefabs.transform, false);
		prefabInit = false;
		((Object)val).name = prefabName;
		return val;
	}

	internal static Component AddComponent(GameObject gameObject, Type type)
	{
		prefabInit = true;
		Component result = gameObject.AddComponent(type);
		prefabInit = false;
		return result;
	}
}
namespace CircletExtended
{
	[Serializable]
	public class HumanoidHelmetCirclet
	{
		public ItemData circlet;

		public HumanoidHelmetCirclet()
		{
			circlet = null;
		}
	}
	public static class HumanoidExtension
	{
		[HarmonyPatch(typeof(Humanoid), "SetupVisEquipment")]
		public static class Humanoid_SetupVisEquipment_CustomItemType
		{
			private static void Postfix(Humanoid __instance, VisEquipment visEq)
			{
				if (CircletExtended.modEnabled.Value && CircletExtended.enablePutOnTop.Value)
				{
					ItemData circlet = __instance.GetCirclet();
					if (CircletExtended.equipCircletUnderHelmet.Value)
					{
						visEq.SetCircletItem((circlet != null) ? ((Object)circlet.m_dropPrefab).name : "");
						return;
					}
					string helmetItem = ((circlet != null) ? ((Object)circlet.m_dropPrefab).name : ((__instance.m_helmetItem != null) ? ((Object)__instance.m_helmetItem.m_dropPrefab).name : ""));
					visEq.SetHelmetItem(helmetItem);
				}
			}
		}

		[HarmonyPatch(typeof(Humanoid), "GetEquipmentWeight")]
		public static class Humanoid_GetEquipmentWeight_CustomItemType
		{
			private static void Postfix(Humanoid __instance, ref float __result)
			{
				if (CircletExtended.modEnabled.Value && CircletExtended.enablePutOnTop.Value)
				{
					ItemData circlet = __instance.GetCirclet();
					if (circlet != null)
					{
						__result += circlet.m_shared.m_weight;
					}
				}
			}
		}

		private static readonly ConditionalWeakTable<Humanoid, HumanoidHelmetCirclet> data = new ConditionalWeakTable<Humanoid, HumanoidHelmetCirclet>();

		public static HumanoidHelmetCirclet GetCircletData(this Humanoid humanoid)
		{
			return data.GetOrCreateValue(humanoid);
		}

		public static ItemData GetCirclet(this Humanoid humanoid)
		{
			return humanoid.GetCircletData().circlet;
		}

		public static ItemData SetCirclet(this Humanoid humanoid, ItemData item)
		{
			return humanoid.GetCircletData().circlet = item;
		}
	}
	[Serializable]
	public class VisEquipmentCirclet
	{
		public string m_circletItem = "";

		public GameObject m_circletItemInstance;

		public int m_currentCircletItemHash = 0;

		public bool m_showCirclet = true;

		public static readonly int s_circletItem = StringExtensionMethods.GetStableHashCode("CircletItem");
	}
	public static class VisEquipmentExtension
	{
		[HarmonyPatch(typeof(VisEquipment), "UpdateEquipmentVisuals")]
		public static class VisEquipment_UpdateEquipmentVisuals_CustomItemType
		{
			private static void Prefix(VisEquipment __instance)
			{
				int hash = 0;
				ZDO zDO = __instance.m_nview.GetZDO();
				if (zDO != null)
				{
					hash = zDO.GetInt(VisEquipmentCirclet.s_circletItem, 0);
				}
				else
				{
					VisEquipmentCirclet circletData = __instance.GetCircletData();
					if (!string.IsNullOrEmpty(circletData.m_circletItem))
					{
						hash = StringExtensionMethods.GetStableHashCode(circletData.m_circletItem);
					}
				}
				if (__instance.SetCircletEquipped(hash))
				{
					__instance.UpdateLodgroup();
				}
			}
		}

		[HarmonyPatch(typeof(VisEquipment), "UpdateLodgroup")]
		public static class VisEquipment_UpdateLodgroup_CustomItemType
		{
			private static void Prefix(VisEquipment __instance)
			{
				if (!CircletExtended.modEnabled.Value || !CircletExtended.enablePutOnTop.Value || (Object)(object)__instance.m_lodGroup == (Object)null)
				{
					return;
				}
				VisEquipmentCirclet circletData = __instance.GetCircletData();
				if (Object.op_Implicit((Object)(object)circletData.m_circletItemInstance))
				{
					bool flag = __instance.m_currentHelmetItemHash == 0 || CircletExtended.equipWithHelmetsList.Contains(__instance.m_currentHelmetItemHash) || CircletExtended.equipWithHelmetsList.Contains(CircletExtended.allHelmetsHash);
					if (circletData.m_showCirclet != flag)
					{
						((Component)circletData.m_circletItemInstance.transform.Find("bronzehelmet")).gameObject.SetActive(flag);
						circletData.m_showCirclet = flag;
					}
				}
			}
		}

		private static readonly ConditionalWeakTable<VisEquipment, VisEquipmentCirclet> data = new ConditionalWeakTable<VisEquipment, VisEquipmentCirclet>();

		public static VisEquipmentCirclet GetCircletData(this VisEquipment visEquipment)
		{
			return data.GetOrCreateValue(visEquipment);
		}

		public static void SetCircletItem(this VisEquipment visEquipment, string name)
		{
			VisEquipmentCirclet circletData = visEquipment.GetCircletData();
			if (!(circletData.m_circletItem == name))
			{
				circletData.m_circletItem = name;
				if (visEquipment.m_nview.GetZDO() != null && visEquipment.m_nview.IsOwner())
				{
					visEquipment.m_nview.GetZDO().Set(VisEquipmentCirclet.s_circletItem, (!string.IsNullOrEmpty(name)) ? StringExtensionMethods.GetStableHashCode(name) : 0, false);
				}
			}
		}

		public static bool SetCircletEquipped(this VisEquipment visEquipment, int hash)
		{
			VisEquipmentCirclet circletData = visEquipment.GetCircletData();
			if (circletData.m_currentCircletItemHash == hash)
			{
				return false;
			}
			if (Object.op_Implicit((Object)(object)circletData.m_circletItemInstance))
			{
				Object.Destroy((Object)(object)circletData.m_circletItemInstance);
				circletData.m_circletItemInstance = null;
			}
			circletData.m_currentCircletItemHash = hash;
			if (hash != 0)
			{
				circletData.m_circletItemInstance = visEquipment.AttachItem(hash, 0, visEquipment.m_helmet, true, false);
			}
			circletData.m_showCirclet = true;
			return true;
		}
	}
	internal static class CustomItemType
	{
		[HarmonyPatch(typeof(Humanoid), "EquipItem")]
		public static class Humanoid_EquipItem_CircletOnTop
		{
			private static void Postfix(Humanoid __instance, ItemData item, ref bool __result, bool triggerEquipEffects)
			{
				if (!CircletExtended.modEnabled.Value || !CircletExtended.enablePutOnTop.Value)
				{
					return;
				}
				if (CircletItem.IsCircletItem(__instance.m_helmetItem))
				{
					CircletExtended.LogInfo("Unequipping circlet on circlet equipment");
					__instance.UnequipItem(__instance.GetCirclet(), triggerEquipEffects);
				}
				else if (CircletItem.IsCircletItem(item))
				{
					bool flag = __instance.GetCirclet() != null;
					__instance.UnequipItem(__instance.GetCirclet(), triggerEquipEffects);
					if (flag)
					{
						__instance.m_visEquipment.UpdateEquipmentVisuals();
					}
					__instance.SetCirclet(item);
					if (__instance.IsItemEquiped(item))
					{
						item.m_equipped = true;
						__result = true;
					}
					__instance.SetupEquipment();
					if (triggerEquipEffects)
					{
						__instance.TriggerEquipEffect(item);
					}
				}
			}
		}

		[HarmonyPatch(typeof(Humanoid), "UnequipItem")]
		public static class Humanoid_UnequipItem_CircletOnTop
		{
			private static void Postfix(Humanoid __instance, ItemData item, bool triggerEquipEffects)
			{
				if (CircletExtended.modEnabled.Value && CircletExtended.enablePutOnTop.Value && CircletItem.IsCircletItem(item) && __instance.GetCirclet() == item)
				{
					__instance.SetCirclet(null);
					__instance.SetupEquipment();
				}
			}
		}

		[HarmonyPatch(typeof(Humanoid), "UnequipAllItems")]
		public class Humanoid_UnequipAllItems_CircletOnTop
		{
			public static void Postfix(Humanoid __instance)
			{
				if (CircletExtended.modEnabled.Value && CircletExtended.enablePutOnTop.Value)
				{
					__instance.UnequipItem(__instance.GetCirclet(), false);
				}
			}
		}

		[HarmonyPatch(typeof(Humanoid), "IsItemEquiped")]
		public static class Humanoid_IsItemEquiped_CircletOnTop
		{
			private static void Postfix(Humanoid __instance, ItemData item, ref bool __result)
			{
				if (CircletExtended.modEnabled.Value && CircletExtended.enablePutOnTop.Value && CircletItem.IsCircletItem(item))
				{
					__result = __result || __instance.GetCirclet() == item;
				}
			}
		}

		[HarmonyPatch(typeof(ItemData), "IsEquipable")]
		public static class ItemDropItemData_IsEquipable_CircletOnTop
		{
			private static void Postfix(ItemData __instance, ref bool __result)
			{
				if (CircletExtended.modEnabled.Value && CircletExtended.enablePutOnTop.Value)
				{
					__result = __result || CircletItem.IsCircletType(__instance);
				}
			}
		}

		[HarmonyPatch(typeof(Inventory), "Changed")]
		public static class Inventory_Changed_CustomItemType
		{
			private static void Prefix(Inventory __instance)
			{
				Player localPlayer = Player.m_localPlayer;
				if (__instance == ((localPlayer != null) ? ((Humanoid)localPlayer).GetInventory() : null) && ((Humanoid)(object)Player.m_localPlayer).GetCirclet() != null && !__instance.ContainsItem(((Humanoid)(object)Player.m_localPlayer).GetCirclet()))
				{
					((Humanoid)(object)Player.m_localPlayer).SetCirclet(null);
					((Humanoid)Player.m_localPlayer).SetupEquipment();
				}
			}
		}

		[HarmonyPatch(typeof(ItemStand), "Awake")]
		public static class ItemStand_Awake_CircletOnTop
		{
			private static void Postfix(ItemStand __instance)
			{
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0068: Unknown result type (might be due to invalid IL or missing references)
				if (CircletExtended.modEnabled.Value && CircletExtended.enablePutOnTop.Value && CircletExtended.visualStateItemStand.Value && __instance.m_supportedTypes.Contains((ItemType)6) && !__instance.m_supportedTypes.Contains(CircletItem.GetItemType()))
				{
					__instance.m_supportedTypes.Add(CircletItem.GetItemType());
				}
			}
		}

		[HarmonyPatch(typeof(ArmorStand), "Awake")]
		public static class ArmorStand_Awake_CircletOnTop
		{
			private static void Postfix(ArmorStand __instance)
			{
				if (CircletExtended.modEnabled.Value && CircletExtended.enablePutOnTop.Value && CircletExtended.visualStateArmorStand.Value)
				{
					CollectionExtensions.Do<ArmorStandSlot>(__instance.m_slots.Where((ArmorStandSlot x) => (int)x.m_slot == 6 && x.m_supportedTypes.Contains((ItemType)6) && !x.m_supportedTypes.Contains(CircletItem.GetItemType())), (Action<ArmorStandSlot>)delegate(ArmorStandSlot x)
					{
						//IL_0006: Unknown result type (might be due to invalid IL or missing references)
						x.m_supportedTypes.Add(CircletItem.GetItemType());
					});
				}
			}
		}
	}
	[BepInIncompatibility("Azumatt.CircletDemister")]
	[BepInIncompatibility("randyknapp.mods.dvergercolor")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("shudnal.CircletExtended", "Circlet Extended", "1.0.19")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class CircletExtended : BaseUnityPlugin
	{
		private const string pluginID = "shudnal.CircletExtended";

		private const string pluginName = "Circlet Extended";

		private const string pluginVersion = "1.0.19";

		private readonly Harmony harmony = new Harmony("shudnal.CircletExtended");

		internal static readonly ConfigSync configSync = new ConfigSync("shudnal.CircletExtended")
		{
			DisplayName = "Circlet Extended",
			CurrentVersion = "1.0.19",
			MinimumRequiredVersion = "1.0.19"
		};

		public static ConfigEntry<bool> modEnabled;

		private static ConfigEntry<bool> configLocked;

		private static ConfigEntry<bool> loggingEnabled;

		public static ConfigEntry<bool> equipCircletUnderHelmet;

		public static ConfigEntry<string> equipCircletWithHelmet;

		public static ConfigEntry<int> itemSlotType;

		public static ConfigEntry<bool> itemSlotAzuEPI;

		public static ConfigEntry<string> itemSlotNameAzuEPI;

		public static ConfigEntry<int> itemSlotIndexAzuEPI;

		public static ConfigEntry<bool> itemSlotExtraSlots;

		public static ConfigEntry<string> itemSlotNameExtraSlots;

		public static ConfigEntry<int> itemSlotIndexExtraSlots;

		public static ConfigEntry<bool> itemSlotExtraSlotsDiscovery;

		public static ConfigEntry<bool> getFeaturesByUpgrade;

		public static ConfigEntry<int> overloadChargesPerLevel;

		public static ConfigEntry<bool> enableOverload;

		public static ConfigEntry<bool> enableDemister;

		public static ConfigEntry<bool> enablePutOnTop;

		public static ConfigEntry<int> fuelMinutes;

		public static ConfigEntry<int> fuelPerLevel;

		public static ConfigEntry<Color> circletColor;

		public static ConfigEntry<bool> disableOnSleep;

		public static ConfigEntry<bool> enableShadows;

		public static ConfigEntry<bool> enableOverloadDemister;

		public static ConfigEntry<float> overloadDemisterRange;

		public static ConfigEntry<float> overloadDemisterTime;

		public static ConfigEntry<bool> visualStateItemDrop;

		public static ConfigEntry<bool> visualStateItemStand;

		public static ConfigEntry<bool> visualStateArmorStand;

		public static ConfigEntry<string> circletRecipeQuality1;

		public static ConfigEntry<string> circletRecipeQuality2;

		public static ConfigEntry<string> circletRecipeQuality3;

		public static ConfigEntry<string> circletRecipeQuality4;

		public static ConfigEntry<KeyboardShortcut> widenShortcut;

		public static ConfigEntry<KeyboardShortcut> narrowShortcut;

		public static ConfigEntry<KeyboardShortcut> toggleShortcut;

		public static ConfigEntry<KeyboardShortcut> toggleDemisterShortcut;

		public static ConfigEntry<KeyboardShortcut> increaseIntensityShortcut;

		public static ConfigEntry<KeyboardShortcut> decreaseIntensityShortcut;

		public static ConfigEntry<KeyboardShortcut> toggleShadowsShortcut;

		public static ConfigEntry<KeyboardShortcut> toggleSpotShortcut;

		public static ConfigEntry<KeyboardShortcut> overloadShortcut;

		public static ConfigEntry<int> maxSteps;

		public static ConfigEntry<float> minAngle;

		public static ConfigEntry<float> maxAngle;

		public static ConfigEntry<float> minIntensity;

		public static ConfigEntry<float> maxIntensity;

		public static ConfigEntry<float> minRange;

		public static ConfigEntry<float> maxRange;

		public static ConfigEntry<float> pointIntensity;

		public static ConfigEntry<float> pointRange;

		public static ConfigEntry<int> maxSteps2;

		public static ConfigEntry<float> minAngle2;

		public static ConfigEntry<float> maxAngle2;

		public static ConfigEntry<float> minIntensity2;

		public static ConfigEntry<float> maxIntensity2;

		public static ConfigEntry<float> minRange2;

		public static ConfigEntry<float> maxRange2;

		public static ConfigEntry<float> pointIntensity2;

		public static ConfigEntry<float> pointRange2;

		public static ConfigEntry<int> maxSteps3;

		public static ConfigEntry<float> minAngle3;

		public static ConfigEntry<float> maxAngle3;

		public static ConfigEntry<float> minIntensity3;

		public static ConfigEntry<float> maxIntensity3;

		public static ConfigEntry<float> minRange3;

		public static ConfigEntry<float> maxRange3;

		public static ConfigEntry<float> pointIntensity3;

		public static ConfigEntry<float> pointRange3;

		public static ConfigEntry<int> maxSteps4;

		public static ConfigEntry<float> minAngle4;

		public static ConfigEntry<float> maxAngle4;

		public static ConfigEntry<float> minIntensity4;

		public static ConfigEntry<float> maxIntensity4;

		public static ConfigEntry<float> minRange4;

		public static ConfigEntry<float> maxRange4;

		public static ConfigEntry<float> pointIntensity4;

		public static ConfigEntry<float> pointRange4;

		internal static CircletExtended instance;

		public static List<int> hotkeys = new List<int>();

		public static Dictionary<int, Requirement[]> recipeRequirements = new Dictionary<int, Requirement[]>();

		public static HashSet<int> equipWithHelmetsList = new HashSet<int>();

		public static string customDataKey = "shudnal.CircletExtended.DvergerLightState";

		public static string allHelmetsString = "AllHelmets";

		public static int allHelmetsHash = StringExtensionMethods.GetStableHashCode(allHelmetsString);

		private void Awake()
		{
			harmony.PatchAll();
			instance = this;
			ConfigInit();
			configSync.AddLockingConfigEntry<bool>(configLocked);
			Game.isModded = true;
			if (itemSlotAzuEPI.Value && AzuExtendedPlayerInventory.API.IsLoaded())
			{
				AzuExtendedPlayerInventory.API.AddSlot(itemSlotNameAzuEPI.Value, [<24af0362-d3e2-4b19-9f69-d307c048a969>NullableContext(1)] [return: <3bc42957-5b01-49c9-a099-7de2bdf94cbc>Nullable(2)] (Player player) => ((Humanoid)(object)player).GetCirclet(), [<24af0362-d3e2-4b19-9f69-d307c048a969>NullableContext(1)] (ItemData item) => CircletItem.IsCircletItem(item), itemSlotIndexAzuEPI.Value);
			}
			if (!ExtraSlotsAPI.API.IsReady())
			{
				return;
			}
			if (itemSlotIndexExtraSlots.Value < 0)
			{
				ExtraSlotsAPI.API.AddSlotBefore("CircletExtended", () => itemSlotNameExtraSlots.Value, (ItemData item) => CircletItem.IsCircletItem(item), () => CircletItem.IsCircletSlotAvailable(), "HipLantern");
			}
			else
			{
				ExtraSlotsAPI.API.AddSlotWithIndex("CircletExtended", itemSlotIndexExtraSlots.Value, () => itemSlotNameExtraSlots.Value, (ItemData item) => CircletItem.IsCircletItem(item), () => CircletItem.IsCircletSlotAvailable());
			}
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
			instance = null;
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}

		public static void LogInfo(object data)
		{
			if (loggingEnabled.Value)
			{
				((BaseUnityPlugin)instance).Logger.LogInfo(data);
			}
		}

		public void ConfigInit()
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0605: Unknown result type (might be due to invalid IL or missing references)
			//IL_062f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0656: Unknown result type (might be due to invalid IL or missing references)
			//IL_0680: Unknown result type (might be due to invalid IL or missing references)
			//IL_06aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_06dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0710: Unknown result type (might be due to invalid IL or missing references)
			//IL_0743: Unknown result type (might be due to invalid IL or missing references)
			//IL_0776: Unknown result type (might be due to invalid IL or missing references)
			config("General", "NexusID", 2617, "Nexus mod ID for updates", synchronizedSetting: false);
			modEnabled = config("General", "Enabled", defaultValue: true, "Enable the mod.");
			configLocked = config("General", "Lock Configuration", defaultValue: true, "Configuration is locked and can be changed by server admins only.");
			loggingEnabled = config("General", "Logging enabled", defaultValue: false, "Enable logging. [Not Synced with Server]", synchronizedSetting: false);
			circletColor = config<Color>("Circlet", "Light color", new Color(1f, 0.9f, 0.75f, 1f), "Circlet beam light color. Changing this ingame will change current circlet color [Not Synced with Server]", synchronizedSetting: false);
			disableOnSleep = config("Circlet", "Disable when sleeping", defaultValue: true, "Turn off the light when sleeping. [Not Synced with Server]", synchronizedSetting: false);
			enableShadows = config("Circlet", "Enables shadows toggle", defaultValue: true, "Enables option to toggle circlet's light to emit shadows. Disable if it impacts your performance. [Not Synced with Server]", synchronizedSetting: false);
			getFeaturesByUpgrade = config("Circlet - Features", "Get features by circlet upgrade", defaultValue: true, "Get circlet features by upgrading it. If False all features are available by default.\nIf True the order of upgrades are \"Default\" -> \"Put on top\" -> \"Overload\" -> \"Demister\"");
			overloadChargesPerLevel = config("Circlet - Features", "Overload charges", 50, "How many overload charges is available. It is the fraction of durability being damaged on Overload use. x2 if upgrades are disabled or quality is maximum.");
			enableOverload = config("Circlet - Features", "Enable overload", defaultValue: true, "Enables overload. Press hotkey to blind opponents with a bright flash at the cost of some circlet durability");
			enableDemister = config("Circlet - Features", "Enable demister", defaultValue: true, "Enables demister. Press hotkey to spawn a little wisp to push away the mists");
			enablePutOnTop = config("Circlet - Features", "Enable put on top", defaultValue: true, "Enables equipping circlet on top of other helmet. Equip circlet without using a helmet slot.");
			getFeaturesByUpgrade.SettingChanged += delegate
			{
				CircletItem.PatchCircletItemOnConfigChange();
			};
			getFeaturesByUpgrade.SettingChanged += delegate
			{
				CircletItem.FillRecipe();
			};
			enablePutOnTop.SettingChanged += delegate
			{
				CircletItem.PatchCircletItemOnConfigChange();
			};
			fuelMinutes = config("Circlet - Fuel", "Basic fuel capacity", 360, "Time in minutes required to consume all fuel. Set to 0 to not consume fuel.");
			fuelPerLevel = config("Circlet - Fuel", "Fuel per level", 120, "Time in minutes added per quality level");
			fuelMinutes.SettingChanged += delegate
			{
				CircletItem.PatchCircletItemOnConfigChange();
			};
			fuelPerLevel.SettingChanged += delegate
			{
				CircletItem.PatchCircletItemOnConfigChange();
			};
			enableOverloadDemister = config("Circlet - Overload demister", "Enable temporary demister on overload", defaultValue: true, "Push away mist on overload activation");
			overloadDemisterRange = config("Circlet - Overload demister", "Range", 40f, "Maximum range");
			overloadDemisterTime = config("Circlet - Overload demister", "Time", 8f, "Time to gradually decrease effect radius");
			equipCircletUnderHelmet = config("Circlet - Put on top", "Equip under helmet", defaultValue: true, "If enabled - Circlet will be invisible if put on top of the helmet.\nIf disabled - Circlet will replace helmet");
			equipCircletWithHelmet = config("Circlet - Put on top", "Show when helmet equipped", "HelmetTrollLeather", "Comma separated list. If you have \"Equip under helmet\" enabled and wear a helmet from that list the Circlet will be shown.\nAdd identifier \"" + allHelmetsString + "\" to show circlet with every helmet equiped. Use that to test how it looks with different helmets.\nThere is only Troll Leather Helmet of Vanilla helmets that looks good with Circlet.");
			equipCircletWithHelmet.SettingChanged += delegate
			{
				FillHelmets();
			};
			circletRecipeQuality1 = config("Circlet - Recipe", "Create", "HelmetBronze:1,Ruby:1,SilverNecklace:1,SurtlingCore:10", "Recipe to create circet");
			circletRecipeQuality2 = config("Circlet - Recipe", "Upgrade quality 2", "Resin:20,LeatherScraps:10,IronNails:10,Chain:1", "Recipe to upgrade circet to quality 2");
			circletRecipeQuality3 = config("Circlet - Recipe", "Upgrade quality 3", "Thunderstone:5,Silver:1,JuteRed:2", "Recipe to upgrade circet to quality 3");
			circletRecipeQuality4 = config("Circlet - Recipe", "Upgrade quality 4", "Demister:1,BlackCore:1", "Recipe to upgrade circet to quality 4");
			circletRecipeQuality1.SettingChanged += delegate
			{
				CircletItem.FillRecipe();
			};
			circletRecipeQuality2.SettingChanged += delegate
			{
				CircletItem.FillRecipe();
			};
			circletRecipeQuality3.SettingChanged += delegate
			{
				CircletItem.FillRecipe();
			};
			circletRecipeQuality4.SettingChanged += delegate
			{
				CircletItem.FillRecipe();
			};
			visualStateItemDrop = config("Circlet - Visual state", "Enable itemdrop state", defaultValue: true, "Circlet dropped on the ground will preserve light state");
			visualStateItemStand = config("Circlet - Visual state", "Enable item stand state", defaultValue: true, "Circlet put on the item stand will preserve light state");
			visualStateArmorStand = config("Circlet - Visual state", "Enable armor stand state", defaultValue: true, "Circlet put on the armor stand will preserve light state");
			itemSlotType = config("Circlet - Custom slot", "Slot type", 55, "Custom item slot type. Change it only if you have issues with other mods compatibility. Game restart is recommended after change.");
			itemSlotAzuEPI = config("Circlet - Custom slot", "AzuEPI - Create slot", defaultValue: false, "Create custom equipment slot with AzuExtendedPlayerInventory. Game restart is required to apply changes.");
			itemSlotNameAzuEPI = config("Circlet - Custom slot", "AzuEPI - Slot name", "Circlet", "Custom equipment slot name. Game restart is required to apply changes.");
			itemSlotIndexAzuEPI = config("Circlet - Custom slot", "AzuEPI - Slot index", -1, "Slot index (position). Game restart is required to apply changes.");
			itemSlotExtraSlots = config("Circlet - Custom slot", "ExtraSlots - Create slot", defaultValue: false, "Create custom equipment slot with ExtraSlots.");
			itemSlotNameExtraSlots = config("Circlet - Custom slot", "ExtraSlots - Slot name", "Circlet", "Custom equipment slot name.");
			itemSlotIndexExtraSlots = config("Circlet - Custom slot", "ExtraSlots - Slot index", -1, "Slot index (position). Game restart is required to apply changes.");
			itemSlotExtraSlotsDiscovery = config("Circlet - Custom slot", "ExtraSlots - Available after discovery", defaultValue: true, "If enabled - slot will be active only if you know circlet item.");
			itemSlotType.SettingChanged += delegate
			{
				CircletItem.PatchCircletItemOnConfigChange();
			};
			itemSlotExtraSlots.SettingChanged += delegate
			{
				ExtraSlotsAPI.API.UpdateSlots();
			};
			widenShortcut = config<KeyboardShortcut>("Hotkeys", "Beam widen", new KeyboardShortcut((KeyCode)275, Array.Empty<KeyCode>()), "Widen beam shortcut. [Not Synced with Server]", synchronizedSetting: false);
			narrowShortcut = config<KeyboardShortcut>("Hotkeys", "Beam narrow", new KeyboardShortcut((KeyCode)276, Array.Empty<KeyCode>()), "Narrow beam shortcut. [Not Synced with Server]", synchronizedSetting: false);
			overloadShortcut = config<KeyboardShortcut>("Hotkeys", "Overload", new KeyboardShortcut((KeyCode)116, Array.Empty<KeyCode>()), "Overload shortcut. Blind opponents with a bright flash at the cost of some circlet durability. [Not Synced with Server]", synchronizedSetting: false);
			toggleShortcut = config<KeyboardShortcut>("Hotkeys", "Toggle light", new KeyboardShortcut((KeyCode)273, Array.Empty<KeyCode>()), "Toggle main light shortcut. Enable/disable frontlight. [Not Synced with Server]", synchronizedSetting: false);
			toggleDemisterShortcut = config<KeyboardShortcut>("Hotkeys", "Toggle demister", new KeyboardShortcut((KeyCode)274, Array.Empty<KeyCode>()), "Toggle demister shortcut. Spawn/despawn demister wisplight. [Not Synced with Server]", synchronizedSetting: false);
			increaseIntensityShortcut = config<KeyboardShortcut>("Hotkeys - Extra", "Intensity increase", new KeyboardShortcut((KeyCode)273, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), "Increase intensity shortcut. Light becomes brighter and have more range. Intensity is capped at 150% [Not Synced with Server]", synchronizedSetting: false);
			decreaseIntensityShortcut = config<KeyboardShortcut>("Hotkeys - Extra", "Intensity decrease", new KeyboardShortcut((KeyCode)274, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), "Decrease intensity shortcut. Light becomes darker and have less range. Intensity is capped at 50% [Not Synced with Server]", synchronizedSetting: false);
			toggleShadowsShortcut = config<KeyboardShortcut>("Hotkeys - Extra", "Toggle shadows", new KeyboardShortcut((KeyCode)276, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), "Toggle shadows shortcut. Enables/disables the current light source to emit soft shadows. [Not Synced with Server]", synchronizedSetting: false);
			toggleSpotShortcut = config<KeyboardShortcut>("Hotkeys - Extra", "Toggle radiance", new KeyboardShortcut((KeyCode)275, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), "Toggle spotlight shortcut. Enables/disables the radiance when circlet is equipped. [Not Synced with Server]", synchronizedSetting: false);
			widenShortcut.SettingChanged += delegate
			{
				FillShortcuts();
			};
			narrowShortcut.SettingChanged += delegate
			{
				FillShortcuts();
			};
			overloadShortcut.SettingChanged += delegate
			{
				FillShortcuts();
			};
			toggleShortcut.SettingChanged += delegate
			{
				FillShortcuts();
			};
			toggleDemisterShortcut.SettingChanged += delegate
			{
				FillShortcuts();
			};
			increaseIntensityShortcut.SettingChanged += delegate
			{
				FillShortcuts();
			};
			decreaseIntensityShortcut.SettingChanged += delegate
			{
				FillShortcuts();
			};
			toggleShadowsShortcut.SettingChanged += delegate
			{
				FillShortcuts();
			};
			toggleSpotShortcut.SettingChanged += delegate
			{
				FillShortcuts();
			};
			maxSteps = config("Light - Default", "Max Steps", 3, "Define how many steps of focus the Dverger light beam has. Must be at least 2.");
			minAngle = config("Light - Default", "Min Angle", 30f, "The angle of the beam at the narrowest setting.");
			maxAngle = config("Light - Default", "Max Angle", 110f, "The angle of the beam at the widest setting.");
			minIntensity = config("Light - Default", "Min Intensity", 1.4f, "The intensity of the beam at the widest setting.");
			maxIntensity = config("Light - Default", "Max Intensity", 2.2f, "The intensity of the beam at the narrowest setting");
			minRange = config("Light - Default", "Min Range", 45f, "The range of the beam at the narrowest setting.");
			maxRange = config("Light - Default", "Max Range", 15f, "The range of the beam at the widest setting");
			pointIntensity = config("Light - Default", "Point Intensity", 1.1f, "The intensity of the Dverger light pool on the point light setting.");
			pointRange = config("Light - Default", "Point Range", 10f, "The range of the Dverger light pool on the point light setting.");
			maxSteps2 = config("Light - Quality 2", "Max Steps", 3, "Define how many steps of focus the Dverger light beam has. Must be at least 2.");
			minAngle2 = config("Light - Quality 2", "Min Angle", 30f, "The angle of the beam at the narrowest setting.");
			maxAngle2 = config("Light - Quality 2", "Max Angle", 110f, "The angle of the beam at the widest setting.");
			minIntensity2 = config("Light - Quality 2", "Min Intensity", 1.4f, "The intensity of the beam at the widest setting.");
			maxIntensity2 = config("Light - Quality 2", "Max Intensity", 2.2f, "The intensity of the beam at the narrowest setting");
			minRange2 = config("Light - Quality 2", "Min Range", 45f, "The range of the beam at the narrowest setting.");
			maxRange2 = config("Light - Quality 2", "Max Range", 15f, "The range of the beam at the widest setting");
			pointIntensity2 = config("Light - Quality 2", "Point Intensity", 1.1f, "The intensity of the Dverger light pool on the point light setting.");
			pointRange2 = config("Light - Quality 2", "Point Range", 10f, "The range of the Dverger light pool on the point light setting.");
			maxSteps3 = config("Light - Quality 3", "Max Steps", 3, "Define how many steps of focus the Dverger light beam has. Must be at least 2.");
			minAngle3 = config("Light - Quality 3", "Min Angle", 30f, "The angle of the beam at the narrowest setting.");
			maxAngle3 = config("Light - Quality 3", "Max Angle", 110f, "The angle of the beam at the widest setting.");
			minIntensity3 = config("Light - Quality 3", "Min Intensity", 1.4f, "The intensity of the beam at the widest setting.");
			maxIntensity3 = config("Light - Quality 3", "Max Intensity", 2.2f, "The intensity of the beam at the narrowest setting");
			minRange3 = config("Light - Quality 3", "Min Range", 45f, "The range of the beam at the narrowest setting.");
			maxRange3 = config("Light - Quality 3", "Max Range", 15f, "The range of the beam at the widest setting");
			pointIntensity3 = config("Light - Quality 3", "Point Intensity", 1.1f, "The intensity of the Dverger light pool on the point light setting.");
			pointRange3 = config("Light - Quality 3", "Point Range", 10f, "The range of the Dverger light pool on the point light setting.");
			maxSteps4 = config("Light - Quality 4", "Max Steps", 3, "Define how many steps of focus the Dverger light beam has. Must be at least 2.");
			minAngle4 = config("Light - Quality 4", "Min Angle", 30f, "The angle of the beam at the narrowest setting.");
			maxAngle4 = config("Light - Quality 4", "Max Angle", 110f, "The angle of the beam at the widest setting.");
			minIntensity4 = config("Light - Quality 4", "Min Intensity", 1.4f, "The intensity of the beam at the widest setting.");
			maxIntensity4 = config("Light - Quality 4", "Max Intensity", 2.2f, "The intensity of the beam at the narrowest setting");
			minRange4 = config("Light - Quality 4", "Min Range", 45f, "The range of the beam at the narrowest setting.");
			maxRange4 = config("Light - Quality 4", "Max Range", 15f, "The range of the beam at the widest setting");
			pointIntensity4 = config("Light - Quality 4", "Point Intensity", 1.1f, "The intensity of the Dverger light pool on the point light setting.");
			pointRange4 = config("Light - Quality 4", "Point Range", 10f, "The range of the Dverger light pool on the point light setting.");
			FillShortcuts();
			FillHelmets();
		}

		private void FillShortcuts()
		{
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			AddShortcut(dictionary, widenShortcut);
			AddShortcut(dictionary, narrowShortcut);
			AddShortcut(dictionary, toggleShortcut);
			AddShortcut(dictionary, toggleSpotShortcut);
			AddShortcut(dictionary, increaseIntensityShortcut);
			AddShortcut(dictionary, decreaseIntensityShortcut);
			AddShortcut(dictionary, toggleShadowsShortcut);
			AddShortcut(dictionary, overloadShortcut);
			AddShortcut(dictionary, toggleDemisterShortcut);
			hotkeys = (from x in dictionary
				orderby x.Value descending
				select x.Key).ToList();
		}

		private void FillHelmets()
		{
			equipWithHelmetsList = new HashSet<int>(from c in equipCircletWithHelmet.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries)
				select StringExtensionMethods.GetStableHashCode(c.Trim()));
		}

		private void AddShortcut(Dictionary<int, int> shortcuts, ConfigEntry<KeyboardShortcut> shortcut)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			int hashCode = ((object)((ConfigEntryBase)shortcut).Definition).GetHashCode();
			KeyboardShortcut value = shortcut.Value;
			shortcuts.Add(hashCode, ((KeyboardShortcut)(ref value)).Modifiers.Count());
		}

		private ConfigEntry<T> config<T>(string group, string name, T defaultValue, ConfigDescription description, bool synchronizedSetting = true)
		{
			ConfigEntry<T> val = ((BaseUnityPlugin)this).Config.Bind<T>(group, name, defaultValue, description);
			SyncedConfigEntry<T> syncedConfigEntry = configSync.AddConfigEntry<T>(val);
			syncedConfigEntry.SynchronizedConfig = synchronizedSetting;
			return val;
		}

		private ConfigEntry<T> config<T>(string group, string name, T defaultValue, string description, bool synchronizedSetting = true)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			return config(group, name, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting);
		}

		public static int GetMaxSteps(int quality)
		{
			return ((!getFeaturesByUpgrade.Value) ? 1 : Mathf.Clamp(quality, 1, 4)) switch
			{
				1 => maxSteps.Value, 
				2 => maxSteps2.Value, 
				3 => maxSteps3.Value, 
				4 => maxSteps4.Value, 
				_ => maxSteps.Value, 
			};
		}

		public static float GetMinAngle(int quality)
		{
			return ((!getFeaturesByUpgrade.Value) ? 1 : Mathf.Clamp(quality, 1, 4)) switch
			{
				1 => minAngle.Value, 
				2 => minAngle2.Value, 
				3 => minAngle3.Value, 
				4 => minAngle4.Value, 
				_ => minAngle.Value, 
			};
		}

		public static float GetMaxAngle(int quality)
		{
			return ((!getFeaturesByUpgrade.Value) ? 1 : Mathf.Clamp(quality, 1, 4)) switch
			{
				1 => maxAngle.Value, 
				2 => maxAngle2.Value, 
				3 => maxAngle3.Value, 
				4 => maxAngle4.Value, 
				_ => maxAngle.Value, 
			};
		}

		public static float GetMinIntensity(int quality)
		{
			return ((!getFeaturesByUpgrade.Value) ? 1 : Mathf.Clamp(quality, 1, 4)) switch
			{
				1 => minIntensity.Value, 
				2 => minIntensity2.Value, 
				3 => minIntensity3.Value, 
				4 => minIntensity4.Value, 
				_ => minIntensity.Value, 
			};
		}

		public static float GetMaxIntensity(int quality)
		{
			return ((!getFeaturesByUpgrade.Value) ? 1 : Mathf.Clamp(quality, 1, 4)) switch
			{
				1 => maxIntensity.Value, 
				2 => maxIntensity2.Value, 
				3 => maxIntensity3.Value, 
				4 => maxIntensity4.Value, 
				_ => maxIntensity.Value, 
			};
		}

		public static float GetMinRange(int quality)
		{
			return ((!getFeaturesByUpgrade.Value) ? 1 : Mathf.Clamp(quality, 1, 4)) switch
			{
				1 => minRange.Value, 
				2 => minRange2.Value, 
				3 => minRange3.Value, 
				4 => minRange4.Value, 
				_ => minRange.Value, 
			};
		}

		public static float GetMaxRange(int quality)
		{
			return ((!getFeaturesByUpgrade.Value) ? 1 : Mathf.Clamp(quality, 1, 4)) switch
			{
				1 => maxRange.Value, 
				2 => maxRange2.Value, 
				3 => maxRange3.Value, 
				4 => maxRange4.Value, 
				_ => maxRange.Value, 
			};
		}

		public static float GetPointIntensity(int quality)
		{
			return ((!getFeaturesByUpgrade.Value) ? 1 : Mathf.Clamp(quality, 1, 4)) switch
			{
				1 => pointIntensity.Value, 
				2 => pointIntensity2.Value, 
				3 => pointIntensity3.Value, 
				4 => pointIntensity4.Value, 
				_ => pointIntensity.Value, 
			};
		}

		public static float GetPointRange(int quality)
		{
			return ((!getFeaturesByUpgrade.Value) ? 1 : Mathf.Clamp(quality, 1, 4)) switch
			{
				1 => pointRange.Value, 
				2 => pointRange2.Value, 
				3 => pointRange3.Value, 
				4 => pointRange4.Value, 
				_ => pointRange.Value, 
			};
		}
	}
	internal static class CircletItem
	{
		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		public static class ObjectDB_Awake_CircletStats
		{
			[HarmonyPriority(0)]
			private static void Postfix()
			{
				if (CircletExtended.modEnabled.Value)
				{
					DvergerLightController.RegisterEffects();
					FillRecipe();
				}
			}
		}

		[HarmonyPatch(typeof(Player), "AddKnownItem")]
		public static class Player_AddKnownItem_CircletStats
		{
			private static void Postfix(ref ItemData item)
			{
				if (CircletExtended.modEnabled.Value && CircletExtended.getFeaturesByUpgrade.Value && IsCircletItemData(item))
				{
					PatchCircletItemData(item);
				}
			}
		}

		[HarmonyPatch(typeof(Player), "OnSpawned")]
		public class Player_OnSpawned_CircletStats
		{
			public static void Postfix(Player __instance)
			{
				if (CircletExtended.modEnabled.Value && CircletExtended.getFeaturesByUpgrade.Value && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
				{
					PatchInventory(((Humanoid)__instance).GetInventory());
				}
			}
		}

		[HarmonyPatch(typeof(Inventory), "Load")]
		public class Inventory_Load_CircletStats
		{
			public static void Postfix(Inventory __instance)
			{
				if (CircletExtended.modEnabled.Value)
				{
					PatchInventory(__instance);
				}
			}
		}

		[HarmonyPatch(typeof(ItemDrop), "Start")]
		public static class ItemDrop_Start_CircletStats
		{
			private static void Postfix(ItemDrop __instance)
			{
				if (CircletExtended.modEnabled.Value && CircletExtended.getFeaturesByUpgrade.Value && IsCircletItem(__instance))
				{
					PatchCircletItemData(__instance.m_itemData);
				}
			}
		}

		[HarmonyPatch(typeof(Requirement), "GetAmount")]
		public class PieceRequirement_GetAmount_CircletUpgrade
		{
			public static void Postfix(Requirement __instance, int qualityLevel, ref int __result)
			{
				if (CircletExtended.modEnabled.Value && CircletExtended.getFeaturesByUpgrade.Value && IsCircletItem(__instance.m_resItem))
				{
					__result = ((qualityLevel <= 1) ? 1 : 0);
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "DoCrafting")]
		public class InventoryGui_DoCrafting_CircletUpgrade
		{
			private static bool PatchMethod(ItemData ___m_craftUpgradeItem, Recipe ___m_craftRecipe)
			{
				if (!CircletExtended.modEnabled.Value)
				{
					return false;
				}
				if (!CircletExtended.getFeaturesByUpgrade.Value)
				{
					return false;
				}
				if ((Object)(object)___m_craftRecipe == (Object)null || ___m_craftUpgradeItem == null)
				{
					return false;
				}
				if (!IsCircletItemData(___m_craftUpgradeItem))
				{
					return false;
				}
				return true;
			}

			[HarmonyPriority(800)]
			public static void Prefix(Player player, ref Recipe ___m_craftRecipe, ref KeyValuePair<bool, Requirement[]> __state, ItemData ___m_craftUpgradeItem)
			{
				if (PatchMethod(___m_craftUpgradeItem, ___m_craftRecipe))
				{
					int key = ___m_craftUpgradeItem.m_quality + 1;
					__state = new KeyValuePair<bool, Requirement[]>(player.m_noPlacementCost, ___m_craftRecipe.m_resources.ToArray());
					___m_craftRecipe.m_resources = CircletExtended.recipeRequirements[key].ToArray();
					player.m_noPlacementCost = true;
				}
			}

			[HarmonyPriority(0)]
			public static void Postfix(Player player, ref Recipe ___m_craftRecipe, KeyValuePair<bool, Requirement[]> __state, ItemData ___m_craftUpgradeItem)
			{
				if (PatchMethod(___m_craftUpgradeItem, ___m_craftRecipe))
				{
					player.m_noPlacementCost = __state.Key;
					if (!player.m_noPlacementCost)
					{
						player.ConsumeResources(___m_craftRecipe.m_resources, 1, -1, 1);
					}
					___m_craftRecipe.m_resources = __state.Value.ToArray();
					PatchCircletItemData(___m_craftUpgradeItem, inventoryItemUpdate: false);
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "SetupRequirementList")]
		public class InventoryGui_SetupRequirementList_CircletUpgrade
		{
			private static bool PatchMethod(KeyValuePair<Recipe, ItemData> ___m_selectedRecipe)
			{
				if (!CircletExtended.modEnabled.Value)
				{
					return false;
				}
				if (!CircletExtended.getFeaturesByUpgrade.Value)
				{
					return false;
				}
				return IsCircletItem(___m_selectedRecipe.Key.m_item);
			}

			[HarmonyPriority(800)]
			public static void Prefix(ref int quality, ref KeyValuePair<Recipe, ItemData> ___m_selectedRecipe, ref KeyValuePair<int, Requirement[]> __state)
			{
				if (PatchMethod(___m_selectedRecipe))
				{
					__state = new KeyValuePair<int, Requirement[]>(quality, ___m_selectedRecipe.Key.m_resources.ToArray());
					___m_selectedRecipe.Key.m_resources = CircletExtended.recipeRequirements[quality].ToArray();
					quality = 1;
				}
			}

			[HarmonyPriority(0)]
			public static void Postfix(ref int quality, ref KeyValuePair<Recipe, ItemData> ___m_selectedRecipe, KeyValuePair<int, Requirement[]> __state)
			{
				if (PatchMethod(___m_selectedRecipe))
				{
					___m_selectedRecipe.Key.m_resources = __state.Value.ToArray();
					quality = __state.Key;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "HaveRequirementItems")]
		public class Player_HaveRequirementItems_CircletUpgrade
		{
			private static bool PatchMethod(bool discover, Recipe piece)
			{
				if (!CircletExtended.modEnabled.Value)
				{
					return false;
				}
				if (!CircletExtended.getFeaturesByUpgrade.Value)
				{
					return false;
				}
				if (discover)
				{
					return false;
				}
				return IsCircletItem(piece.m_item);
			}

			[HarmonyPriority(800)]
			public static void Prefix(ref Recipe piece, bool discover, ref int qualityLevel, ref KeyValuePair<int, Requirement[]> __state)
			{
				if (PatchMethod(discover, piece))
				{
					__state = new KeyValuePair<int, Requirement[]>(qualityLevel, piece.m_resources.ToArray());
					piece.m_resources = CircletExtended.recipeRequirements[qualityLevel].ToArray();
					qualityLevel = 1;
				}
			}

			[HarmonyPriority(0)]
			public static void Postfix(ref Recipe piece, bool discover, ref int qualityLevel, KeyValuePair<int, Requirement[]> __state)
			{
				if (PatchMethod(discover, piece))
				{
					piece.m_resources = __state.Value.ToArray();
					qualityLevel = __state.Key;
				}
			}
		}

		[HarmonyPatch(typeof(Humanoid), "UpdateEquipment")]
		public class Humanoid_UpdateEquipment_CircletEquipmentDrain
		{
			public static void Postfix(Humanoid __instance, float dt)
			{
				if (CircletExtended.modEnabled.Value && ((Character)__instance).IsPlayer() && UseFuel() && __instance.GetCirclet() != null && __instance.GetCirclet().IsCircletLightEnabled() && (Object)(object)((Player)((__instance is Player) ? __instance : null)).GetCurrentCraftingStation() == (Object)null)
				{
					__instance.DrainEquipedItemDurability(__instance.GetCirclet(), dt);
				}
			}
		}

		[HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[]
		{
			typeof(ItemData),
			typeof(int),
			typeof(bool),
			typeof(float),
			typeof(int)
		})]
		private class ItemDropItemData_GetTooltip_ItemTooltip
		{
			[HarmonyPriority(0)]
			private static void Postfix(ItemData item, ref string __result)
			{
				if (IsCircletItemData(item) && UseFuel())
				{
					__result = __result.Replace("$item_durability", "$piece_fire_fuel");
				}
			}
		}

		[HarmonyPatch(typeof(Inventory), "GetWornItems")]
		public class Inventory_GetWornItems_CircletAlwaysLastToRepair
		{
			public static void Postfix(Inventory __instance, List<ItemData> worn)
			{
				if (!CircletExtended.modEnabled.Value)
				{
					return;
				}
				Player localPlayer = Player.m_localPlayer;
				if (__instance != ((localPlayer != null) ? ((Humanoid)localPlayer).GetInventory() : null) || !UseFuel())
				{
					return;
				}
				for (int num = worn.Count - 1; num >= 0; num--)
				{
					if (IsCircletItemData(worn[num]) && worn[num].m_equipped && (((Humanoid)(object)Player.m_localPlayer)?.GetCirclet() == worn[num] || ((Humanoid)Player.m_localPlayer).m_helmetItem == worn[num]))
					{
						worn.Add(worn[num]);
						worn.RemoveAt(num);
					}
				}
			}
		}

		[HarmonyPatch(typeof(Inventory), "Changed")]
		public static class Inventory_Changed_PatchCirclets
		{
			private static void Prefix(Inventory __instance)
			{
				PatchInventory(__instance);
			}
		}

		[HarmonyPatch(typeof(Inventory), "AddItem", new Type[]
		{
			typeof(ItemData),
			typeof(int),
			typeof(int),
			typeof(int)
		})]
		private static class Inventory_AddItem_ItemData_amount_x_y_PatchCircletItemDataOnLoad
		{
			[HarmonyBefore(new string[] { "shudnal.ExtraSlots" })]
			[HarmonyPriority(800)]
			private static void Prefix(ItemData item)
			{
				if (CircletExtended.modEnabled.Value && CircletExtended.getFeaturesByUpgrade.Value && IsCircletItemData(item))
				{
					PatchCircletItemData(item);
				}
			}
		}

		public const string itemNameHelmetDverger = "HelmetDverger";

		public const string itemDropNameHelmetDverger = "$item_helmet_dverger";

		public static int itemHashHelmetDverger = StringExtensionMethods.GetStableHashCode("HelmetDverger");

		public static GameObject circletPrefab;

		public const int maxQuality = 4;

		internal static ItemType GetItemType()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			return (ItemType)CircletExtended.itemSlotType.Value;
		}

		internal static bool IsCircletType(ItemData item)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			return item != null && item.m_shared.m_itemType == GetItemType();
		}

		internal static bool IsCircletItem(ItemDrop item)
		{
			return (Object)(object)item != (Object)null && (IsCircletItemName(item.GetPrefabName(((Object)item).name)) || IsCircletItemData(item.m_itemData));
		}

		internal static bool IsCircletItemData(ItemData item)
		{
			return item != null && (((Object)(object)item.m_dropPrefab != (Object)null && IsCircletItemName(((Object)item.m_dropPrefab).name)) || IsCircletItemDropName(item.m_shared.m_name));
		}

		internal static bool IsCircletItem(ItemData item)
		{
			return IsCircletItemData(item) && IsCircletType(item);
		}

		internal static bool IsCircletItemDropName(string name)
		{
			return name == "$item_helmet_dverger";
		}

		internal static bool IsCircletItemName(string name)
		{
			return name == "HelmetDverger";
		}

		internal static bool IsCircletKnown()
		{
			if (!Object.op_Implicit((Object)(object)Player.m_localPlayer) || Player.m_localPlayer.m_isLoading)
			{
				return true;
			}
			return Player.m_localPlayer.IsKnownMaterial("$item_helmet_dverger");
		}

		internal static bool IsCircletSlotAvailable()
		{
			return CircletExtended.itemSlotExtraSlots.Value && (!CircletExtended.itemSlotExtraSlotsDiscovery.Value || IsCircletKnown());
		}

		internal static void PatchCircletItemData(ItemData item, bool inventoryItemUpdate = true)
		{
			//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_0187: Unknown result type (might be due to invalid IL or missing references)
			if (CircletExtended.modEnabled.Value && item != null)
			{
				item.m_shared.m_maxQuality = ((!CircletExtended.getFeaturesByUpgrade.Value) ? 1 : 4);
				item.m_shared.m_durabilityPerLevel = (CircletExtended.getFeaturesByUpgrade.Value ? CircletExtended.fuelPerLevel.Value : 100);
				item.m_shared.m_useDurability = UseFuel() || item.GetDurabilityPercentage() != 1f || item.m_quality >= 3;
				item.m_shared.m_maxDurability = (UseFuel() ? CircletExtended.fuelMinutes.Value : 1000);
				item.m_shared.m_useDurabilityDrain = (UseFuel() ? 1f : 0f);
				item.m_shared.m_durabilityDrain = (UseFuel() ? (Time.fixedDeltaTime * (5f / 6f)) : 0f);
				item.m_shared.m_destroyBroken = false;
				item.m_shared.m_canBeReparied = true;
				if (!inventoryItemUpdate || item.m_durability > item.GetMaxDurability())
				{
					item.m_durability = item.GetMaxDurability();
				}
				if (CircletExtended.enablePutOnTop.Value && ((CircletExtended.getFeaturesByUpgrade.Value && item.m_quality >= 2) || !CircletExtended.getFeaturesByUpgrade.Value))
				{
					item.m_shared.m_itemType = GetItemType();
					item.m_shared.m_attachOverride = (ItemType)6;
				}
			}
		}

		internal static void PatchInventory(Inventory inventory)
		{
			if (inventory == null)
			{
				return;
			}
			List<ItemData> list = new List<ItemData>();
			inventory.GetAllItems("$item_helmet_dverger", list);
			foreach (ItemData item in list)
			{
				PatchCircletItemData(item);
			}
		}

		internal static void PatchCircletItemOnConfigChange()
		{
			GameObject obj = circletPrefab;
			PatchCircletItemData((obj == null) ? null : obj.GetComponent<ItemDrop>()?.m_itemData, inventoryItemUpdate: false);
			Player localPlayer = Player.m_localPlayer;
			PatchInventory((localPlayer != null) ? ((Humanoid)localPlayer).GetInventory() : null);
		}

		internal static bool UseFuel()
		{
			return CircletExtended.fuelMinutes.Value > 0;
		}

		public static bool IsCircletLightEnabled(this ItemData item)
		{
			return DvergerLightController.IsCircletLightEnabled(item);
		}

		internal static void FillRecipe()
		{
			if (!Object.op_Implicit((Object)(object)ObjectDB.instance))
			{
				return;
			}
			if (ObjectDB.instance.m_recipes.RemoveAll((Recipe x) => IsCircletItemName(((Object)x).name)) > 0)
			{
				CircletExtended.LogInfo("Removed recipe HelmetDverger");
			}
			circletPrefab = ObjectDB.instance.GetItemPrefab(itemHashHelmetDverger);
			if ((Object)(object)circletPrefab == (Object)null)
			{
				return;
			}
			ItemDrop component = circletPrefab.GetComponent<ItemDrop>();
			PatchCircletItemData(component.m_itemData, inventoryItemUpdate: false);
			if (CircletExtended.getFeaturesByUpgrade.Value)
			{
				FillRecipeRequirements();
				CraftingStation val = ((IEnumerable<Recipe>)ObjectDB.instance.m_recipes).FirstOrDefault((Func<Recipe, bool>)((Recipe rec) => rec.m_craftingStation?.m_name == "$piece_forge"))?.m_craftingStation;
				Recipe val2 = ScriptableObject.CreateInstance<Recipe>();
				((Object)val2).name = "HelmetDverger";
				val2.m_amount = 1;
				val2.m_minStationLevel = 3;
				val2.m_item = component;
				val2.m_enabled = true;
				if ((Object)(object)val != (Object)null)
				{
					val2.m_craftingStation = val;
				}
				val2.m_resources = CircletExtended.recipeRequirements[1];
				ObjectDB.instance.m_recipes.Add(val2);
			}
		}

		private static void FillRecipeRequirements()
		{
			CircletExtended.recipeRequirements.Clear();
			for (int i = 0; i <= 5; i++)
			{
				CircletExtended.recipeRequirements.Add(i, GetRequirements(i));
			}
		}

		private static string GetRecipe(int quality)
		{
			if (1 == 0)
			{
			}
			string result = quality switch
			{
				1 => CircletExtended.circletRecipeQuality1.Value, 
				2 => CircletExtended.circletRecipeQuality2.Value, 
				3 => CircletExtended.circletRecipeQuality3.Value, 
				4 => CircletExtended.circletRecipeQuality4.Value, 
				_ => "", 
			};
			if (1 == 0)
			{
			}
			return result;
		}

		private static Requirement[] GetRequirements(int quality)
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			List<Requirement> list = new List<Requirement>();
			string[] array = GetRecipe(quality).Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
			foreach (string text in array)
			{
				string[] array2 = text.Split(new char[1] { ':' }, StringSplitOptions.RemoveEmptyEntries);
				if (array2.Length != 2)
				{
					continue;
				}
				int num = int.Parse(array2[1]);
				if (num > 0)
				{
					GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(array2[0].Trim());
					if (!((Object)(object)itemPrefab == (Object)null))
					{
						list.Add(new Requirement
						{
							m_amount = num,
							m_resItem = itemPrefab.GetComponent<ItemDrop>()
						});
					}
				}
			}
			return list.ToArray();
		}
	}
	[RequireComponent(typeof(Light))]
	public class DvergerLightController : MonoBehaviour
	{
		[Serializable]
		private class LightState
		{
			public bool on = true;

			public int level = 2;

			public int intensity = 100;

			public Color color = new Color(0.25f, 0.38f, 0.37f);

			public bool shadows = true;

			public bool spot = false;

			public bool overloaded = false;

			public float overload = 1f;

			public bool demister = false;

			public int quality = 1;

			public bool demisted = false;

			public float demistedrange = 1f;

			public bool forceoff = false;

			[NonSerialized]
			public int hash = 0;

			[NonSerialized]
			public string json = "";

			public void UpdateHash()
			{
				json = JsonUtility.ToJson((object)this);
				hash = StringExtensionMethods.GetStableHashCode(json);
			}
		}

		private ZNetView m_nview;

		private Light m_frontLight;

		private Light m_spotLight;

		private Player m_playerAttached;

		private ItemData m_item;

		private int m_zdoIndex;

		private GameObject m_visual;

		private LightState m_state = new LightState();

		private ParticleSystemForceField m_overloadDemister;

		private int m_maxLevel = 3;

		private float m_minAngle = 30f;

		private float m_maxAngle = 110f;

		private float m_minIntensity = 1.4f;

		private float m_maxIntensity = 2.2f;

		private float m_minRange = 45f;

		private float m_maxRange = 15f;

		private float m_pointIntensity = 1.1f;

		private float m_pointRange = 10f;

		private int m_overloadCharges = 50;

		private MeshRenderer m_gemRenderer;

		private Color m_gemColor;

		private const int intensityIncrement = 10;

		private const int intensityFactorMax = 150;

		private const int intensityFactorMin = 50;

		private const float overloadIntensityInterval = 2f;

		private const float overloadIntensityMin = 0.5f;

		private const float overloadIntensityMax = 4f;

		private static int s_rayMaskSolids = 0;

		private static int s_rayMaskCharacters = 0;

		private static readonly MaterialPropertyBlock s_matBlock = new MaterialPropertyBlock();

		public static GameObject overloadEffect;

		public const string overloadItemName = "circletExtendedOverload";

		public static int overloadItemHash = StringExtensionMethods.GetStableHashCode("circletExtendedOverload");

		public static Color overloadColor;

		public static int demisterEffectHash = StringExtensionMethods.GetStableHashCode("Demister");

		public static GameObject demisterForceField;

		public const string forceFieldDemisterName = "Particle System Force Field";

		public static int s_lightMaskNonPlayer;

		private float m_updateVisualTimer = 0f;

		private static readonly List<DvergerLightController> Instances = new List<DvergerLightController>();

		private static readonly Dictionary<ItemData, LightState> itemState = new Dictionary<ItemData, LightState>();

		private const int c_characterLayer = 9;

		public static readonly int s_stateHash = StringExtensionMethods.GetStableHashCode("circletStateHash");

		public static readonly int s_state = StringExtensionMethods.GetStableHashCode("circletState");

		private void Awake()
		{
			m_nview = ((Component)this).GetComponentInParent<ZNetView>();
			m_gemRenderer = ((Component)this).GetComponentInChildren<MeshRenderer>();
			if (s_lightMaskNonPlayer == 0)
			{
				s_lightMaskNonPlayer = LayerMask.GetMask(new string[11]
				{
					"Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "character_net", "character_ghost", "hitbox", "character_noenv",
					"vehicle"
				});
			}
		}

		private void Start()
		{
			GetSpotLight();
			Player playerAttached = m_playerAttached;
			m_visual = ((playerAttached != null) ? ((Character)playerAttached).GetVisual() : null);
			UpdateVisualLayers();
		}

		private void FixedUpdate()
		{
			if (m_updateVisualTimer > 0f)
			{
				m_updateVisualTimer = Mathf.Max(0f, m_updateVisualTimer - Time.fixedDeltaTime);
				if (m_updateVisualTimer == 0f)
				{
					UpdateVisualLayers();
				}
			}
		}

		private void OnEnable()
		{
			Instances.Add(this);
			if (m_item != null && !itemState.ContainsKey(m_item))
			{
				itemState.Add(m_item, m_state);
			}
		}

		private void OnDisable()
		{
			Instances.Remove(this);
			if (m_item != null)
			{
				itemState.Remove(m_item);
			}
		}

		private void ApplyGemColor(Color gemColor)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_0027: 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)
			if (!((Object)(object)m_gemRenderer == (Object)null) && !(m_gemColor == gemColor))
			{
				m_gemColor = gemColor;
				((Renderer)m_gemRenderer).GetPropertyBlock(s_matBlock, 0);
				s_matBlock.SetColor("_EmissionColor", m_gemColor);
				((Renderer)m_gemRenderer).SetPropertyBlock(s_matBlock, 0);
			}
		}

		private void Update()
		{
			if (CircletExtended.modEnabled.Value)
			{
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer != (Object)null && (Object)(object)localPlayer == (Object)(object)m_playerAttached && ((Character)localPlayer).TakeInput() && StateChanged(localPlayer))
				{
					SaveState(showMessage: true);
				}
				UpdateLights();
			}
		}

		private void OnDestroy()
		{
			if (CircletExtended.modEnabled.Value)
			{
				Player playerAttached = m_playerAttached;
				if ((Object)(object)playerAttached != (Object)null && m_state.demister && (Object)(object)((Character)playerAttached).GetSEMan().GetStatusEffect(demisterEffectHash) != (Object)null && (((Humanoid)playerAttached).m_utilityItem == null || ((Humanoid)playerAttached).m_utilityItem.m_shared.m_name != "$item_demister"))
				{
					((Character)playerAttached).GetSEMan().RemoveStatusEffect(demisterEffectHash, false);
				}
			}
		}

		private bool QualityLevelAvailable(int quality)
		{
			return !CircletExtended.getFeaturesByUpgrade.Value || m_state.quality >= quality;
		}

		private bool ForceOff()
		{
			return CircletExtended.disableOnSleep.Value && (Object)(object)m_playerAttached != (Object)null && ((Character)m_playerAttached).InBed();
		}

		private bool StateChanged(Player player)
		{
			if (m_item != null)
			{
				m_state.quality = m_item.m_quality;
			}
			if (m_state.forceoff != ForceOff())
			{
				m_state.forceoff = ForceOff();
				CircletExtended.LogInfo("Force off " + (m_state.forceoff ? "enabled" : "disabled"));
				return true;
			}
			foreach (int hotkey in CircletExtended.hotkeys)
			{
				if (IsShortcutDown(hotkey, CircletExtended.toggleShortcut))
				{
					m_state.on = !m_state.on;
					CircletExtended.LogInfo("Toggle " + (m_state.on ? "on" : "off"));
					return true;
				}
				if (QualityLevelAvailable(2) && IsShortcutDown(hotkey, CircletExtended.toggleSpotShortcut))
				{
					m_state.spot = !m_state.spot;
					CircletExtended.LogInfo("Toggle spot " + (m_state.spot ? "on" : "off"));
					return true;
				}
				if (CircletExtended.enableDemister.Value && QualityLevelAvailable(4) && IsShortcutDown(hotkey, CircletExtended.toggleDemisterShortcut))
				{
					m_state.demister = !m_state.demister;
					CircletExtended.LogInfo("Toggle demister " + (m_state.demister ? "on" : "off"));
					return true;
				}
				if (!m_state.on)
				{
					continue;
				}
				if (m_state.level > 0 && IsShortcutDown(hotkey, CircletExtended.widenShortcut))
				{
					m_state.level--;
					CircletExtended.LogInfo($"Widen {m_state.level}");
					return true;
				}
				if (m_state.level < m_maxLevel && IsShortcutDown(hotkey, CircletExtended.narrowShortcut))
				{
					m_state.level++;
					CircletExtended.LogInfo($"Narrow {m_state.level}");
					return true;
				}
				if (m_state.intensity < 150 && IsShortcutDown(hotkey, CircletExtended.increaseIntensityShortcut))
				{
					m_state.intensity = Mathf.Clamp(m_state.intensity + 10, 50, 150);
					CircletExtended.LogInfo($"Increase intensity {m_state.intensity}%");
					return true;
				}
				if (m_state.intensity > 50 && IsShortcutDown(hotkey, CircletExtended.decreaseIntensityShortcut))
				{
					m_state.intensity = Mathf.Clamp(m_state.intensity - 10, 50, 150);
					CircletExtended.LogInfo($"Decrease intensity {m_state.intensity}%");
					return true;
				}
				if (IsShortcutDown(hotkey, CircletExtended.toggleShadowsShortcut))
				{
					m_state.shadows = !m_state.shadows;
					CircletExtended.LogInfo("Toggle shadows " + (m_state.shadows ? "on" : "off"));
					return true;
				}
				if (CircletExtended.enableOverload.Value && QualityLevelAvailable(3) && IsShortcutDown(hotkey, CircletExtended.overloadShortcut))
				{
					CircletExtended.LogInfo("Overload");
					if (m_state.overloaded)
					{
						MessageHud.instance.ShowMessage((MessageType)2, "$item_helmet_dverger: $hud_powernotready", 0, (Sprite)null);
					}
					else
					{
						ApplyOverloadEffect(player);
					}
				}
			}
			return false;
		}

		private void ApplyOverloadEffect(Player player)
		{
			//IL_00a6: 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_00f2: 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_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Expected O, but got Unknown
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			if (m_item == null)
			{
				return;
			}
			if (s_rayMaskSolids == 0)
			{
				s_rayMaskSolids = LayerMask.GetMask(new string[7] { "Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "terrain", "vehicle" });
				s_rayMaskCharacters = LayerMask.GetMask(new string[4] { "character", "character_net", "character_ghost", "character_noenv" });
			}
			ZNetScene.instance.SpawnObject(((Component)player).transform.position, ((Component)m_frontLight).transform.rotation, overloadEffect);
			if (((Character)player).InWater())
			{
				((Character)player).AddLightningDamage(5f);
				((Character)player).AddStaggerDamage(((Character)player).GetStaggerTreshold() + 1f, -((Component)player).transform.forward);
			}
			((MonoBehaviour)this).StartCoroutine(OverloadIntensity());
			if (CircletExtended.enableOverloadDemister.Value && (Object)(object)m_overloadDemister != (Object)null && CircletExtended.overloadDemisterTime.Value != 0f)
			{
				((MonoBehaviour)this).StartCoroutine(OverloadDemister());
			}
			float num = (float)Math.Tan((double)(m_frontLight.spotAngle / 2f) * (Math.PI / 180.0)) * m_frontLight.range;
			RaycastHit[] array = Physics.SphereCastAll(((Component)m_frontLight).transform.position, num, ((Component)m_frontLight).transform.forward, m_frontLight.range, s_rayMaskCharacters);
			if (array.Length != 0)
			{
				for (int i = 0; i < array.Length; i++)
				{
					RaycastHit val = array[i];
					GameObject val2 = (Object.op_Implicit((Object)((RaycastHit)(ref val)).collider) ? Projectile.FindHitObject(((RaycastHit)(ref val)).collider) : null);
					bool flag = false;
					IDestructible val3 = (Object.op_Implicit((Object)(object)val2) ? val2.GetComponent<IDestructible>() : null);
					if (val3 != null)
					{
						flag = val3 is Character;
						if (!IsValidTarget(val3))
						{
							continue;
						}
					}
					if (flag)
					{
						Character val4 = (Character)(object)((val3 is Character) ? val3 : null);
						Vector3 val5 = (((Object)(object)val4.m_head != (Object)null) ? val4.GetHeadPoint() : val4.GetTopPoint());
						Vector3 val6 = val5 - ((Component)m_frontLight).transform.position;
						bool flag2 = Vector3.Angle(((Component)m_frontLight).transform.forward, ((Vector3)(ref val6)).normalized) <= (m_frontLight.spotAngle + 5f) / 2f;
						float num2 = Utils.DistanceXZ(((Component)m_frontLight).transform.position, val5);
						if (num2 <= 5f || (flag2 && num2 <= m_frontLight.range && !Physics.Linecast(((Component)m_frontLight).transform.position, val5, s_rayMaskSolids)))
						{
							val4.AddStaggerDamage(val4.GetStaggerTreshold() + 1f, ((Vector3)(ref val6)).normalized);
						}
					}
				}
			}
			m_item.m_shared.m_useDurability = true;
			float num3 = m_item.GetMaxDurability() / (float)m_overloadCharges;
			m_item.m_durability = Mathf.Max(0f, m_item.m_durability - num3);
		}

		public IEnumerator OverloadIntensity()
		{
			m_state.overloaded = true;
			m_state.overload = 4f;
			float increment = 1.75f * Time.fixedDeltaTime;
			while (m_state.overload > 0.5f)
			{
				m_state.overload -= increment;
				SaveState();
				yield return (object)new WaitForFixedUpdate();
			}
			yield return (object)new WaitForSeconds(1f);
			while (m_state.overload <= 1.05f)
			{
				m_state.overload += increment;
				SaveState();
				yield return (object)new WaitForFixedUpdate();
			}
			yield return (object)new WaitForSeconds(1f);
			while (m_state.overload >= 1f)
			{
				m_state.overload -= increment;
				SaveState();
				yield return (object)new WaitForFixedUpdate();
			}
			m_state.overload = 1f;
			m_state.overloaded = false;
			SaveState();
		}

		public IEnumerator OverloadDemister()
		{
			m_state.demisted = true;
			SaveState();
			for (int i = 0; (float)i < CircletExtended.overloadDemisterTime.Value; i++)
			{
				m_state.demistedrange = 10f + (CircletExtended.overloadDemisterRange.Value - 10f) * (1f - (float)i / CircletExtended.overloadDemisterTime.Value);
				yield return (object)new WaitForSeconds(1f);
			}
			m_state.demisted = false;
			SaveState();
		}

		public bool IsValidTarget(IDestructible destr)
		{
			Character val = (Character)(object)((destr is Character) ? destr : null);
			if (Object.op_Implicit((Object)(object)val))
			{
				if ((Object)(object)val == (Object)(object)m_playerAttached)
				{
					return false;
				}
				if ((Object)(object)m_playerAttached != (Object)null)
				{
					bool flag = BaseAI.IsEnemy((Character)(object)m_playerAttached, val) || (Object.op_Implicit((Object)(object)val.GetBaseAI()) && val.GetBaseAI().IsAggravatable() && ((Character)m_playerAttached).IsPlayer());
					if (!((Character)m_playerAttached).IsPlayer() && !flag)
					{
						return false;
					}
					if (((Character)m_playerAttached).IsPlayer() && !((Character)m_playerAttached).IsPVPEnabled() && !flag)
					{
						return false;
					}
				}
				if (val.IsDodgeInvincible())
				{
					return false;
				}
			}
			return true;
		}

		private bool IsShortcutDown(int hotkey, ConfigEntry<KeyboardShortcut> shortcut)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			int result;
			if (hotkey == ((object)((ConfigEntryBase)shortcut).Definition).GetHashCode())
			{
				KeyboardShortcut value = shortcut.Value;
				if (!((KeyboardShortcut)(ref value)).IsDown())
				{
					value = shortcut.Value;
					if (Input.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey))
					{
						value = shortcut.Value;
						result = ((!((KeyboardShortcut)(ref value)).Modifiers.Any()) ? 1 : 0);
					}
					else
					{
						result = 0;
					}
				}
				else
				{
					result = 1;
				}
			}
			else
			{
				result = 0;
			}
			return (byte)result != 0;
		}

		private void ShowMessage()
		{
			if ((Object)(object)MessageHud.instance != (Object)null && (Object)(object)m_playerAttached != (Object)null && (Object)(object)Player.m_localPlayer == (Object)(object)m_playerAttached)
			{
				MessageHud.instance.m_msgQeue.Clear();
				MessageHud.instance.m_msgQueueTimer = 1f;
				if (!m_state.forceoff && m_state.on)
				{
					MessageHud.instance.ShowMessage((MessageType)1, $"$item_helmet_dverger: $msg_level {m_state.level} ({m_state.intensity}%)", 0, (Sprite)null);
				}
				else
				{
					MessageHud.instance.ShowMessage((MessageType)1, "$item_helmet_dverger: $hud_off", 0, (Sprite)null);
				}
			}
		}

		public void Initialize(Light light, Player player = null, ItemData item = null, int zdoIndex = 0)
		{
			m_frontLight = light;
			m_playerAttached = player;
			m_item = item;
			m_zdoIndex = zdoIndex;
			if (CircletExtended.enableOverloadDemister.Value && Object.op_Implicit((Object)(object)player) && Object.op_Implicit((Object)(object)demisterForceField) && !Object.op_Implicit((Object)(object)m_overloadDemister))
			{
				GameObject val = Object.Instantiate<GameObject>(demisterForceField, ((Component)this).transform);
				((Object)val).name = "Particle System Force Field";
				val.SetActive(false);
				m_overloadDemister = val.GetComponent<ParticleSystemForceField>();
				m_overloadDemister.endRange = CircletExtended.overloadDemisterRange.Value;
			}
			LoadState();
			if (m_item != null && !itemState.ContainsKey(m_item))
			{
				itemState.Add(m_item, m_state);
			}
		}

		private void LoadState()
		{
			if (IsStateLoaded())
			{
				SetQuality();
			}
			if (m_state.overloaded || m_state.demisted || ((Object)(object)m_nview != (Object)null && m_nview.IsValid() && m_nview.IsOwner() && m_nview.GetZDO().GetInt(s_stateHash, 0) == 0))
			{
				m_state.overloaded = false;
				m_state.demisted = false;
				SaveState();
			}
		}

		private bool IsStateLoaded()
		{
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Expected O, but got Unknown
			string text = "";
			if (m_item != null)
			{
				text = GeneralExtensions.GetValueSafe<string, string>(m_item.m_customData, CircletExtended.customDataKey);
				if (string.IsNullOrWhiteSpace(text))
				{
					m_state = new LightState
					{
						quality = m_item.m_quality
					};
					SaveState();
				}
				CircletExtended.LogInfo("Loading state from item: " + text);
			}
			if (string.IsNullOrWhiteSpace(text) && (Object)(object)m_nview != (Object)null && m_nview.IsValid())
			{
				ZDO zDO = m_nview.GetZDO();
				ItemData val = new ItemData();
				ItemDrop.LoadFromZDO(val, zDO);
				text = GeneralExtensions.GetValueSafe<string, string>(val.m_customData, CircletExtended.customDataKey);
				CircletExtended.LogInfo("Loading state from item zdo: " + text);
				if (string.IsNullOrWhiteSpace(text))
				{
					ItemDrop.LoadFromZDO(m_zdoIndex, val, zDO);
					text = GeneralExtensions.GetValueSafe<string, string>(val.m_customData, CircletExtended.customDataKey);
					CircletExtended.LogInfo($"Loading state from zdo index {m_zdoIndex}: {text}");
				}
				if (string.IsNullOrWhiteSpace(text))
				{
					text = zDO.GetString(s_state, "");
					CircletExtended.LogInfo("Loading state from zdo state: " + text);
				}
			}
			if (!string.IsNullOrWhiteSpace(text))
			{
				try
				{
					m_state = JsonUtility.FromJson<LightState>(text);
				}
				catch (Exception arg)
				{
					CircletExtended.LogInfo($"State parsing error:\n{arg}");
					return false;
				}
			}
			return true;
		}

		private void SaveState(bool showMessage = false)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			m_state.color = CircletExtended.circletColor.Value;
			m_state.UpdateHash();
			if (m_item != null)
			{
				m_item.m_customData[CircletExtended.customDataKey] = m_state.json;
			}
			if ((Object)(object)m_nview != (Object)null && m_nview.IsValid() && m_nview.IsOwner())
			{
				m_nview.GetZDO().Set(s_stateHash, m_state.hash, false);
				m_nview.GetZDO().Set(s_state, m_state.json);
			}
			if (showMessage)
			{
				ShowMessage();
			}
			m_state.hash = 0;
		}

		private void SetQuality()
		{
			m_maxLevel = Mathf.Clamp(CircletExtended.GetMaxSteps(m_state.quality), 1, 50);
			m_minAngle = Mathf.Clamp(CircletExtended.GetMinAngle(m_state.quality), 1f, 360f);
			m_maxAngle = Mathf.Clamp(CircletExtended.GetMaxAngle(m_state.quality), 1f, 360f);
			m_minIntensity = Mathf.Clamp(CircletExtended.GetMaxIntensity(m_state.quality), 0f, 10f);
			m_maxIntensity = Mathf.Clamp(CircletExtended.GetMinIntensity(m_state.quality), 0f, 10f);
			m_minRange = Mathf.Clamp(CircletExtended.GetMinRange(m_state.quality), 0f, 1000f);
			m_maxRange = Mathf.Clamp(CircletExtended.GetMaxRange(m_state.quality), 0f, 1000f);
			m_pointIntensity = Mathf.Clamp(CircletExtended.GetPointIntensity(m_state.quality), 0f, 10f);
			m_pointRange = Mathf.Clamp(CircletExtended.GetPointRange(m_state.quality), 0f, 1000f);
			m_overloadCharges = CircletExtended.overloadChargesPerLevel.Value * ((!QualityLevelAvailable(4)) ? 1 : 2);
		}

		private void UpdateLights()
		{
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
			if ((!((Object)(object)m_nview != (Object)null) || !m_nview.IsValid() || m_nview.GetZDO().GetInt(s_stateHash, 0) == m_state.hash || !IsStateLoaded()) && m_state.hash != 0)
			{
				return;
			}
			m_state.UpdateHash();
			if (m_state.level == m_maxLevel)
			{
				m_frontLight.type = (LightType)2;
				m_frontLight.intensity = m_pointIntensity;
				m_frontLight.range = m_pointRange;
			}
			else
			{
				float num = (float)m_state.level / (float)Math.Max(m_maxLevel - 1, 1);
				m_frontLight.type = (LightType)0;
				m_frontLight.spotAngle = Mathf.Lerp(m_minAngle, m_maxAngle, num);
				m_frontLight.intensity = Mathf.Lerp(m_minIntensity, m_maxIntensity, num);
				m_frontLight.range = Mathf.Lerp(m_minRange, m_maxRange, num);
			}
			m_frontLight.color = ((m_state.overload == 1f) ? m_state.color : Color.Lerp(m_state.color, overloadColor, (m_state.overload - 1.05f) / 3.5f));
			float num2 = (float)m_state.intensity / 100f;
			Light frontLight = m_frontLight;
			frontLight.range *= num2;
			Light frontLight2 = m_frontLight;
			frontLight2.intensity *= num2;
			Light frontLight3 = m_frontLight;
			frontLight3.intensity *= m_state.overload;
			float num3 = 1f + (float)m_state.quality * 0.05f;
			Light frontLight4 = m_frontLight;
			frontLight4.range *= num3;
			Light frontLight5 = m_frontLight;
			frontLight5.intensity *= num3;
			((Behaviour)m_frontLight).enabled = !m_state.forceoff && m_state.on;
			m_frontLight.shadows = (LightShadows)((CircletExtended.enableShadows.Value && m_state.shadows && m_state.level != m_maxLevel) ? 2 : 0);
			m_frontLight.shadowStrength = 1f - (float)m_state.level * 0.1f;
			if ((Object)(object)m_spotLight != (Object)null)
			{
				((Behaviour)m_spotLight).enabled = !m_state.forceoff && m_state.spot;
				m_spotLight.intensity = m_state.overload;
				m_spotLight.color = m_frontLight.color;
				m_spotLight.shadows = (LightShadows)((CircletExtended.enableShadows.Value && m_state.shadows && m_state.level != m_maxLevel) ? 2 : 0);
				m_spotLight.shadowStrength = (((Object)(object)m_playerAttached != (Object)null && ((Character)m_playerAttached).InInterior()) ? 0.9f : 0.8f);
				m_spotLight.cullingMask = s_lightMaskNonPlayer;
			}
			if ((Object)(object)m_playerAttached != (Object)null && (Object)(object)m_nview != (Object)null && m_nview.IsValid() && QualityLevelAvailable(4) && (((Humanoid)m_playerAttached).m_utilityItem == null || ((Humanoid)m_playerAttached).m_utilityItem.m_shared.m_name != "$item_demister"))
			{
				SEMan sEMan = ((Character)m_playerAttached).GetSEMan();
				if (m_state.demister && (Object)(object)sEMan.GetStatusEffect(demisterEffectHash) == (Object)null)
				{
					sEMan.AddStatusEffect(demisterEffectHash, false, 0, 0f);
				}
				else if (!m_state.demister && (Object)(object)sEMan.GetStatusEffect(demisterEffectHash) != (Object)null)
				{
					sEMan.RemoveStatusEffect(demisterEffectHash, false);
				}
			}
			if (Object.op_Implicit((Object)(object)m_overloadDemister))
			{
				m_overloadDemister.endRange = m_state.demistedrange;
				((Component)m_overloadDemister).gameObject.SetActive(m_state.demisted);
			}
			ApplyGemColor(m_state.color);
		}

		private void GetSpotLight()
		{
			if ((Object)(object)m_spotLight != (Object)null)
			{
				return;
			}
			Light[] componentsInParent = ((Component)m_frontLight).GetComponentsInParent<Light>();
			foreach (Light val in componentsInParent)
			{
				if ((Object)(object)val != (Object)(object)m_frontLight)
				{
					m_spotLight = val;
				}
			}
		}

		private void UpdateVisualLayers()
		{
			if ((Object)(object)m_visual == (Object)null)
			{
				return;
			}
			for (int i = 0; i < m_visual.transform.childCount; i++)
			{
				Transform child = m_visual.transform.GetChild(i);
				if (((Component)child).gameObject.layer != 9)
				{
					((Component)child).gameObject.layer = 9;
					Transform[] componentsInChildren = ((Component)child).GetComponentsInChildren<Transform>(true);
					Transform[] array = componentsInChildren;
					foreach (Transform val in array)
					{
						((Component)val).gameObject.layer = 9;
					}
				}
			}
		}

		private void StartUpdateVisualLayers()
		{
			m_updateVisualTimer = 0.5f;
		}

		internal static void UpdateVisualsLayers(GameObject visual)
		{
			foreach (DvergerLightController instance in Instances)
			{
				if ((Object)(object)instance.m_visual == (Object)(object)visual)
				{
					instance.StartUpdateVisualLayers();
				}
			}
		}

		public static bool IsCircletLightEnabled(ItemData item)
		{
			return item != null && itemState.ContainsKey(item) && itemState[item].on;
		}

		public static void RegisterEffects()
		{
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Demister");
			object obj;
			if (itemPrefab == null)
			{
				obj = null;
			}
			else
			{
				Transform obj2 = itemPrefab.transform.Find("Particle System Force Field");
				obj = ((obj2 != null) ? ((Component)obj2).gameObject : null);
			}
			demisterForceField = (GameObject)obj;
			if (!Object.op_Implicit((Object)(object)overloadEffect))
			{
				Incinerator val = Resources.FindObjectsOfTypeAll<Incinerator>().FirstOrDefault();
				overloadEffect = CustomPrefabs.InitPrefabClone(val.m_lightingAOEs, "circletExtendedOverload");
				for (int num = overloadEffect.transform.childCount - 1; num > 0; num--)
				{
					Transform child = overloadEffect.transform.GetChild(num);
					switch (((Object)child).name)
					{
					case "AOE_AREA":
					case "Lighting":
					case "lightning":
					case "poff_ring":
					case "shockwave":
					case "vfx_RockHit (1)":
					case "AOE_ROD":
					case "Lighting_rod":
					case "Sparcs":
					case "sfx_shockwave (1)":
						child.parent = null;
						Object.Destroy((Object)(object)((Component)child).gameObject);
						break;
					case "glow":
						((Component)child).gameObject.SetActive(true);
						break;
					case "Point light (1)":
						overloadColor = ((Component)child).GetComponent<Light>().color;
						break;
					}
				}
			}
			if (Object.op_Implicit((Object)(object)overloadEffect) && Object.op_Implicit((Object)(object)ZNetScene.instance) && !ZNetScene.instance.m_namedPrefabs.ContainsKey(overloadItemHash))
			{
				ZNetScene.instance.m_prefabs.Add(overloadEffect);
				ZNetScene.instance.m_namedPrefabs.Add(overloadItemHash, overloadEffect);
			}
		}
	}
	[HarmonyPatch(typeof(VisEquipment), "AttachItem")]
	public static class VisEquipment_AttachItem_HumanoidAttachment
	{
		private static void Postfix(VisEquipment __instance, GameObject __result, int itemHash)
		{
			if (!CircletExtended.modEnabled.Value || itemHash != CircletItem.itemHashHelmetDverger || (Object)(object)__result == (Object)null)
			{
				return;
			}
			DvergerLightController component = __result.GetComponent<DvergerLightController>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			Light[] componentsInChildren = __result.GetComponentsInChildren<Light>(true);
			if (componentsInChildren.Length == 0)
			{
				return;
			}
			ItemData val = null;
			Player val2 = null;
			if (__instance.m_isPlayer)
			{
				val2 = ((Component)__instance).GetComponentInParent<Player>(true);
				if ((Object)(object)val2 == (Object)null)
				{
					return;
				}
				val = ((Humanoid)(object)val2).GetCirclet();
				if (val != null)
				{
					CircletItem.PatchCircletItemData(val);
				}
			}
			__instance.UpdateVisuals();
			__result.AddComponent<DvergerLightController>().Initialize(componentsInChildren[0], val2, val);
		}
	}
	[HarmonyPatch(typeof(ItemDrop), "Start")]
	public static class ItemDrop_Start_ItemDropAttachment
	{
		private static void Postfix(ItemDrop __instance)
		{
			if (CircletExtended.modEnabled.Value && CircletExtended.visualStateItemDrop.Value && CircletItem.IsCircletItem(__instance))
			{
				DvergerLightController componentInChildren = ((Component)__instance).GetComponentInChildren<DvergerLightController>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					Object.Destroy((Object)(object)componentInChildren);
				}
				Light[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Light>(true);
				if (componentsInChildren.Length != 0)
				{
					((Component)((Component)componentsInChildren[0]).gameObject.transform.parent).gameObject.AddComponent<DvergerLightController>().Initialize(componentsInChildren[0], null, __instance.m_itemData);
				}
			}
		}
	}
	[HarmonyPatch(typeof(ItemStand), "SetVisualItem")]
	public static class ItemStand_SetVisualItem_ItemStandAttachment
	{
		private static void Prefix(ItemStand __instance, GameObject ___m_visualItem, string ___m_visualName, int ___m_visualVariant, string itemName, int variant, ref bool __state)
		{
			if (CircletExtended.modEnabled.Value && CircletExtended.visualStateItemStand.Value && CircletItem.IsCircletItemName(__instance.GetAttachedItem()) && !((Object)(object)___m_visualItem != (Object)null) && (!(___m_visualName == itemName) || ___m_visualVariant != variant))
			{
				__state = true;
			}
		}

		private static void Postfix(GameObject ___m_visualItem, bool __state)
		{
			if (CircletExtended.modEnabled.Value && __state)
			{
				DvergerLightController componentInChildren = ___m_visualItem.GetComponentInChildren<DvergerLightController>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					Object.Destroy((Object)(object)componentInChildren);
				}
				Light[] componentsInChildren = ___m_visualItem.GetComponentsInChildren<Light>(true);
				if (componentsInChildren.Length != 0)
				{
					___m_visualItem.AddComponent<DvergerLightController>().Initialize(componentsInChildren[0]);
				}
			}
		}
	}
	[HarmonyPatch(typeof(ArmorStand), "SetVisualItem")]
	public static class ArmorStand_SetVisualItem_ArmorStandAttachment
	{
		private static void Prefix(int index, List<ArmorStandSlot> ___m_slots, string itemName, int variant, ref bool __state)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Invalid comparison between Unknown and I4
			if (CircletExtended.modEnabled.Value && CircletExtended.visualStateArmorStand.Value && CircletItem.IsCircletItemName(itemName))
			{
				ArmorStandSlot val = ___m_slots[index];
				if ((int)val.m_slot == 6 && (!(val.m_visualName == itemName) || val.m_visualVariant != variant))
				{
					__state = true;
				}
			}
		}

		private static void Postfix(int index, VisEquipment ___m_visEquipment, List<ArmorStandSlot> ___m_slots, bool __state)
		{
			if (!CircletExtended.modEnabled.Value || !__state)
			{
				return;
			}
			___m_visEquipment.UpdateVisuals();
			ArmorStandSlot val = ___m_slots[index];
			if (!CircletItem.IsCircletItemName(val.m_visualName))
			{
				return;
			}
			GameObject helmetItemInstance = ___m_visEquipment.m_helmetItemInstance;
			if (!((Object)(object)helmetItemInstance == (Object)null))
			{
				DvergerLightController componentInChildren = helmetItemInstance.GetComponentInChildren<DvergerLightController>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					Object.Destroy((Object)(object)componentInChildren);
				}
				Light[] componentsInChildren = helmetItemInstance.GetComponentsInChildren<Light>(true);
				if (componentsInChildren.Length != 0)
				{
					helmetItemInstance.AddComponent<DvergerLightController>().Initialize(componentsInChildren[0], null, null, index);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Humanoid), "SetupEquipment")]
	public static class Humanoid_SetupVisEquipment_AttachLayersFix
	{
		private static void Postfix(Humanoid __instance)
		{
			DvergerLightController.UpdateVisualsLayers(((Character)__instance).m_visual);
		}
	}
}
namespace Microsoft.CodeAnalysis
{
	[<c29e1d1a-73fa-4ad3-9a38-4c8ec7993d9f>Embedded]
	[CompilerGenerated]
	internal sealed class <c29e1d1a-73fa-4ad3-9a38-4c8ec7993d9f>EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[<c29e1d1a-73fa-4ad3-9a38-4c8ec7993d9f>Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	[CompilerGenerated]
	internal sealed class <da2d192c-7c94-4c2d-874d-30778f71665c>NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public <da2d192c-7c94-4c2d-874d-30778f71665c>NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public <da2d192c-7c94-4c2d-874d-30778f71665c>NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	[<c29e1d1a-73fa-4ad3-9a38-4c8ec7993d9f>Embedded]
	internal sealed class <0f003606-83d5-4149-9d80-604b2b496ad7>NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public <0f003606-83d5-4149-9d80-604b2b496ad7>NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[<c29e1d1a-73fa-4ad3-9a38-4c8ec7993d9f>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 ServerSync
{
	[<da2d192c-7c94-4c2d-874d-30778f71665c>Nullable(0)]
	[PublicAPI]
	[<0f003606-83d5-4149-9d80-604b2b496ad7>NullableContext(1)]
	internal abstract class OwnConfigEntryBase
	{
		[<da2d192c-7c94-4c2d-874d-30778f71665c>Nullable(2)]
		public object LocalBaseValue;

		public bool SynchronizedConfig = true;

		public abstract ConfigEntryBase BaseConfig { get; }
	}
	[PublicAPI]
	[<da2d192c-7c94-4c2d-874d-30778f71665c>Nullable(0)]
	[<0f003606-83d5-4149-9d80-604b2b496ad7>NullableContext(1)]
	internal class SyncedConfigEntry<[<da2d192c-7c94-4c2d-874d-30778f71665c>Nullable(2)] T> : OwnConfigEntryBase
	{
		public readonly ConfigEntry<T> SourceConfig;

		public override ConfigEntryBase BaseConfig => (ConfigEntryBase)(object)SourceConfig;

		public T Value
		{
			get
			{
				return SourceConfig.Value;
			}
			set
			{
				SourceConfig.Value = value;
			}
		}

		public SyncedConfigEntry(ConfigEntry<T> sourceConfig)
		{
			SourceConfig = sourceConfig;
		}

		public void AssignLocalValue(T value)
		{
			if (LocalBaseValue == null)
			{
				Value = value;
			}
			else
			{
				LocalBaseValue = value;
			}
		}
	}
	[<da2d192c-7c94-4c2d-874d-30778f71665c>Nullable(0)]
	[<0f003606-83d5-4149-9d80-604b2b496ad7>NullableContext(2)]
	internal abstract class CustomSyncedValueBase
	{
		public object LocalBaseValue;

		[<da2d192c-7c94-4c2d-874d-30778f71665c>Nullable(1)]
		public readonly string Identifier;

		[<da2d192c-7c94-4c2d-874d-30778f71665c>Nullable(1)]
		public readonly Type Type;

		private object boxedValue;

		protected bool localIsOwner;

		public readonly int Priority;

		public object BoxedValue
		{
			get
			{
				return boxedValue;
			}
			set
			{
				boxedValue = value;
				this.ValueChanged?.Invoke();
			}
		}

		public event Action ValueChanged;

		[<0f003606-83d5-4149-9d80-604b2b496ad7>NullableContext(1)]
		protected CustomSyncedValueBase(ConfigSync configSync, string identifier, Type type, int priority)
		{
			Priority = priority;
			Identifier = identifier;
			Type = type;
			configSync.AddCustomValue(this);
			localIsOwner = configSync.IsSourceOfTruth;
			configSync.SourceOfTruthChanged += delegate(bool truth)
			{
				localIsOwner = truth;
			};
		}
	}
	[PublicAPI]
	[<0f003606-83d5-4149-9d80-604b2b496ad7>NullableContext(1)]
	[<da2d192c-7c94-4c2d-874d-30778f71665c>Nullable(0)]
	internal sealed class CustomSyncedValue<[<da2d192c-7c94-4c2d-874d-30778f71665c>Nullable(2)] T> : CustomSyncedValueBase
	{
		public T Value
		{
			get
			{
				return (T)base.BoxedValue;
			}
			set
			{
				base.BoxedValue = value;
			}
		}

		public CustomSyncedValue(ConfigSync configSync, string identifier, T value = default(T), int priority = 0)
			: base(configSync, identifier, typeof(T), priority)
		{
			Value = value;
		}

		public void AssignLocalValue(T value)
		{
			if (localIsOwner)
			{
				Value = value;
			}
			else
			{
				LocalBaseValue = value;
			}
		}
	}
	internal class ConfigurationManagerAttributes
	{
		[UsedImplicitly]
		public bool? ReadOnly = false;
	}
	[PublicAPI]
	[<da2d192c-7c94-4c2d-874d-30778f71665c>Nullable(0)]
	[<0f003606-83d5-4149-9d80-604b2b496ad7>NullableContext(1)]
	internal class ConfigSync
	{
		[HarmonyPatch(typeof(ZRpc), "HandlePackage")]
		[<0f003606-83d5-4149-9d80-604b2b496ad7>NullableContext(0)]
		private static class SnatchCurrentlyHandlingRPC
		{
			[<da2d192c-7c94-4c2d-874d-30778f71665c>Nullable(2)]
			public static ZRpc currentRpc;

			[<0f003606-83d5-4149-9d80-604b2b496ad7>NullableContext(1)]
			[HarmonyPrefix]
			private static void Prefix(ZRpc __instance)
			{
				currentRpc = __instance;
			}
		}

		[HarmonyPatch(typeof(ZNet), "Awake")]
		[<0f003606-83d5-4149-9d80-604b2b496ad7>NullableContext(0)]
		internal static class RegisterRPCPatch
		{
			[<0f003606-83d5-4149-9d80-604b2b496ad7>NullableContext(1)]
			[HarmonyPostfix]
			private static void Postfix(ZNet __instance)
			{
				isServer = __instance.IsServer();
				foreach (ConfigSync configSync2 in configSyncs)
				{
					ZRoutedRpc.instance.Register<ZPackage>(configSync2.Name + " ConfigSync", (Action<long, ZPackage>)configSync2.RPC_FromOtherClientConfigSync);
					if (isServer)
					{
						configSync2.InitialSyncDone = true;
						Debug.Log((object)("Registered '" + configSync2.Name + " ConfigSync' RPC - waiting for incoming connections"));
					}
				}
				if (isServer)
				{
					((MonoBehaviour)__instance).StartCoroutine(WatchAdminListChanges());
				}
				[<0f003606-83d5-4149-9d80-604b2b496ad7>NullableContext(1)]
				static void SendAdmin(List<ZNetPeer> peers, bool isAdmin)
				{
					ZPackage package = ConfigsToPackage(null, null, new PackageEntry[1]
					{
						new PackageEntry
						{
							section = "Internal",
							key = "lockexempt",
							type = typeof(bool),
							value = isAdmin
						}
					});
					ConfigSync configSync = configSyncs.First();
					if (configSync != null)
					{
						((MonoBehaviour)ZNet.instance).StartCoroutine(configSync.sendZPackage(peers, package));
					}
				}
				[<0f003606-83d5-4149-9d80-604b2b496ad7>NullableContext(1)]
				static IEnumerator WatchAdminListChanges()