Decompiled source of BeastMarketOutpost v1.0.0

BeastMarketOutpost.dll

Decompiled 4 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BeastMarketOutpost.Core;
using BeastMarketOutpost.Managers;
using BeastMarketOutpost.Patches;
using BeastMarketOutpost.Registration;
using BeastMarketOutpost.Shaders;
using BeastMarketOutpost.TownQuests;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CreatureManager;
using HarmonyLib;
using ItemManager;
using JetBrains.Annotations;
using LocationManager;
using Microsoft.CodeAnalysis;
using ServerSync;
using SoftReferenceableAssets;
using Splatform;
using TMPro;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BeastMarketOutpost")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Yggdrah")]
[assembly: AssemblyProduct("BeastMarketOutpost")]
[assembly: AssemblyCopyright("Copyright \ufffd  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("E0E2F92E-557C-4A05-9D89-AA92A0BD75C4")]
[assembly: AssemblyFileVersion("1.0.0")]
[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]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
public static class ItemManagerVersion
{
	public const string Version = "1.2.9";
}
public class MonsterMapIcon : MonoBehaviour
{
	public string iconName = "";

	public Sprite iconSprite;

	private PinData mapMarker;

	private Character monster;

	private void Start()
	{
		monster = ((Component)this).GetComponent<Character>();
		if ((Object)(object)monster != (Object)null && monster.IsTamed())
		{
			AddMapMarker();
		}
	}

	private void Update()
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		if (mapMarker != null && (Object)(object)monster != (Object)null && monster.IsTamed())
		{
			mapMarker.m_pos = ((Component)this).transform.position;
		}
	}

	private void AddMapMarker()
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Minimap.instance != (Object)null)
		{
			mapMarker = Minimap.instance.AddPin(((Component)this).transform.position, (PinType)3, iconName, false, false, 0L, default(PlatformUserID));
			mapMarker.m_icon = iconSprite;
		}
	}

	private void OnDestroy()
	{
		if ((Object)(object)Minimap.instance != (Object)null && mapMarker != null)
		{
			Minimap.instance.RemovePin(mapMarker);
		}
	}
}
namespace PieceManager
{
	[PublicAPI]
	public static class MaterialReplacer
	{
		public enum ShaderType
		{
			PieceShader,
			VegetationShader,
			RockShader,
			RugShader,
			GrassShader,
			CustomCreature,
			UseUnityShader
		}

		private static readonly Dictionary<GameObject, bool> ObjectToSwap;

		private static readonly Dictionary<string, Material> OriginalMaterials;

		private static readonly Dictionary<GameObject, ShaderType> ObjectsForShaderReplace;

		private static readonly HashSet<Shader> CachedShaders;

		private static bool hasRun;

		static MaterialReplacer()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			CachedShaders = new HashSet<Shader>();
			hasRun = false;
			OriginalMaterials = new Dictionary<string, Material>();
			ObjectToSwap = new Dictionary<GameObject, bool>();
			ObjectsForShaderReplace = new Dictionary<GameObject, ShaderType>();
			Harmony val = new Harmony("org.bepinex.helpers.PieceManager");
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ZoneSystem), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(MaterialReplacer), "ReplaceAllMaterialsWithOriginal", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		public static void RegisterGameObjectForShaderSwap(GameObject go, ShaderType type)
		{
			if (!ObjectsForShaderReplace.ContainsKey(go))
			{
				ObjectsForShaderReplace.Add(go, type);
			}
		}

		public static void RegisterGameObjectForMatSwap(GameObject go, bool isJotunnMock = false)
		{
			if (!((Object)(object)go == (Object)null) && !ObjectToSwap.ContainsKey(go))
			{
				ObjectToSwap.Add(go, isJotunnMock);
			}
		}

		private static void GetAllMaterials()
		{
			Material[] array = Resources.FindObjectsOfTypeAll<Material>();
			foreach (Material val in array)
			{
				OriginalMaterials[((Object)val).name] = val;
			}
		}

		[HarmonyPriority(700)]
		private static void ReplaceAllMaterialsWithOriginal()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)SystemInfo.graphicsDeviceType == 4 || hasRun)
			{
				return;
			}
			if (OriginalMaterials.Count == 0)
			{
				GetAllMaterials();
			}
			foreach (KeyValuePair<GameObject, bool> item in ObjectToSwap)
			{
				GameObject key = item.Key;
				bool value = item.Value;
				ProcessGameObjectMaterials(key, value);
			}
			AssetBundle[] array = Resources.FindObjectsOfTypeAll<AssetBundle>();
			AssetBundle[] array2 = array;
			foreach (AssetBundle val in array2)
			{
				IEnumerable<Shader> enumerable3;
				try
				{
					IEnumerable<Shader> enumerable2;
					if (!val.isStreamedSceneAssetBundle || !Object.op_Implicit((Object)(object)val))
					{
						IEnumerable<Shader> enumerable = val.LoadAllAssets<Shader>();
						enumerable2 = enumerable;
					}
					else
					{
						enumerable2 = from shader in ((IEnumerable<string>)val.GetAllAssetNames()).Select((Func<string, Shader>)val.LoadAsset<Shader>)
							where (Object)(object)shader != (Object)null
							select shader;
					}
					enumerable3 = enumerable2;
				}
				catch (Exception)
				{
					continue;
				}
				if (enumerable3 == null)
				{
					continue;
				}
				foreach (Shader item2 in enumerable3)
				{
					CachedShaders.Add(item2);
				}
			}
			foreach (KeyValuePair<GameObject, ShaderType> item3 in ObjectsForShaderReplace)
			{
				GameObject key2 = item3.Key;
				ShaderType value2 = item3.Value;
				ProcessGameObjectShaders(key2, value2);
			}
			hasRun = true;
		}

		private static void ProcessGameObjectMaterials(GameObject go, bool isJotunnMock)
		{
			Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
			Renderer[] array = componentsInChildren;
			foreach (Renderer val in array)
			{
				Material[] sharedMaterials = val.sharedMaterials.Select((Material material) => ((Object)(object)material == (Object)null) ? null : ReplaceMaterial(material, isJotunnMock)).ToArray();
				val.sharedMaterials = sharedMaterials;
			}
		}

		private static Material ReplaceMaterial(Material originalMaterial, bool isJotunnMock)
		{
			if ((Object)(object)originalMaterial == (Object)null)
			{
				return null;
			}
			string text = (isJotunnMock ? "JVLmock_" : "_REPLACE_");
			if (!((Object)originalMaterial).name.StartsWith(text, StringComparison.Ordinal))
			{
				return originalMaterial;
			}
			string text2 = ((Object)originalMaterial).name.Replace(" (Instance)", "").Replace(text, "");
			if (OriginalMaterials.TryGetValue(text2, out Material value))
			{
				return value;
			}
			Debug.LogWarning((object)("No suitable material found to replace: " + text2));
			return originalMaterial;
		}

		private static void ProcessGameObjectShaders(GameObject go, ShaderType shaderType)
		{
			Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
			Renderer[] array = componentsInChildren;
			foreach (Renderer val in array)
			{
				Material[] sharedMaterials = val.sharedMaterials;
				foreach (Material val2 in sharedMaterials)
				{
					if ((Object)(object)val2 != (Object)null)
					{
						val2.shader = GetShaderForType(val2.shader, shaderType, ((Object)val2.shader).name);
					}
				}
			}
		}

		private static Shader GetShaderForType(Shader orig, ShaderType shaderType, string originalShaderName)
		{
			return (Shader)(shaderType switch
			{
				ShaderType.PieceShader => FindShaderWithName(orig, "Custom/Piece"), 
				ShaderType.VegetationShader => FindShaderWithName(orig, "Custom/Vegetation"), 
				ShaderType.RockShader => FindShaderWithName(orig, "Custom/StaticRock"), 
				ShaderType.RugShader => FindShaderWithName(orig, "Custom/Rug"), 
				ShaderType.GrassShader => FindShaderWithName(orig, "Custom/Grass"), 
				ShaderType.CustomCreature => FindShaderWithName(orig, "Custom/Creature"), 
				ShaderType.UseUnityShader => FindShaderWithName(orig, ((Object)(object)FindShaderWithName(orig, originalShaderName) != (Object)null) ? originalShaderName : "ToonDeferredShading2017"), 
				_ => FindShaderWithName(orig, "Standard"), 
			});
		}

		public static Shader FindShaderWithName(Shader origShader, string name)
		{
			foreach (Shader cachedShader in CachedShaders)
			{
				if (((Object)cachedShader).name == name)
				{
					return cachedShader;
				}
			}
			return origShader;
		}
	}
}
namespace LocationManager
{
	public enum ShowIcon
	{
		Always,
		Never,
		Explored
	}
	public enum Rotation
	{
		Fixed,
		Random,
		Slope
	}
	[PublicAPI]
	public struct Range
	{
		public float min;

		public float max;

		public Range(float min, float max)
		{
			this.min = min;
			this.max = max;
		}
	}
	[PublicAPI]
	public class Location
	{
		private class ConfigurationManagerAttributes
		{
			[UsedImplicitly]
			public int? Order;
		}

		public static class PrefabManager
		{
			private struct BundleId
			{
				[UsedImplicitly]
				public string assetBundleFileName;

				[UsedImplicitly]
				public string folderName;
			}

			private static readonly Dictionary<BundleId, AssetBundle> bundleCache = new Dictionary<BundleId, AssetBundle>();

			public static AssetBundle RegisterAssetBundle(string assetBundleFileName, string folderName = "assets")
			{
				BundleId key = new BundleId
				{
					assetBundleFileName = assetBundleFileName,
					folderName = folderName
				};
				if (bundleCache.TryGetValue(key, out AssetBundle value))
				{
					Debug.LogWarning((object)("AssetBundle " + assetBundleFileName + " in folder " + folderName + " is already loaded."));
					return value;
				}
				AssetBundle val;
				try
				{
					val = ((IEnumerable<AssetBundle>)Resources.FindObjectsOfTypeAll<AssetBundle>()).FirstOrDefault((Func<AssetBundle, bool>)((AssetBundle a) => ((Object)a).name == assetBundleFileName)) ?? AssetBundle.LoadFromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream(Assembly.GetExecutingAssembly().GetName().Name + ((folderName == "") ? "" : ".") + folderName + "." + assetBundleFileName));
					if ((Object)(object)val == (Object)null)
					{
						throw new FileNotFoundException("AssetBundle " + assetBundleFileName + " not found in folder " + folderName + ".");
					}
					bundleCache[key] = val;
				}
				catch (Exception ex)
				{
					Debug.LogError((object)("Failed to load AssetBundle " + assetBundleFileName + " in folder " + folderName + ": " + ex.Message));
					throw;
				}
				return val;
			}

			[PublicAPI]
			public static AssetID AssetIDFromObject(Object obj)
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				int instanceID = obj.GetInstanceID();
				return new AssetID(1u, 1u, 1u, (uint)instanceID);
			}

			public static SoftReference<T> AddLoadedSoftReferenceAsset<T>(T obj) where T : Object
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0104: Unknown result type (might be due to invalid IL or missing references)
				//IL_011c: Unknown result type (might be due to invalid IL or missing references)
				//IL_011e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0122: Unknown result type (might be due to invalid IL or missing references)
				AssetBundleLoader instance = AssetBundleLoader.Instance;
				instance.m_bundleNameToLoaderIndex[""] = 0;
				AssetID val = AssetIDFromObject((Object)(object)obj);
				string text = ((Object)obj).name;
				int num = 1;
				while (instance.m_assetIDToLoaderIndex.ContainsKey(val))
				{
					text = ((Object)obj).name + "_" + num;
					num++;
				}
				AssetLoader val2 = default(AssetLoader);
				((AssetLoader)(ref val2))..ctor(val, new AssetLocation("", text));
				val2.m_asset = (Object)(object)obj;
				val2.m_referenceCounter = new ReferenceCounter(2u);
				val2.m_shouldBeLoaded = true;
				AssetLoader val3 = val2;
				int count = instance.m_assetIDToLoaderIndex.Count;
				if (count >= instance.m_assetLoaders.Length)
				{
					Array.Resize(ref instance.m_assetLoaders, instance.m_assetIDToLoaderIndex.Count + 256);
				}
				instance.m_assetLoaders[count] = val3;
				instance.m_assetIDToLoaderIndex[val] = count;
				SoftReference<T> result = default(SoftReference<T>);
				result..ctor(val);
				result.m_name = ((Object)obj).name;
				return result;
			}
		}

		public bool CanSpawn = true;

		public Biome Biome = (Biome)1;

		[Description("If the location should spawn more towards the edge of the biome or towards the center.\nUse 'Edge' to make it spawn towards the edge.\nUse 'Median' to make it spawn towards the center.\nUse 'Everything' if it doesn't matter.")]
		public BiomeArea SpawnArea = (BiomeArea)3;

		[Description("Maximum number of locations to spawn in.\nDoes not mean that this many locations will spawn. But Valheim will try its best to spawn this many, if there is space.")]
		public int Count = 1;

		[Description("If set to true, this location will be prioritized over other locations, if they would spawn in the same area.")]
		public bool Prioritize = false;

		[Description("If set to true, Valheim will try to spawn your location as close to the center of the map as possible.")]
		public bool PreferCenter = false;

		[Description("If set to true, all other locations will be deleted, once the first one has been discovered by a player.")]
		public bool Unique = false;

		[Description("The name of the group of the location, used by the minimum distance from group setting.")]
		public string GroupName;

		[Description("Locations in the same group will keep at least this much distance between each other.")]
		public float MinimumDistanceFromGroup = 0f;

		[Description("When to show the map icon of the location. Requires an icon to be set.\nUse 'Never' to not show a map icon for the location.\nUse 'Always' to always show a map icon for the location.\nUse 'Explored' to start showing a map icon for the location as soon as a player has explored the area.")]
		public ShowIcon ShowMapIcon = ShowIcon.Never;

		public readonly GameObject Prefab;

		private string? mapIconName = null;

		[Description("Sets the map icon for the location.")]
		public Sprite? MapIconSprite = null;

		[Description("How to rotate the location.\nUse 'Fixed' to use the rotation of the prefab.\nUse 'Random' to randomize the rotation.\nUse 'Slope' to rotate the location along a possible slope.")]
		public Rotation Rotation = Rotation.Random;

		[Description("The minimum and maximum height difference of the terrain below the location.")]
		public Range HeightDelta = new Range(0f, 2f);

		[Description("If the location should spawn near water.")]
		public bool SnapToWater = false;

		[Description("If the location should spawn in a forest.\nEverything above 1.15 is considered a forest by Valheim.\n2.19 is considered a thick forest by Valheim.")]
		public Range ForestThreshold = new Range(0f, 2.19f);

		[Description("Minimum and maximum range from the center of the map for the location.")]
		public Range SpawnDistance = new Range(0f, 10000f);

		[Description("Minimum and maximum altitude for the location.")]
		public Range SpawnAltitude = new Range(-1000f, 1000f);

		[Description("If set to true, vegetation is removed inside the location exterior radius.")]
		public bool ClearArea = false;

		[Description("Adds a creature to a spawner that has been added to the location prefab.")]
		public Dictionary<string, string> CreatureSpawner = new Dictionary<string, string>();

		public static bool ConfigurationEnabled;

		private readonly Location location;

		private string folderName = "";

		private AssetBundle? assetBundle;

		private static readonly List<Location> registeredLocations;

		private static Dictionary<Location, SoftReference<GameObject>>? softReferences;

		private static bool firstStartup;

		private static BaseUnityPlugin? _plugin;

		private static bool hasConfigSync;

		private static object? _configSync;

		[Description("Sets the map icon for the location.")]
		public string? MapIcon
		{
			get
			{
				return mapIconName;
			}
			set
			{
				mapIconName = value;
				MapIconSprite = ((mapIconName == null) ? null : loadSprite(mapIconName));
			}
		}

		private static BaseUnityPlugin plugin
		{
			get
			{
				//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b2: Expected O, but got Unknown
				if (_plugin == null)
				{
					IEnumerable<TypeInfo> source;
					try
					{
						source = Assembly.GetExecutingAssembly().DefinedTypes.ToList();
					}
					catch (ReflectionTypeLoadException ex)
					{
						source = from t in ex.Types
							where t != null
							select t.GetTypeInfo();
					}
					_plugin = (BaseUnityPlugin)Chainloader.ManagerObject.GetComponent((Type)source.First((TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t)));
				}
				return _plugin;
			}
		}

		private static object? configSync
		{
			get
			{
				if (_configSync == null && hasConfigSync)
				{
					Type type = Assembly.GetExecutingAssembly().GetType("ServerSync.ConfigSync");
					if ((object)type != null)
					{
						_configSync = Activator.CreateInstance(type, plugin.Info.Metadata.GUID + " ItemManager");
						type.GetField("CurrentVersion").SetValue(_configSync, plugin.Info.Metadata.Version.ToString());
						type.GetProperty("IsLocked").SetValue(_configSync, true);
					}
					else
					{
						hasConfigSync = false;
					}
				}
				return _configSync;
			}
		}

		public Location(string assetBundleFileName, string prefabName, string folderName = "assets")
			: this(PrefabManager.RegisterAssetBundle(assetBundleFileName, folderName), prefabName)
		{
			this.folderName = folderName;
		}

		public Location(AssetBundle bundle, string prefabName)
			: this(bundle.LoadAsset<GameObject>(prefabName))
		{
			assetBundle = bundle;
		}

		public Location(GameObject location)
			: this(location.GetComponent<Location>())
		{
			if ((Object)(object)this.location == (Object)null)
			{
				throw new ArgumentNullException("location", "The GameObject does not have a location component.");
			}
		}

		public Location(Location location)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			this.location = location;
			Prefab = ((Component)this.location).gameObject;
			GroupName = ((Object)location).name;
			registeredLocations.Add(this);
		}

		private Sprite loadSprite(string name)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				AssetBundle? obj = assetBundle;
				Sprite val = ((obj != null) ? obj.LoadAsset<Sprite>(name) : null);
				if (val != null)
				{
					return val;
				}
				AssetBundle? obj2 = assetBundle;
				Texture2D val2 = ((obj2 != null) ? obj2.LoadAsset<Texture2D>(name) : null);
				if (val2 != null)
				{
					return Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f));
				}
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("Failed to load sprite '" + name + "': " + ex.Message));
			}
			throw new FileNotFoundException("Could not find sprite or texture named " + name + " in the asset bundle");
		}

		private static void AddLocationToZoneSystem(ZoneSystem __instance)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Expected O, but got Unknown
			if (softReferences == null)
			{
				softReferences = registeredLocations.ToDictionary((Location l) => l, (Location l) => PrefabManager.AddLoadedSoftReferenceAsset<GameObject>(((Component)l.location).gameObject));
			}
			foreach (Location registeredLocation in registeredLocations)
			{
				__instance.m_locations.Add(new ZoneLocation
				{
					m_prefabName = ((Object)registeredLocation.location).name,
					m_prefab = softReferences[registeredLocation],
					m_enable = registeredLocation.CanSpawn,
					m_biome = registeredLocation.Biome,
					m_biomeArea = registeredLocation.SpawnArea,
					m_quantity = registeredLocation.Count,
					m_prioritized = registeredLocation.Prioritize,
					m_centerFirst = registeredLocation.PreferCenter,
					m_unique = registeredLocation.Unique,
					m_group = registeredLocation.GroupName,
					m_minDistanceFromSimilar = registeredLocation.MinimumDistanceFromGroup,
					m_iconAlways = (registeredLocation.ShowMapIcon == ShowIcon.Always),
					m_iconPlaced = (registeredLocation.ShowMapIcon == ShowIcon.Explored),
					m_randomRotation = (registeredLocation.Rotation == Rotation.Random),
					m_slopeRotation = (registeredLocation.Rotation == Rotation.Slope),
					m_snapToWater = registeredLocation.SnapToWater,
					m_minTerrainDelta = registeredLocation.HeightDelta.min,
					m_maxTerrainDelta = registeredLocation.HeightDelta.max,
					m_inForest = true,
					m_forestTresholdMin = registeredLocation.ForestThreshold.min,
					m_forestTresholdMax = registeredLocation.ForestThreshold.max,
					m_minDistance = registeredLocation.SpawnDistance.min,
					m_maxDistance = registeredLocation.SpawnDistance.max,
					m_minAltitude = registeredLocation.SpawnAltitude.min,
					m_maxAltitude = registeredLocation.SpawnAltitude.max,
					m_clearArea = registeredLocation.ClearArea,
					m_exteriorRadius = registeredLocation.location.m_exteriorRadius,
					m_interiorRadius = registeredLocation.location.m_interiorRadius
				});
			}
			Object.DestroyImmediate((Object)(object)__instance.m_locationProxyPrefab.GetComponent<LocationProxy>());
			__instance.m_locationProxyPrefab.AddComponent<LocationProxy>();
		}

		private static void AddLocationZNetViewsToZNetScene(ZNetScene __instance)
		{
			foreach (ZNetView item in registeredLocations.SelectMany((Location l) => ((Component)l.location).GetComponentsInChildren<ZNetView>(true)))
			{
				if (__instance.m_namedPrefabs.ContainsKey(StringExtensionMethods.GetStableHashCode(item.GetPrefabName())))
				{
					string prefabName = Utils.GetPrefabName(__instance.m_namedPrefabs[StringExtensionMethods.GetStableHashCode(item.GetPrefabName())]);
					if (item.GetPrefabName() != prefabName)
					{
						Debug.LogError((object)$"Found hash collision for names of prefabs {item.GetPrefabName()} and {prefabName} in {Assembly.GetExecutingAssembly()}. Skipping.");
					}
				}
				else
				{
					__instance.m_prefabs.Add(((Component)item).gameObject);
					__instance.m_namedPrefabs[StringExtensionMethods.GetStableHashCode(item.GetPrefabName())] = ((Component)item).gameObject;
				}
			}
			foreach (Location registeredLocation in registeredLocations)
			{
				CreatureSpawner[] componentsInChildren = ((Component)((Component)registeredLocation.location).transform).GetComponentsInChildren<CreatureSpawner>();
				foreach (CreatureSpawner val in componentsInChildren)
				{
					if (registeredLocation.CreatureSpawner.TryGetValue(((Object)val).name, out string value))
					{
						val.m_creaturePrefab = __instance.GetPrefab(value);
					}
				}
			}
		}

		private static void AddMinimapIcons(Minimap __instance)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			foreach (Location registeredLocation in registeredLocations)
			{
				Sprite mapIconSprite = registeredLocation.MapIconSprite;
				if (mapIconSprite != null)
				{
					__instance.m_locationIcons.Add(new LocationSpriteData
					{
						m_icon = mapIconSprite,
						m_name = ((Object)registeredLocation.location).name
					});
				}
			}
		}

		internal static void Patch_FejdStartup()
		{
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Expected O, but got Unknown
			if (ConfigurationEnabled && firstStartup)
			{
				bool saveOnConfigSet = plugin.Config.SaveOnConfigSet;
				plugin.Config.SaveOnConfigSet = false;
				foreach (Location location in registeredLocations)
				{
					int num = 0;
					foreach (KeyValuePair<string, string> kv in location.CreatureSpawner)
					{
						ConfigEntry<string> spawnerCreature = config(((Object)location.location).name, kv.Key + " spawns", kv.Value, new ConfigDescription("", (AcceptableValueBase)null, new object[1]
						{
							new ConfigurationManagerAttributes
							{
								Order = (num -= 1)
							}
						}));
						spawnerCreature.SettingChanged += delegate
						{
							location.CreatureSpawner[kv.Key] = spawnerCreature.Value;
							if (Object.op_Implicit((Object)(object)ZNetScene.instance))
							{
								CreatureSpawner val = ((IEnumerable<CreatureSpawner>)((Component)((Component)location.location).transform).GetComponentsInChildren<CreatureSpawner>()).FirstOrDefault((Func<CreatureSpawner, bool>)((CreatureSpawner s) => ((Object)s).name == kv.Key));
								if (val != null)
								{
									val.m_creaturePrefab = ZNetScene.instance.GetPrefab(spawnerCreature.Value);
								}
							}
						};
					}
				}
				if (saveOnConfigSet)
				{
					plugin.Config.SaveOnConfigSet = true;
					plugin.Config.Save();
				}
			}
			firstStartup = false;
		}

		static Location()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Expected O, but got Unknown
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected O, but got Unknown
			ConfigurationEnabled = true;
			registeredLocations = new List<Location>();
			firstStartup = true;
			hasConfigSync = true;
			Harmony val = new Harmony("org.bepinex.helpers.LocationManager");
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ZNetScene), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Location), "AddLocationZNetViewsToZNetScene", (Type[])null, (Type[])null), 100, (string[])null, (string[])null, (bool?)null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ZoneSystem), "SetupLocations", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Location), "AddLocationToZoneSystem", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Minimap), "Awake", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Location), "AddMinimapIcons", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(FejdStartup), "Awake", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Location), "Patch_FejdStartup", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static ConfigEntry<T> config<T>(string group, string name, T value, ConfigDescription description)
		{
			ConfigEntry<T> val = plugin.Config.Bind<T>(group, name, value, description);
			configSync?.GetType().GetMethod("AddConfigEntry").MakeGenericMethod(typeof(T))
				.Invoke(configSync, new object[1] { val });
			return val;
		}

		private static ConfigEntry<T> config<T>(string group, string name, T value, string description)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()));
		}
	}
}
namespace ItemManager
{
	[PublicAPI]
	public enum CraftingTable
	{
		Disabled,
		Inventory,
		[InternalName("piece_workbench")]
		Workbench,
		[InternalName("piece_cauldron")]
		Cauldron,
		[InternalName("piece_MeadCauldron")]
		MeadCauldron,
		[InternalName("forge")]
		Forge,
		[InternalName("piece_artisanstation")]
		ArtisanTable,
		[InternalName("piece_stonecutter")]
		StoneCutter,
		[InternalName("piece_magetable")]
		MageTable,
		[InternalName("piece_preptable")]
		PrepTable,
		[InternalName("blackforge")]
		BlackForge,
		Custom
	}
	[PublicAPI]
	public enum ConversionPiece
	{
		Disabled,
		[InternalName("smelter")]
		Smelter,
		[InternalName("charcoal_kiln")]
		CharcoalKiln,
		[InternalName("blastfurnace")]
		BlastFurnace,
		[InternalName("windmill")]
		Windmill,
		[InternalName("piece_spinningwheel")]
		SpinningWheel,
		[InternalName("eitrrefinery")]
		EitrRefinery,
		Custom
	}
	public class InternalName : Attribute
	{
		public readonly string internalName;

		public InternalName(string internalName)
		{
			this.internalName = internalName;
		}
	}
	[PublicAPI]
	public class RequiredResourceList
	{
		public readonly List<Requirement> Requirements = new List<Requirement>();

		public bool Free;

		public void Add(string itemName, int amount, int quality = 0)
		{
			Requirements.Add(new Requirement
			{
				itemName = itemName,
				amount = amount,
				quality = quality
			});
		}

		public void Add(string itemName, ConfigEntry<int> amountConfig, int quality = 0)
		{
			Requirements.Add(new Requirement
			{
				itemName = itemName,
				amountConfig = amountConfig,
				quality = quality
			});
		}
	}
	[PublicAPI]
	public class CraftingStationList
	{
		public readonly List<CraftingStationConfig> Stations = new List<CraftingStationConfig>();

		public void Add(CraftingTable table, int level)
		{
			Stations.Add(new CraftingStationConfig
			{
				Table = table,
				level = level
			});
		}

		public void Add(string customTable, int level)
		{
			Stations.Add(new CraftingStationConfig
			{
				Table = CraftingTable.Custom,
				level = level,
				custom = customTable
			});
		}
	}
	[PublicAPI]
	public class ItemRecipe
	{
		public readonly CraftingStationList Crafting = new CraftingStationList();

		public readonly RequiredResourceList RequiredItems = new RequiredResourceList();

		public readonly RequiredResourceList RequiredUpgradeItems = new RequiredResourceList();

		public int CraftAmount = 1;

		public float QualityResultAmountMultiplier = 1f;

		public ConfigEntryBase? RecipeIsActive;

		public bool RequireOnlyOneIngredient;
	}
	[PublicAPI]
	public class Trade
	{
		public uint Price;

		public string? RequiredGlobalKey;

		public uint Stack = 1u;

		public Trader Trader = Trader.None;
	}
	[PublicAPI]
	[Flags]
	public enum Trader
	{
		None = 0,
		Haldor = 1,
		Hildir = 2,
		BogWitch = 4
	}
	public struct Requirement
	{
		public string itemName;

		public int amount;

		public ConfigEntry<int>? amountConfig;

		[Description("Set to a non-zero value to apply the requirement only for a specific quality")]
		public int quality;
	}
	public struct CraftingStationConfig
	{
		public CraftingTable Table;

		public int level;

		public string? custom;
	}
	[Flags]
	public enum Configurability
	{
		Disabled = 0,
		Recipe = 1,
		Stats = 2,
		Drop = 4,
		Trader = 8,
		Full = 0xF
	}
	[PublicAPI]
	public class DropTargets
	{
		public readonly List<DropTarget> Drops = new List<DropTarget>();

		public void Add(string creatureName, float chance, int min = 1, int? max = null, bool levelMultiplier = true)
		{
			Drops.Add(new DropTarget
			{
				creature = creatureName,
				chance = chance,
				min = min,
				max = (max ?? min),
				levelMultiplier = levelMultiplier
			});
		}
	}
	public struct DropTarget
	{
		public string creature;

		public int min;

		public int max;

		public float chance;

		public bool levelMultiplier;
	}
	public enum Toggle
	{
		On = 1,
		Off = 0
	}
	[PublicAPI]
	public class Item
	{
		[PublicAPI]
		public enum DamageModifier
		{
			Normal,
			Resistant,
			Weak,
			Immune,
			Ignore,
			VeryResistant,
			VeryWeak,
			None
		}

		private class ItemConfig
		{
			public ConfigEntry<string>? craft;

			public ConfigEntry<string> customTable = null;

			public ConfigEntry<int>? maximumTableLevel;

			public ConfigEntry<float> qualityResultAmountMultiplier = null;

			public ConfigEntry<Toggle> requireOneIngredient = null;

			public ConfigEntry<CraftingTable> table = null;

			public ConfigEntry<int> tableLevel = null;

			public ConfigEntry<string>? upgrade;
		}

		private class TraderConfig
		{
			public ConfigEntry<uint> price = null;

			public ConfigEntry<string> requiredGlobalKey = null;

			public ConfigEntry<uint> stack = null;

			public ConfigEntry<Trader> trader = null;

			public ConfigEntry<int> value = null;
		}

		private class RequirementQuality
		{
			public int quality;
		}

		private class ConfigurationManagerAttributes
		{
			public Func<bool>? browsability;

			[UsedImplicitly]
			public bool? Browsable;

			[UsedImplicitly]
			public string? Category;

			[UsedImplicitly]
			public Action<ConfigEntryBase>? CustomDrawer;

			[UsedImplicitly]
			public int? Order;
		}

		private delegate void setDmgFunc(ref DamageTypes dmg, float value);

		public class SerializedRequirements
		{
			public readonly List<Requirement> Reqs;

			public SerializedRequirements(List<Requirement> reqs)
			{
				Reqs = reqs;
			}

			public SerializedRequirements(string reqs)
				: this(reqs.Split(new char[1] { ',' }).Select(delegate(string r)
				{
					string[] array = r.Split(new char[1] { ':' });
					int result;
					int result2;
					return new Requirement
					{
						itemName = array[0],
						amount = ((array.Length <= 1 || !int.TryParse(array[1], out result)) ? 1 : result),
						quality = ((array.Length > 2 && int.TryParse(array[2], out result2)) ? result2 : 0)
					};
				}).ToList())
			{
			}

			public override string ToString()
			{
				return string.Join(",", Reqs.Select((Requirement r) => $"{r.itemName}:{r.amount}" + ((r.quality > 0) ? $":{r.quality}" : "")));
			}

			public static ItemDrop? fetchByName(ObjectDB objectDB, string name)
			{
				GameObject itemPrefab = objectDB.GetItemPrefab(name);
				ItemDrop val = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null);
				if ((Object)(object)val == (Object)null)
				{
					Debug.LogWarning((object)("The required item '" + name + "' does not exist."));
				}
				return val;
			}

			public static Requirement[] toPieceReqs(ObjectDB objectDB, SerializedRequirements craft, SerializedRequirements upgrade)
			{
				//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
				//IL_0104: Unknown result type (might be due to invalid IL or missing references)
				//IL_010c: Unknown result type (might be due to invalid IL or missing references)
				//IL_019a: Unknown result type (might be due to invalid IL or missing references)
				//IL_019f: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b1: Expected O, but got Unknown
				//IL_01b6: Expected O, but got Unknown
				//IL_012b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0134: Expected O, but got Unknown
				Dictionary<string, Requirement> dictionary = craft.Reqs.Where((Requirement r) => r.itemName != "").ToDictionary((Func<Requirement, string>)((Requirement r) => r.itemName), (Func<Requirement, Requirement>)delegate(Requirement r)
				{
					//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)
					//IL_0030: Unknown result type (might be due to invalid IL or missing references)
					//IL_0037: Unknown result type (might be due to invalid IL or missing references)
					ItemDrop val6 = ResItem(r);
					return (val6 == null) ? ((Requirement)null) : new Requirement
					{
						m_amount = (r.amountConfig?.Value ?? r.amount),
						m_resItem = val6,
						m_amountPerLevel = 0
					};
				});
				List<Requirement> list = dictionary.Values.Where((Requirement v) => v != null).ToList();
				foreach (Requirement item in upgrade.Reqs.Where((Requirement r) => r.itemName != ""))
				{
					if (item.quality > 0)
					{
						ItemDrop val = ResItem(item);
						if (val != null)
						{
							Requirement val2 = new Requirement
							{
								m_resItem = val,
								m_amountPerLevel = (item.amountConfig?.Value ?? item.amount),
								m_amount = 0
							};
							list.Add(val2);
							requirementQuality.Add(val2, new RequirementQuality
							{
								quality = item.quality
							});
						}
						continue;
					}
					if (!dictionary.TryGetValue(item.itemName, out var value) || value == null)
					{
						ItemDrop val3 = ResItem(item);
						if (val3 != null)
						{
							string itemName = item.itemName;
							Requirement val4 = new Requirement
							{
								m_resItem = val3,
								m_amount = 0
							};
							Requirement val5 = val4;
							dictionary[itemName] = val4;
							value = val5;
							list.Add(value);
						}
					}
					if (value != null)
					{
						value.m_amountPerLevel = item.amountConfig?.Value ?? item.amount;
					}
				}
				return list.ToArray();
				ItemDrop? ResItem(Requirement r)
				{
					return fetchByName(objectDB, r.itemName);
				}
			}
		}

		private class SerializedDrop
		{
			public readonly List<DropTarget> Drops;

			public SerializedDrop(List<DropTarget> drops)
			{
				Drops = drops;
			}

			public SerializedDrop(string drops)
			{
				Drops = ((drops == "") ? ((IEnumerable<string>)Array.Empty<string>()) : ((IEnumerable<string>)drops.Split(new char[1] { ',' }))).Select(delegate(string r)
				{
					string[] array = r.Split(new char[1] { ':' });
					if (array.Length <= 2 || !int.TryParse(array[2], out var result))
					{
						result = 1;
					}
					if (array.Length <= 3 || !int.TryParse(array[3], out var result2))
					{
						result2 = result;
					}
					bool levelMultiplier = array.Length <= 4 || array[4] != "0";
					float result3;
					return new DropTarget
					{
						creature = array[0],
						chance = ((array.Length > 1 && float.TryParse(array[1], out result3)) ? result3 : 1f),
						min = result,
						max = result2,
						levelMultiplier = levelMultiplier
					};
				}).ToList();
			}

			public override string ToString()
			{
				return string.Join(",", Drops.Select((DropTarget r) => $"{r.creature}:{r.chance.ToString(CultureInfo.InvariantCulture)}:{r.min}:" + ((r.min == r.max) ? "" : $"{r.max}") + (r.levelMultiplier ? "" : ":0")));
			}

			private static Character? fetchByName(ZNetScene netScene, string name)
			{
				GameObject prefab = netScene.GetPrefab(name);
				Character val = ((prefab != null) ? prefab.GetComponent<Character>() : null);
				if ((Object)(object)val == (Object)null)
				{
					Debug.LogWarning((object)("The drop target character '" + name + "' does not exist."));
				}
				return val;
			}

			public Dictionary<Character, Drop> toCharacterDrops(ZNetScene netScene, GameObject item)
			{
				//IL_0037: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0067: Unknown result type (might be due to invalid IL or missing references)
				//IL_0078: Expected O, but got Unknown
				Dictionary<Character, Drop> dictionary = new Dictionary<Character, Drop>();
				foreach (DropTarget drop in Drops)
				{
					Character val = fetchByName(netScene, drop.creature);
					if (val != null)
					{
						dictionary[val] = new Drop
						{
							m_prefab = item,
							m_amountMin = drop.min,
							m_amountMax = drop.max,
							m_chance = drop.chance,
							m_levelMultiplier = drop.levelMultiplier
						};
					}
				}
				return dictionary;
			}
		}

		private static readonly List<Item> registeredItems = new List<Item>();

		private static readonly Dictionary<ItemDrop, Item> itemDropMap = new Dictionary<ItemDrop, Item>();

		private static Dictionary<Item, Dictionary<string, List<Recipe>>> activeRecipes = new Dictionary<Item, Dictionary<string, List<Recipe>>>();

		private static Dictionary<Recipe, ConfigEntryBase?> hiddenCraftRecipes = new Dictionary<Recipe, ConfigEntryBase>();

		private static Dictionary<Recipe, ConfigEntryBase?> hiddenUpgradeRecipes = new Dictionary<Recipe, ConfigEntryBase>();

		private static Dictionary<Item, Dictionary<string, ItemConfig>> itemCraftConfigs = new Dictionary<Item, Dictionary<string, ItemConfig>>();

		private static Dictionary<Item, ConfigEntry<string>> itemDropConfigs = new Dictionary<Item, ConfigEntry<string>>();

		private static readonly ConditionalWeakTable<Requirement, RequirementQuality> requirementQuality = new ConditionalWeakTable<Requirement, RequirementQuality>();

		public static Configurability DefaultConfigurability = Configurability.Disabled;

		private static object? configManager;

		private static Localization? _english;

		private static BaseUnityPlugin? _plugin;

		private static bool hasConfigSync = true;

		private static object? _configSync;

		[Description("Assigns the item as a drop item to a creature.\nUses a creature name, a drop chance and a minimum and maximum amount.")]
		public readonly DropTargets DropsFrom = new DropTargets();

		public readonly GameObject Prefab;

		private readonly Dictionary<ConfigEntryBase, Action> statsConfigs = new Dictionary<ConfigEntryBase, Action>();

		[Description("Configures whether the item can be bought at the trader.\nDon't forget to set cost to something above 0 or the item will be sold for free.")]
		public readonly Trade Trade = new Trade();

		private LocalizeKey? _description;

		private LocalizeKey? _name;

		private Dictionary<CharacterDrop, Drop> characterDrops = new Dictionary<CharacterDrop, Drop>();

		public Configurability? Configurable;

		private Configurability configurationVisible = Configurability.Full;

		internal List<ItemConversion> conversions = new List<ItemConversion>();

		internal List<Conversion> Conversions = new List<Conversion>();

		[Description("Specifies the maximum required crafting station level to upgrade and repair the item.\nDefault is calculated from crafting station level and maximum quality.")]
		public int MaximumRequiredStationLevel = int.MaxValue;

		public Dictionary<string, ItemRecipe> Recipes = new Dictionary<string, ItemRecipe>();

		private TraderConfig? traderConfig;

		private Configurability configurability => Configurable ?? DefaultConfigurability;

		[Description("Specifies the resources needed to craft the item.\nUse .Add to add resources with their internal ID and an amount.\nUse one .Add for each resource type the item should need.")]
		public RequiredResourceList RequiredItems => this[""].RequiredItems;

		[Description("Specifies the resources needed to upgrade the item.\nUse .Add to add resources with their internal ID and an amount. This amount will be multipled by the item quality level.\nUse one .Add for each resource type the upgrade should need.")]
		public RequiredResourceList RequiredUpgradeItems => this[""].RequiredUpgradeItems;

		[Description("Specifies the crafting station needed to craft the item.\nUse .Add to add a crafting station, using the CraftingTable enum and a minimum level for the crafting station.\nUse one .Add for each crafting station.")]
		public CraftingStationList Crafting => this[""].Crafting;

		[Description("Specifies a config entry which toggles whether a recipe is active.")]
		public ConfigEntryBase? RecipeIsActive
		{
			get
			{
				return this[""].RecipeIsActive;
			}
			set
			{
				this[""].RecipeIsActive = value;
			}
		}

		[Description("Specifies the number of items that should be given to the player with a single craft of the item.\nDefaults to 1.")]
		public int CraftAmount
		{
			get
			{
				return this[""].CraftAmount;
			}
			set
			{
				this[""].CraftAmount = value;
			}
		}

		public bool RequireOnlyOneIngredient
		{
			get
			{
				return this[""].RequireOnlyOneIngredient;
			}
			set
			{
				this[""].RequireOnlyOneIngredient = value;
			}
		}

		public float QualityResultAmountMultiplier
		{
			get
			{
				return this[""].QualityResultAmountMultiplier;
			}
			set
			{
				this[""].QualityResultAmountMultiplier = value;
			}
		}

		public ItemRecipe this[string name]
		{
			get
			{
				if (Recipes.TryGetValue(name, out ItemRecipe value))
				{
					return value;
				}
				return Recipes[name] = new ItemRecipe();
			}
		}

		public LocalizeKey Name
		{
			get
			{
				LocalizeKey name = _name;
				if (name != null)
				{
					return name;
				}
				SharedData shared = Prefab.GetComponent<ItemDrop>().m_itemData.m_shared;
				if (shared.m_name.StartsWith("$"))
				{
					_name = new LocalizeKey(shared.m_name);
				}
				else
				{
					string text = "$item_" + ((Object)Prefab).name.Replace(" ", "_");
					_name = new LocalizeKey(text).English(shared.m_name);
					shared.m_name = text;
				}
				return _name;
			}
		}

		public LocalizeKey Description
		{
			get
			{
				LocalizeKey description = _description;
				if (description != null)
				{
					return description;
				}
				SharedData shared = Prefab.GetComponent<ItemDrop>().m_itemData.m_shared;
				if (shared.m_description.StartsWith("$"))
				{
					_description = new LocalizeKey(shared.m_description);
				}
				else
				{
					string text = "$itemdesc_" + ((Object)Prefab).name.Replace(" ", "_");
					_description = new LocalizeKey(text).English(shared.m_description);
					shared.m_description = text;
				}
				return _description;
			}
		}

		private static Localization english => _english ?? (_english = LocalizationCache.ForLanguage("English"));

		private static BaseUnityPlugin plugin
		{
			get
			{
				//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b2: Expected O, but got Unknown
				if (_plugin == null)
				{
					IEnumerable<TypeInfo> source;
					try
					{
						source = Assembly.GetExecutingAssembly().DefinedTypes.ToList();
					}
					catch (ReflectionTypeLoadException ex)
					{
						source = from t in ex.Types
							where t != null
							select t.GetTypeInfo();
					}
					_plugin = (BaseUnityPlugin)Chainloader.ManagerObject.GetComponent((Type)source.First((TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t)));
				}
				return _plugin;
			}
		}

		private static object? configSync
		{
			get
			{
				if (_configSync == null && hasConfigSync)
				{
					Type type = Assembly.GetExecutingAssembly().GetType("ServerSync.ConfigSync");
					if ((object)type != null)
					{
						_configSync = Activator.CreateInstance(type, plugin.Info.Metadata.GUID + " ItemManager");
						type.GetField("CurrentVersion").SetValue(_configSync, plugin.Info.Metadata.Version.ToString());
						type.GetProperty("IsLocked").SetValue(_configSync, true);
					}
					else
					{
						hasConfigSync = false;
					}
				}
				return _configSync;
			}
		}

		public Item(string assetBundleFileName, string prefabName, string folderName = "assets")
			: this(PrefabManager.RegisterAssetBundle(assetBundleFileName, folderName), prefabName)
		{
		}

		public Item(AssetBundle bundle, string prefabName)
			: this(PrefabManager.RegisterPrefab(bundle, prefabName, addToObjectDb: true), skipRegistering: true)
		{
		}

		public Item(GameObject prefab, bool skipRegistering = false)
		{
			if (!skipRegistering)
			{
				PrefabManager.RegisterPrefab(prefab, addToObjectDb: true);
			}
			Prefab = prefab;
			registeredItems.Add(this);
			itemDropMap[Prefab.GetComponent<ItemDrop>()] = this;
			Prefab.GetComponent<ItemDrop>().m_itemData.m_dropPrefab = Prefab;
		}

		public void ToggleConfigurationVisibility(Configurability visible)
		{
			configurationVisible = visible;
			if (itemDropConfigs.TryGetValue(this, out ConfigEntry<string> value))
			{
				Toggle((ConfigEntryBase)(object)value, Configurability.Drop);
			}
			if (itemCraftConfigs.TryGetValue(this, out Dictionary<string, ItemConfig> value2))
			{
				foreach (ItemConfig value4 in value2.Values)
				{
					ToggleObj(value4, Configurability.Recipe);
				}
			}
			foreach (Conversion conversion in Conversions)
			{
				if (conversion.config != null)
				{
					ToggleObj(conversion.config, Configurability.Recipe);
				}
			}
			foreach (KeyValuePair<ConfigEntryBase, Action> statsConfig in statsConfigs)
			{
				Toggle(statsConfig.Key, Configurability.Stats);
				if ((visible & Configurability.Stats) != Configurability.Disabled)
				{
					statsConfig.Value();
				}
			}
			reloadConfigDisplay();
			void Toggle(ConfigEntryBase cfg, Configurability check)
			{
				object[] tags = cfg.Description.Tags;
				foreach (object obj in tags)
				{
					if (obj is ConfigurationManagerAttributes configurationManagerAttributes)
					{
						configurationManagerAttributes.Browsable = (visible & check) != Configurability.Disabled && (configurationManagerAttributes.browsability == null || configurationManagerAttributes.browsability());
					}
				}
			}
			void ToggleObj(object obj, Configurability check)
			{
				FieldInfo[] fields = obj.GetType().GetFields();
				foreach (FieldInfo fieldInfo in fields)
				{
					object? value3 = fieldInfo.GetValue(obj);
					ConfigEntryBase val = (ConfigEntryBase)((value3 is ConfigEntryBase) ? value3 : null);
					if (val != null)
					{
						Toggle(val, check);
					}
				}
			}
		}

		internal static void reloadConfigDisplay()
		{
			if (configManager?.GetType().GetProperty("DisplayingWindow").GetValue(configManager) is int num && num != 0)
			{
				configManager.GetType().GetMethod("BuildSettingList").Invoke(configManager, Array.Empty<object>());
			}
		}

		public void UpdateItemTableConfig(string recipeKey, CraftingTable table, string customTableValue)
		{
			if (!activeRecipes.ContainsKey(this) || !activeRecipes[this].TryGetValue(recipeKey, out List<Recipe> value))
			{
				return;
			}
			Recipe val = value.FirstOrDefault();
			if (!((Object)(object)val == (Object)null))
			{
				val.m_enabled = table != CraftingTable.Disabled;
				if ((uint)table <= 1u)
				{
					val.m_craftingStation = null;
				}
				else if (table == CraftingTable.Custom)
				{
					GameObject prefab = ZNetScene.instance.GetPrefab(customTableValue);
					val.m_craftingStation = ((prefab != null) ? prefab.GetComponent<CraftingStation>() : null);
				}
				else
				{
					val.m_craftingStation = ZNetScene.instance.GetPrefab(getInternalName(table)).GetComponent<CraftingStation>();
				}
			}
		}

		public void UpdateCraftConfig(string recipeKey, SerializedRequirements craftRequirements, SerializedRequirements upgradeRequirements)
		{
			if (!Object.op_Implicit((Object)(object)ObjectDB.instance) || !activeRecipes.ContainsKey(this) || !activeRecipes[this].TryGetValue(recipeKey, out List<Recipe> value))
			{
				return;
			}
			foreach (Recipe item in value)
			{
				item.m_resources = SerializedRequirements.toPieceReqs(ObjectDB.instance, craftRequirements, upgradeRequirements);
			}
		}

		public void UpdateStationLevel(string recipeKey, int stationLevel)
		{
			if (activeRecipes.ContainsKey(this) && activeRecipes[this].TryGetValue(recipeKey, out List<Recipe> value))
			{
				Recipe val = value.FirstOrDefault();
				if ((Object)(object)val != (Object)null)
				{
					val.m_minStationLevel = stationLevel;
				}
			}
		}

		public void UpdateRequireOneIngredient(string recipeKey, bool requireOne)
		{
			if (!activeRecipes.ContainsKey(this) || !activeRecipes[this].TryGetValue(recipeKey, out List<Recipe> value))
			{
				return;
			}
			foreach (Recipe item in value)
			{
				item.m_requireOnlyOneIngredient = requireOne;
			}
		}

		public void UpdateQualityMultiplier(string recipeKey, float multiplier)
		{
			if (!activeRecipes.ContainsKey(this) || !activeRecipes[this].TryGetValue(recipeKey, out List<Recipe> value))
			{
				return;
			}
			foreach (Recipe item in value)
			{
				item.m_qualityResultAmountMultiplier = multiplier;
			}
		}

		public void UpdateCraftAmount(string recipeKey, int amount)
		{
			if (!activeRecipes.ContainsKey(this) || !activeRecipes[this].TryGetValue(recipeKey, out List<Recipe> value))
			{
				return;
			}
			foreach (Recipe item in value)
			{
				item.m_amount = amount;
			}
		}

		internal static void Patch_FejdStartup()
		{
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Expected O, but got Unknown
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Expected O, but got Unknown
			//IL_137b: Unknown result type (might be due to invalid IL or missing references)
			//IL_1380: Unknown result type (might be due to invalid IL or missing references)
			//IL_26de: Unknown result type (might be due to invalid IL or missing references)
			//IL_26e8: Expected O, but got Unknown
			//IL_1444: Unknown result type (might be due to invalid IL or missing references)
			//IL_1447: Unknown result type (might be due to invalid IL or missing references)
			//IL_149d: Expected I4, but got Unknown
			//IL_0fe7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ff1: Expected O, but got Unknown
			//IL_15d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_15da: Unknown result type (might be due to invalid IL or missing references)
			//IL_15dc: Invalid comparison between Unknown and I4
			//IL_0521: Unknown result type (might be due to invalid IL or missing references)
			//IL_052b: Expected O, but got Unknown
			//IL_1138: Unknown result type (might be due to invalid IL or missing references)
			//IL_1142: Expected O, but got Unknown
			//IL_11f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_1202: Expected O, but got Unknown
			//IL_15e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_15e4: Invalid comparison between Unknown and I4
			//IL_12c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_12cb: Expected O, but got Unknown
			//IL_17ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_17f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_17f4: Invalid comparison between Unknown and I4
			//IL_0656: Unknown result type (might be due to invalid IL or missing references)
			//IL_0660: Expected O, but got Unknown
			//IL_15e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_15ec: Invalid comparison between Unknown and I4
			//IL_17f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_17fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_17fe: Invalid comparison between Unknown and I4
			//IL_07e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_07eb: Expected O, but got Unknown
			//IL_18e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_18e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_18ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_18ed: Invalid comparison between Unknown and I4
			//IL_1802: Unknown result type (might be due to invalid IL or missing references)
			//IL_1806: Invalid comparison between Unknown and I4
			//IL_18f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_18f5: Invalid comparison between Unknown and I4
			//IL_0a2c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a36: Expected O, but got Unknown
			//IL_094b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0955: Expected O, but got Unknown
			//IL_196a: Unknown result type (might be due to invalid IL or missing references)
			//IL_196d: Unknown result type (might be due to invalid IL or missing references)
			//IL_196f: Invalid comparison between Unknown and I4
			//IL_0b82: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b8c: Expected O, but got Unknown
			//IL_1973: Unknown result type (might be due to invalid IL or missing references)
			//IL_1977: Unknown result type (might be due to invalid IL or missing references)
			//IL_1979: Invalid comparison between Unknown and I4
			//IL_1ac8: Unknown result type (might be due to invalid IL or missing references)
			//IL_1acb: Invalid comparison between Unknown and I4
			//IL_197d: Unknown result type (might be due to invalid IL or missing references)
			//IL_1981: Invalid comparison between Unknown and I4
			//IL_1cd0: Unknown result type (might be due to invalid IL or missing references)
			//IL_1cd7: Invalid comparison between Unknown and I4
			//IL_1da8: Unknown result type (might be due to invalid IL or missing references)
			//IL_1dad: Unknown result type (might be due to invalid IL or missing references)
			//IL_1daf: Unknown result type (might be due to invalid IL or missing references)
			//IL_1db3: Unknown result type (might be due to invalid IL or missing references)
			//IL_1db5: Invalid comparison between Unknown and I4
			//IL_1a3c: Unknown result type (might be due to invalid IL or missing references)
			//IL_1a41: Unknown result type (might be due to invalid IL or missing references)
			//IL_1e2a: Unknown result type (might be due to invalid IL or missing references)
			//IL_1e2d: Unknown result type (might be due to invalid IL or missing references)
			//IL_1e2f: Invalid comparison between Unknown and I4
			//IL_1e33: Unknown result type (might be due to invalid IL or missing references)
			//IL_1e37: Invalid comparison between Unknown and I4
			//IL_1e3b: Unknown result type (might be due to invalid IL or missing references)
			//IL_1e3f: Invalid comparison between Unknown and I4
			//IL_22b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_22b7: Invalid comparison between Unknown and I4
			Type type = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "ConfigurationManager")?.GetType("ConfigurationManager.ConfigurationManager");
			if (DefaultConfigurability != Configurability.Disabled)
			{
				bool saveOnConfigSet = plugin.Config.SaveOnConfigSet;
				plugin.Config.SaveOnConfigSet = false;
				List<Item> list = registeredItems.Where((Item i) => i.configurability != Configurability.Disabled).ToList();
				foreach (Item item4 in list)
				{
					Item item = item4;
					ItemDrop itemDrop = item.Prefab.GetComponent<ItemDrop>();
					string name = itemDrop.m_itemData.m_shared.m_name;
					string englishName = new Regex("[=\\n\\t\\\"\\'\\[\\]]*").Replace(english.Localize(name), "").Trim();
					string localizedName = Localization.instance.Localize(name).Trim();
					int order = 0;
					ConfigEntry<string> nameConfig = config(englishName, "Name", itemDrop.m_itemData.m_shared.m_name, new ConfigDescription("Display name for " + englishName + ".", (AcceptableValueBase)null, new object[1]
					{
						new ConfigurationManagerAttributes
						{
							Order = (order -= 1),
							Category = localizedName
						}
					}));
					nameConfig.SettingChanged += delegate
					{
						itemDrop.m_itemData.m_shared.m_name = nameConfig.Value;
						item.ApplyToAllInstances(delegate(ItemData itemData)
						{
							itemData.m_shared.m_name = nameConfig.Value;
						});
					};
					ConfigEntry<string> descriptionConfig = config(englishName, "Description", itemDrop.m_itemData.m_shared.m_description, new ConfigDescription("Description for " + englishName + ".", (AcceptableValueBase)null, new object[1]
					{
						new ConfigurationManagerAttributes
						{
							Order = (order -= 1),
							Category = localizedName
						}
					}));
					descriptionConfig.SettingChanged += delegate
					{
						itemDrop.m_itemData.m_shared.m_description = descriptionConfig.Value;
						item.ApplyToAllInstances(delegate(ItemData itemData)
						{
							itemData.m_shared.m_description = descriptionConfig.Value;
						});
					};
					if ((item.configurability & Configurability.Recipe) != Configurability.Disabled)
					{
						itemCraftConfigs[item] = new Dictionary<string, ItemConfig>();
						foreach (string item5 in item.Recipes.Keys.DefaultIfEmpty(""))
						{
							string configKey = item5;
							string text = ((configKey == "") ? "" : (" (" + configKey + ")"));
							if (!item.Recipes.ContainsKey(configKey) || item.Recipes[configKey].Crafting.Stations.Count <= 0)
							{
								continue;
							}
							ItemConfig itemConfig = (itemCraftConfigs[item][configKey] = new ItemConfig());
							ItemConfig cfg = itemConfig;
							List<ConfigurationManagerAttributes> hideWhenNoneAttributes = new List<ConfigurationManagerAttributes>();
							ItemConfig itemConfig3 = cfg;
							string text2 = englishName;
							string name2 = "Crafting Station" + text;
							CraftingTable table = item.Recipes[configKey].Crafting.Stations.First().Table;
							string text3 = "Crafting station where " + englishName + " is available.";
							object[] array = new object[1];
							ConfigurationManagerAttributes configurationManagerAttributes = new ConfigurationManagerAttributes();
							int num = order - 1;
							order = num;
							configurationManagerAttributes.Order = num;
							configurationManagerAttributes.Browsable = (item.configurationVisible & Configurability.Recipe) != 0;
							configurationManagerAttributes.Category = localizedName;
							array[0] = configurationManagerAttributes;
							itemConfig3.table = config(text2, name2, table, new ConfigDescription(text3, (AcceptableValueBase)null, array));
							ConfigurationManagerAttributes configurationManagerAttributes2 = new ConfigurationManagerAttributes();
							num = order - 1;
							order = num;
							configurationManagerAttributes2.Order = num;
							configurationManagerAttributes2.browsability = CustomTableBrowsability;
							configurationManagerAttributes2.Browsable = CustomTableBrowsability() && (item.configurationVisible & Configurability.Recipe) != 0;
							configurationManagerAttributes2.Category = localizedName;
							ConfigurationManagerAttributes customTableAttributes = configurationManagerAttributes2;
							cfg.customTable = config(englishName, "Custom Crafting Station" + text, item.Recipes[configKey].Crafting.Stations.First().custom ?? "", new ConfigDescription("", (AcceptableValueBase)null, new object[1] { customTableAttributes }));
							cfg.table.SettingChanged += TableConfigChanged;
							cfg.customTable.SettingChanged += TableConfigChanged;
							ConfigurationManagerAttributes configurationManagerAttributes3 = new ConfigurationManagerAttributes();
							num = order - 1;
							order = num;
							configurationManagerAttributes3.Order = num;
							configurationManagerAttributes3.browsability = TableLevelBrowsability;
							configurationManagerAttributes3.Browsable = TableLevelBrowsability() && (item.configurationVisible & Configurability.Recipe) != 0;
							configurationManagerAttributes3.Category = localizedName;
							ConfigurationManagerAttributes configurationManagerAttributes4 = configurationManagerAttributes3;
							hideWhenNoneAttributes.Add(configurationManagerAttributes4);
							cfg.tableLevel = config(englishName, "Crafting Station Level" + text, item.Recipes[configKey].Crafting.Stations.First().level, new ConfigDescription("Required crafting station level to craft " + englishName + ".", (AcceptableValueBase)null, new object[1] { configurationManagerAttributes4 }));
							cfg.tableLevel.SettingChanged += delegate
							{
								if (activeRecipes.ContainsKey(item) && activeRecipes[item].TryGetValue(configKey, out List<Recipe> value2))
								{
									value2.First().m_minStationLevel = cfg.tableLevel.Value;
								}
							};
							if (item.Prefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_maxQuality > 1)
							{
								cfg.maximumTableLevel = config(englishName, "Maximum Crafting Station Level" + text, (item.MaximumRequiredStationLevel == int.MaxValue) ? (item.Recipes[configKey].Crafting.Stations.First().level + item.Prefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_maxQuality - 1) : item.MaximumRequiredStationLevel, new ConfigDescription("Maximum crafting station level to upgrade and repair " + englishName + ".", (AcceptableValueBase)null, new object[1] { configurationManagerAttributes4 }));
							}
							ItemConfig itemConfig4 = cfg;
							string text4 = englishName;
							string name3 = "Require only one resource" + text;
							int value = (item.Recipes[configKey].RequireOnlyOneIngredient ? 1 : 0);
							string text5 = "Whether only one of the ingredients is needed to craft " + englishName;
							object[] array2 = new object[1];
							ConfigurationManagerAttributes configurationManagerAttributes5 = new ConfigurationManagerAttributes();
							num = order - 1;
							order = num;
							configurationManagerAttributes5.Order = num;
							configurationManagerAttributes5.Category = localizedName;
							array2[0] = configurationManagerAttributes5;
							itemConfig4.requireOneIngredient = config(text4, name3, (Toggle)value, new ConfigDescription(text5, (AcceptableValueBase)null, array2));
							ConfigurationManagerAttributes configurationManagerAttributes6 = new ConfigurationManagerAttributes();
							num = order - 1;
							order = num;
							configurationManagerAttributes6.Order = num;
							configurationManagerAttributes6.browsability = QualityResultBrowsability;
							configurationManagerAttributes6.Browsable = QualityResultBrowsability() && (item.configurationVisible & Configurability.Recipe) != 0;
							configurationManagerAttributes6.Category = localizedName;
							ConfigurationManagerAttributes qualityResultAttributes = configurationManagerAttributes6;
							cfg.requireOneIngredient.SettingChanged += delegate
							{
								if (activeRecipes.ContainsKey(item) && activeRecipes[item].TryGetValue(configKey, out List<Recipe> value2))
								{
									foreach (Recipe item6 in value2)
									{
										item6.m_requireOnlyOneIngredient = cfg.requireOneIngredient.Value == Toggle.On;
									}
								}
								qualityResultAttributes.Browsable = QualityResultBrowsability();
								reloadConfigDisplay();
							};
							cfg.qualityResultAmountMultiplier = config(englishName, "Quality Multiplier" + text, item.Recipes[configKey].QualityResultAmountMultiplier, new ConfigDescription("Multiplies the crafted amount based on the quality of the resources when crafting " + englishName + ". Only works, if Require Only One Resource is true.", (AcceptableValueBase)null, new object[1] { qualityResultAttributes }));
							cfg.qualityResultAmountMultiplier.SettingChanged += delegate
							{
								if (activeRecipes.ContainsKey(item) && activeRecipes[item].TryGetValue(configKey, out List<Recipe> value2))
								{
									foreach (Recipe item7 in value2)
									{
										item7.m_qualityResultAmountMultiplier = cfg.qualityResultAmountMultiplier.Value;
									}
								}
							};
							if ((!item.Recipes[configKey].RequiredItems.Free || item.Recipes[configKey].RequiredItems.Requirements.Count > 0) && item.Recipes[configKey].RequiredItems.Requirements.All((Requirement r) => r.amountConfig == null))
							{
								cfg.craft = itemConfig5("Crafting Costs" + text, new SerializedRequirements(item.Recipes[configKey].RequiredItems.Requirements).ToString(), "Item costs to craft " + englishName, isUpgrade: false);
							}
							if (item.Prefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_maxQuality > 1 && (!item.Recipes[configKey].RequiredUpgradeItems.Free || item.Recipes[configKey].RequiredUpgradeItems.Requirements.Count > 0) && item.Recipes[configKey].RequiredUpgradeItems.Requirements.All((Requirement r) => r.amountConfig == null))
							{
								cfg.upgrade = itemConfig5("Upgrading Costs" + text, new SerializedRequirements(item.Recipes[configKey].RequiredUpgradeItems.Requirements).ToString(), "Item costs per level to upgrade " + englishName, isUpgrade: true);
							}
							if (cfg.craft != null)
							{
								cfg.craft.SettingChanged += ConfigChanged;
							}
							if (cfg.upgrade != null)
							{
								cfg.upgrade.SettingChanged += ConfigChanged;
							}
							void ConfigChanged(object o, EventArgs e)
							{
								item.UpdateCraftConfig(configKey, new SerializedRequirements(cfg.craft?.Value ?? ""), new SerializedRequirements(cfg.upgrade?.Value ?? ""));
							}
							bool CustomTableBrowsability()
							{
								return cfg.table.Value == CraftingTable.Custom;
							}
							bool ItemBrowsability()
							{
								return cfg.table.Value != CraftingTable.Disabled;
							}
							bool QualityResultBrowsability()
							{
								return cfg.requireOneIngredient.Value == Toggle.On;
							}
							void TableConfigChanged(object o, EventArgs e)
							{
								item.UpdateItemTableConfig(configKey, cfg.table.Value, cfg.customTable.Value);
								customTableAttributes.Browsable = cfg.table.Value == CraftingTable.Custom;
								foreach (ConfigurationManagerAttributes item8 in hideWhenNoneAttributes)
								{
									item8.Browsable = cfg.table.Value != CraftingTable.Disabled;
								}
								reloadConfigDisplay();
							}
							bool TableLevelBrowsability()
							{
								return cfg.table.Value != CraftingTable.Disabled;
							}
							ConfigEntry<string> itemConfig5(string name4, string value2, string desc, bool isUpgrade)
							{
								//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
								//IL_00ec: Expected O, but got Unknown
								ConfigurationManagerAttributes obj = new ConfigurationManagerAttributes
								{
									CustomDrawer = drawRequirementsConfigTable(item, isUpgrade)
								};
								int num5 = order - 1;
								order = num5;
								obj.Order = num5;
								obj.browsability = ItemBrowsability;
								obj.Browsable = ItemBrowsability() && (item.configurationVisible & Configurability.Recipe) != 0;
								obj.Category = localizedName;
								ConfigurationManagerAttributes configurationManagerAttributes8 = obj;
								hideWhenNoneAttributes.Add(configurationManagerAttributes8);
								return config(englishName, name4, value2, new ConfigDescription(desc, (AcceptableValueBase)null, new object[1] { configurationManagerAttributes8 }));
							}
						}
						if ((item.configurability & Configurability.Drop) != Configurability.Disabled)
						{
							ConfigEntry<string> val = (itemDropConfigs[item] = config(englishName, "Drop from", new SerializedDrop(item.DropsFrom.Drops).ToString(), new ConfigDescription(englishName + " drops from this creature.", (AcceptableValueBase)null, new object[1]
							{
								new ConfigurationManagerAttributes
								{
									CustomDrawer = drawDropsConfigTable,
									Category = localizedName,
									Browsable = ((item.configurationVisible & Configurability.Drop) != 0)
								}
							})));
							ConfigEntry<string> val3 = val;
							val3.SettingChanged += delegate
							{
								item.UpdateCharacterDrop();
							};
						}
						for (int num2 = 0; num2 < item.Conversions.Count; num2++)
						{
							string text6 = ((item.Conversions.Count > 1) ? $"{num2 + 1}. " : "");
							Conversion conversion = item.Conversions[num2];
							conversion.config = new Conversion.ConversionConfig();
							int index = num2;
							conversion.config.input = config(englishName, text6 + "Conversion Input Item", conversion.Input, new ConfigDescription("Input item to create " + englishName, (AcceptableValueBase)null, new object[1]
							{
								new ConfigurationManagerAttributes
								{
									Category = localizedName,
									Browsable = ((item.configurationVisible & Configurability.Recipe) != 0)
								}
							}));
							conversion.config.input.SettingChanged += delegate
							{
								if (index < item.conversions.Count)
								{
									ObjectDB instance = ObjectDB.instance;
									if (instance != null)
									{
										ItemDrop val4 = SerializedRequirements.fetchByName(instance, conversion.config.input.Value);
										item.conversions[index].m_from = val4;
										UpdatePiece();
									}
								}
							};
							conversion.config.piece = config(englishName, text6 + "Conversion Piece", conversion.Piece, new ConfigDescription("Conversion piece used to create " + englishName, (AcceptableValueBase)null, new object[1]
							{
								new ConfigurationManagerAttributes
								{
									Category = localizedName,
									Browsable = ((item.configurationVisible & Configurability.Recipe) != 0)
								}
							}));
							conversion.config.piece.SettingChanged += delegate
							{
								UpdatePiece();
							};
							conversion.config.customPiece = config(englishName, text6 + "Conversion Custom Piece", conversion.customPiece ?? "", new ConfigDescription("Custom conversion piece to create " + englishName, (AcceptableValueBase)null, new object[1]
							{
								new ConfigurationManagerAttributes
								{
									Category = localizedName,
									Browsable = ((item.configurationVisible & Configurability.Recipe) != 0)
								}
							}));
							conversion.config.customPiece.SettingChanged += delegate
							{
								UpdatePiece();
							};
							void UpdatePiece()
							{
								if (index < item.conversions.Count && Object.op_Implicit((Object)(object)ZNetScene.instance))
								{
									string text9 = ((conversion.config.piece.Value == ConversionPiece.Disabled) ? null : ((conversion.config.piece.Value == ConversionPiece.Custom) ? conversion.config.customPiece.Value : getInternalName(conversion.config.piece.Value)));
									string activePiece = conversion.config.activePiece;
									if (conversion.config.activePiece != null)
									{
										Smelter component = ZNetScene.instance.GetPrefab(conversion.config.activePiece).GetComponent<Smelter>();
										int num5 = component.m_conversion.IndexOf(item.conversions[index]);
										if (num5 >= 0)
										{
											Smelter[] array6 = Resources.FindObjectsOfTypeAll<Smelter>();
											foreach (Smelter val4 in array6)
											{
												if (Utils.GetPrefabName(((Component)val4).gameObject) == activePiece)
												{
													val4.m_conversion.RemoveAt(num5);
												}
											}
										}
										conversion.config.activePiece = null;
									}
									if (item.conversions[index].m_from != null && conversion.config.piece.Value != ConversionPiece.Disabled)
									{
										GameObject prefab = ZNetScene.instance.GetPrefab(text9);
										if (((prefab != null) ? prefab.GetComponent<Smelter>() : null) != null)
										{
											conversion.config.activePiece = text9;
											Smelter[] array7 = Resources.FindObjectsOfTypeAll<Smelter>();
											foreach (Smelter val5 in array7)
											{
												if (Utils.GetPrefabName(((Component)val5).gameObject) == text9)
												{
													val5.m_conversion.Add(item.conversions[index]);
												}
											}
										}
									}
								}
							}
						}
					}
					if ((item.configurability & Configurability.Stats) != Configurability.Disabled)
					{
						item.statsConfigs.Clear();
						SharedData shared = item.Prefab.GetComponent<ItemDrop>().m_itemData.m_shared;
						ItemType itemType = shared.m_itemType;
						statcfg<float>("Weight", "Weight of " + englishName + ".", (SharedData val4) => val4.m_weight, delegate(SharedData val4, float weight)
						{
							val4.m_weight = weight;
						});
						statcfg<int>("Trader Value", "Trader value of " + englishName + ".", (SharedData val4) => val4.m_value, delegate(SharedData val4, int value2)
						{
							val4.m_value = value2;
						});
						bool flag;
						switch (itemType - 3)
						{
						case 0:
						case 1:
						case 2:
						case 3:
						case 4:
						case 8:
						case 9:
						case 11:
						case 14:
						case 16:
						case 19:
							flag = true;
							break;
						default:
							flag = false;
							break;
						}
						if (flag)
						{
							statcfg<float>("Durability", "Durability of " + englishName + ".", (SharedData val4) => val4.m_maxDurability, delegate(SharedData val4, float maxDurability)
							{
								val4.m_maxDurability = maxDurability;
							});
							statcfg<float>("Durability per Level", "Durability gain per level of " + englishName + ".", (SharedData val4) => val4.m_durabilityPerLevel, delegate(SharedData val4, float durabilityPerLevel)
							{
								val4.m_durabilityPerLevel = durabilityPerLevel;
							});
							statcfg<float>("Movement Speed Modifier", "Movement speed modifier of " + englishName + ".", (SharedData val4) => val4.m_movementModifier, delegate(SharedData val4, float movementModifier)
							{
								val4.m_movementModifier = movementModifier;
							});
						}
						if ((itemType - 3 <= 2 || (int)itemType == 14 || (int)itemType == 22) ? true : false)
						{
							statcfg<float>("Block Armor", "Block armor of " + englishName + ".", (SharedData val4) => val4.m_blockPower, delegate(SharedData val4, float blockPower)
							{
								val4.m_blockPower = blockPower;
							});
							statcfg<float>("Block Armor per Level", "Block armor per level for " + englishName + ".", (SharedData val4) => val4.m_blockPowerPerLevel, delegate(SharedData val4, float blockPowerPerLevel)
							{
								val4.m_blockPowerPerLevel = blockPowerPerLevel;
							});
							statcfg<float>("Block Force", "Block force of " + englishName + ".", (SharedData val4) => val4.m_deflectionForce, delegate(SharedData val4, float deflectionForce)
							{
								val4.m_deflectionForce = deflectionForce;
							});
							statcfg<float>("Block Force per Level", "Block force per level for " + englishName + ".", (SharedData val4) => val4.m_deflectionForcePerLevel, delegate(SharedData val4, float deflectionForcePerLevel)
							{
								val4.m_deflectionForcePerLevel = deflectionForcePerLevel;
							});
							statcfg<float>("Parry Bonus", "Parry bonus of " + englishName + ".", (SharedData val4) => val4.m_timedBlockBonus, delegate(SharedData val4, float timedBlockBonus)
							{
								val4.m_timedBlockBonus = timedBlockBonus;
							});
						}
						else if ((itemType - 6 <= 1 || itemType - 11 <= 1 || (int)itemType == 17) ? true : false)
						{
							statcfg<float>("Armor", "Armor of " + englishName + ".", (SharedData val4) => val4.m_armor, delegate(SharedData val4, float armor)
							{
								val4.m_armor = armor;
							});
							statcfg<float>("Armor per Level", "Armor per level for " + englishName + ".", (SharedData val4) => val4.m_armorPerLevel, delegate(SharedData val4, float armorPerLevel)
							{
								val4.m_armorPerLevel = armorPerLevel;
							});
						}
						SkillType skillType = shared.m_skillType;
						if (((int)skillType == 7 || (int)skillType == 12) ? true : false)
						{
							statcfg<int>("Tool tier", "Tool tier of " + englishName + ".", (SharedData val4) => val4.m_toolTier, delegate(SharedData val4, int toolTier)
							{
								val4.m_toolTier = toolTier;
							});
						}
						if ((itemType - 5 <= 2 || itemType - 11 <= 1 || (int)itemType == 17) ? true : false)
						{
							Dictionary<DamageType, DamageModifier> modifiers = shared.m_damageModifiers.ToDictionary((DamageModPair d) => d.m_type, (DamageModPair d) => (DamageModifier)d.m_modifier);
							DamageType[] first = (DamageType[])Enum.GetValues(typeof(DamageType));
							DamageType[] array3 = new DamageType[5];
							RuntimeHelpers.InitializeArray(array3, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
							foreach (DamageType damageType in first.Except((IEnumerable<DamageType>)(object)array3))
							{
								statcfg<DamageModifier>(((object)Unsafe.As<DamageType, DamageType>(ref damageType)/*cast due to .constrained prefix*/).ToString() + " Resistance", ((object)Unsafe.As<DamageType, DamageType>(ref damageType)/*cast due to .constrained prefix*/).ToString() + " resistance of " + englishName + ".", (SharedData _) => modifiers.TryGetValue(damageType, out var value2) ? value2 : DamageModifier.None, delegate(SharedData val5, DamageModifier damageModifier)
								{
									//IL_0003: Unknown result type (might be due to invalid IL or missing references)
									//IL_000c: Unknown result type (might be due to invalid IL or missing references)
									//IL_0011: Unknown result type (might be due to invalid IL or missing references)
									//IL_0019: Unknown result type (might be due to invalid IL or missing references)
									//IL_001e: Unknown result type (might be due to invalid IL or missing references)
									//IL_001f: Unknown result type (might be due to invalid IL or missing references)
									//IL_002b: Unknown result type (might be due to invalid IL or missing references)
									//IL_0030: Unknown result type (might be due to invalid IL or missing references)
									//IL_0036: Unknown result type (might be due to invalid IL or missing references)
									//IL_0096: Unknown result type (might be due to invalid IL or missing references)
									//IL_0062: Unknown result type (might be due to invalid IL or missing references)
									DamageModPair val4 = new DamageModPair
									{
										m_type = damageType,
										m_modifier = (DamageModifier)damageModifier
									};
									for (int i = 0; i < val5.m_damageModifiers.Count; i++)
									{
										if (val5.m_damageModifiers[i].m_type == damageType)
										{
											if (damageModifier == DamageModifier.None)
											{
												val5.m_damageModifiers.RemoveAt(i);
											}
											else
											{
												val5.m_damageModifiers[i] = val4;
											}
											return;
										}
									}
									if (damageModifier != DamageModifier.None)
									{
										val5.m_damageModifiers.Add(val4);
									}
								});
							}
						}
						if ((int)itemType == 2 && shared.m_food > 0f)
						{
							statcfg<float>("Health", "Health value of " + englishName + ".", (SharedData val4) => val4.m_food, delegate(SharedData val4, float food)
							{
								val4.m_food = food;
							});
							statcfg<float>("Stamina", "Stamina value of " + englishName + ".", (SharedData val4) => val4.m_foodStamina, delegate(SharedData val4, float foodStamina)
							{
								val4.m_foodStamina = foodStamina;
							});
							statcfg<float>("Eitr", "Eitr value of " + englishName + ".", (SharedData val4) => val4.m_foodEitr, delegate(SharedData val4, float foodEitr)
							{
								val4.m_foodEitr = foodEitr;
							});
							statcfg<float>("Duration", "Duration of " + englishName + ".", (SharedData val4) => val4.m_foodBurnTime, delegate(SharedData val4, float foodBurnTime)
							{
								val4.m_foodBurnTime = foodBurnTime;
							});
							statcfg<float>("Health Regen", "Health regen value of " + englishName + ".", (SharedData val4) => val4.m_foodRegen, delegate(SharedData val4, float foodRegen)
							{
								val4.m_foodRegen = foodRegen;
							});
						}
						if ((int)shared.m_skillType == 10)
						{
							statcfg<float>("Health Cost", "Health cost of " + englishName + ".", (SharedData val4) => val4.m_attack.m_attackHealth, delegate(SharedData val4, float attackHealth)
							{
								val4.m_attack.m_attackHealth = attackHealth;
							});
							statcfg<float>("Health Cost Percentage", "Health cost percentage of " + englishName + ".", (SharedData val4) => val4.m_attack.m_attackHealthPercentage, delegate(SharedData val4, float attackHealthPercentage)
							{
								val4.m_attack.m_attackHealthPercentage = attackHealthPercentage;
							});
						}
						skillType = shared.m_skillType;
						if (skillType - 9 <= 1)
						{
							statcfg<float>("Eitr Cost", "Eitr cost of " + englishName + ".", (SharedData val4) => val4.m_attack.m_attackEitr, delegate(SharedData val4, float attackEitr)
							{
								val4.m_attack.m_attackEitr = attackEitr;
							});
						}
						if ((itemType - 3 <= 1 || (int)itemType == 14 || (int)itemType == 22) ? true : false)
						{
							statcfg<float>("Knockback", "Knockback of " + englishName + ".", (SharedData val4) => val4.m_attackForce, delegate(SharedData val4, float attackForce)
							{
								val4.m_attackForce = attackForce;
							});
							statcfg<float>("Backstab Bonus", "Backstab bonus of " + englishName + ".", (SharedData val4) => val4.m_backstabBonus, delegate(SharedData val4, float backstabBonus)
							{
								val4.m_backstabBonus = backstabBonus;
							});
							statcfg<float>("Attack Stamina", "Attack stamina of " + englishName + ".", (SharedData val4) => val4.m_attack.m_attackStamina, delegate(SharedData val4, float attackStamina)
							{
								val4.m_attack.m_attackStamina = attackStamina;
							});
							SetDmg("True", (DamageTypes dmg) => dmg.m_damage, delegate(ref DamageTypes dmg, float damage)
							{
								dmg.m_damage = damage;
							});
							SetDmg("Slash", (DamageTypes dmg) => dmg.m_slash, delegate(ref DamageTypes dmg, float slash)
							{
								dmg.m_slash = slash;
							});
							SetDmg("Pierce", (DamageTypes dmg) => dmg.m_pierce, delegate(ref DamageTypes dmg, float pierce)
							{
								dmg.m_pierce = pierce;
							});
							SetDmg("Blunt", (DamageTypes dmg) => dmg.m_blunt, delegate(ref DamageTypes dmg, float blunt)
							{
								dmg.m_blunt = blunt;
							});
							SetDmg("Chop", (DamageTypes dmg) => dmg.m_chop, delegate(ref DamageTypes dmg, float chop)
							{
								dmg.m_chop = chop;
							});
							SetDmg("Pickaxe", (DamageTypes dmg) => dmg.m_pickaxe, delegate(ref DamageTypes dmg, float pickaxe)
							{
								dmg.m_pickaxe = pickaxe;
							});
							SetDmg("Fire", (DamageTypes dmg) => dmg.m_fire, delegate(ref DamageTypes dmg, float fire)
							{
								dmg.m_fire = fire;
							});
							SetDmg("Poison", (DamageTypes dmg) => dmg.m_poison, delegate(ref DamageTypes dmg, float poison)
							{
								dmg.m_poison = poison;
							});
							SetDmg("Frost", (DamageTypes dmg) => dmg.m_frost, delegate(ref DamageTypes dmg, float frost)
							{
								dmg.m_frost = frost;
							});
							SetDmg("Lightning", (DamageTypes dmg) => dmg.m_lightning, delegate(ref DamageTypes dmg, float lightning)
							{
								dmg.m_lightning = lightning;
							});
							SetDmg("Spirit", (DamageTypes dmg) => dmg.m_spirit, delegate(ref DamageTypes dmg, float spirit)
							{
								dmg.m_spirit = spirit;
							});
							if ((int)itemType == 4)
							{
								statcfg<int>("Projectiles", "Number of projectiles that " + englishName + " shoots at once.", (SharedData val4) => val4.m_attack.m_projectileBursts, delegate(SharedData val4, int projectileBursts)
								{
									val4.m_attack.m_projectileBursts = projectileBursts;
								});
								statcfg<float>("Burst Interval", "Time between the projectiles " + englishName + " shoots at once.", (SharedData val4) => val4.m_attack.m_burstInterval, delegate(SharedData val4, float burstInterval)
								{
									val4.m_attack.m_burstInterval = burstInterval;
								});
								statcfg<float>("Minimum Accuracy", "Minimum accuracy for " + englishName + ".", (SharedData val4) => val4.m_attack.m_projectileAccuracyMin, delegate(SharedData val4, float projectileAccuracyMin)
								{
									val4.m_attack.m_projectileAccuracyMin = projectileAccuracyMin;
								});
								statcfg<float>("Accuracy", "Accuracy for " + englishName + ".", (SharedData val4) => val4.m_attack.m_projectileAccuracy, delegate(SharedData val4, float projectileAccuracy)
								{
									val4.m_attack.m_projectileAccuracy = projectileAccuracy;
								});
								statcfg<float>("Minimum Velocity", "Minimum velocity for " + englishName + ".", (SharedData val4) => val4.m_attack.m_projectileVelMin, delegate(SharedData val4, float projectileVelMin)
								{
									val4.m_attack.m_projectileVelMin = projectileVelMin;
								});
								statcfg<float>("Velocity", "Velocity for " + englishName + ".", (SharedData val4) => val4.m_attack.m_projectileVel, delegate(SharedData val4, float projectileVel)
								{
									val4.m_attack.m_projectileVel = projectileVel;
								});
								statcfg<float>("Maximum Draw Time", "Time until " + englishName + " is fully drawn at skill level 0.", (SharedData val4) => val4.m_attack.m_drawDurationMin, delegate(SharedData val4, float drawDurationMin)
								{
									val4.m_attack.m_drawDurationMin = drawDurationMin;
								});
								statcfg<float>("Stamina Drain", "Stamina drain per second while drawing " + englishName + ".", (SharedData val4) => val4.m_attack.m_drawStaminaDrain, delegate(SharedData val4, float drawStaminaDrain)
								{
									val4.m_attack.m_drawStaminaDrain = drawStaminaDrain;
								});
							}
						}
					}
					List<ConfigurationManagerAttributes> traderAttributes;
					if ((item.configurability & Configurability.Trader) != Configurability.Disabled)
					{
						traderAttributes = new List<ConfigurationManagerAttributes>();
						Item item2 = item;
						TraderConfig traderConfig = new TraderConfig();
						string text7 = englishName;
						Trader trader = item.Trade.Trader;
						string text8 = "Which traders sell " + englishName + ".";
						object[] array4 = new object[1];
						ConfigurationManagerAttributes configurationManagerAttributes7 = new ConfigurationManagerAttributes();
						int num = order - 1;
						order = num;
						configurationManagerAttributes7.Order = num;
						configurationManagerAttributes7.Browsable = (item.configurationVisible & Configurability.Trader) != 0;
						configurationManagerAttributes7.Category = localizedName;
						array4[0] = configurationManagerAttributes7;
						traderConfig.trader = config(text7, "Trader Selling", trader, new ConfigDescription(text8, (AcceptableValueBase)null, array4));
						item2.traderConfig = traderConfig;
						item.traderConfig.trader.SettingChanged += delegate
						{
							item.ReloadTraderConfiguration();
							foreach (ConfigurationManagerAttributes item9 in traderAttributes)
							{
								item9.Browsable = TraderBrowsability();
							}
							reloadConfigDisplay();
						};
						item.traderConfig.price = traderConfig2<uint>("Trader Price", item.Trade.Price, "Price of " + englishName + " at the trader.");
						item.traderConfig.stack = traderConfig2<uint>("Trader Stack", item.Trade.Stack, "Stack size of " + englishName + " in the trader. Also known as the number of items sold by a trader in one transaction.");
						item.traderConfig.requiredGlobalKey = traderConfig2<string>("Trader Required Global Key", item.Trade.RequiredGlobalKey ?? "", "Required global key to unlock " + englishName + " at the trader.");
						item.traderConfig.value = traderConfig2<int>("Trader Value", item.Prefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_value, "Value of " + englishName + " when sold to the trader (what Haldor buys it for).");
						if (item.traderConfig.trader.Value != Trader.None)
						{
							PrefabManager.AddItemToTrader(item.Prefab, item.traderConfig.trader.Value, item.traderConfig.price.Value, item.traderConfig.stack.Value, item.traderConfig.requiredGlobalKey.Value);
						}
					}
					else if (item.Trade.Trader != Trader.None)
					{
						PrefabManager.AddItemToTrader(item.Prefab, item.Trade.Trader, item.Trade.Price, item.Trade.Stack, item.Trade.RequiredGlobalKey);
					}
					void SetDmg(string dmgType, Func<DamageTypes, float> readDmg, setDmgFunc setDmg)
					{
						statcfg<float>(dmgType + " Damage", dmgType + " damage dealt by " + englishName + ".", (SharedData val4) => readDmg(val4.m_damages), delegate(SharedData val4, float value2)
						{
							setDmg(ref val4.m_damages, value2);
						});
						statcfg<float>(dmgType + " Damage Per Level", dmgType + " damage dealt increase per level for " + englishName + ".", (SharedData val4) => readDmg(val4.m_damagesPerLevel), delegate(SharedData val4, float value2)
						{
							setDmg(ref val4.m_damagesPerLevel, value2);
						});
					}
					bool TraderBrowsability()
					{
						return item.traderConfig.trader.Value != Trader.None;
					}
					void statcfg<T>(string configName, string description, Func<SharedData, T> readDefault, Action<SharedData, T> setValue) where T : notnull
					{
						//IL_0081: Unknown result type (might be due to invalid IL or missing references)
						//IL_008b: Expected O, but got Unknown
						SharedData shared2 = item.Prefab.GetComponent<ItemDrop>().m_itemData.m_shared;
						ConfigEntry<T> cfg2 = config(englishName, configName, readDefault(shared2), new ConfigDescription(description, (AcceptableValueBase)null, new object[1]
						{
							new ConfigurationManagerAttributes
							{
								Category = localizedName,
								Browsable = ((item.configurationVisible & Configurability.Stats) != 0)
							}
						}));
						if ((item.configurationVisible & Configurability.Stats) != Configurability.Disabled)
						{
							setValue(shared2, cfg2.Value);
						}
						item.statsConfigs.Add((ConfigEntryBase)(object)cfg2, ApplyConfig);
						cfg2.SettingChanged += delegate
						{
							if ((item.configurationVisible & Configurability.Stats) != Configurability.Disabled)
							{
								ApplyConfig();
							}
						};
						void ApplyConfig()
						{
							item.ApplyToAllInstances(delegate(ItemData val4)
							{
								setValue(val4.m_shared, cfg2.Value);
							});
						}
					}
					ConfigEntry<T> traderConfig2<T>(string name4, T value2, string desc) where T : notnull
					{
						//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
						//IL_00c4: Expected O, but got Unknown
						ConfigurationManagerAttributes configurationManagerAttributes8 = new ConfigurationManagerAttributes();
						int num5 = order - 1;
						order = num5;
						configurationManagerAttributes8.Order = num5;
						configurationManagerAttributes8.browsability = TraderBrowsability;
						configurationManagerAttributes8.Browsable = TraderBrowsability() && (item.configurationVisible & Configurability.Trader) != 0;
						configurationManagerAttributes8.Category = localizedName;
						ConfigurationManagerAttributes configurationManagerAttributes9 = configurationManagerAttributes8;
						traderAttributes.Add(configurationManagerAttributes9);
						ConfigEntry<T> val4 = config(englishName, name4, value2, new ConfigDescription(desc, (AcceptableValueBase)null, new object[1] { configurationManagerAttributes9 }));
						val4.SettingChanged += delegate
						{
							item.Reload