Decompiled source of Outsiders v1.5.5

Outsiders.dll

Decompiled a year ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Linq.Expressions;
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.Cryptography;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using CreatureManager;
using HarmonyLib;
using ItemManager;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using ServerSync;
using TMPro;
using UnityEngine;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Core.Tokens;
using YamlDotNet.Helpers;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.BufferedDeserialization;
using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators;
using YamlDotNet.Serialization.Converters;
using YamlDotNet.Serialization.EventEmitters;
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization.NodeDeserializers;
using YamlDotNet.Serialization.NodeTypeResolvers;
using YamlDotNet.Serialization.ObjectFactories;
using YamlDotNet.Serialization.ObjectGraphTraversalStrategies;
using YamlDotNet.Serialization.ObjectGraphVisitors;
using YamlDotNet.Serialization.Schemas;
using YamlDotNet.Serialization.TypeInspectors;
using YamlDotNet.Serialization.TypeResolvers;
using YamlDotNet.Serialization.Utilities;
using YamlDotNet.Serialization.ValueDeserializers;

[assembly: AssemblyFileVersion("1.5.5")]
[assembly: Guid("29D394C1-8423-4048-B5A7-08ABE81DBA99")]
[assembly: ComVisible(false)]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyProduct("Outsiders")]
[assembly: AssemblyCompany("UnJohnny")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyTitle("Outsiders")]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.5.5.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[<344870b2-c0d5-4be5-b6e1-3f228a7ef6ac>Embedded]
	internal sealed class <344870b2-c0d5-4be5-b6e1-3f228a7ef6ac>EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[<344870b2-c0d5-4be5-b6e1-3f228a7ef6ac>Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class <ad5c2e39-9f49-4bca-be00-35998cd25028>NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public <ad5c2e39-9f49-4bca-be00-35998cd25028>NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public <ad5c2e39-9f49-4bca-be00-35998cd25028>NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[<344870b2-c0d5-4be5-b6e1-3f228a7ef6ac>Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class <55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public <55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace Outsiders
{
	[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
	[BepInPlugin("UnJohnny.Outsiders", "Outsiders", "1.5.5")]
	[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(1)]
	public class OutsidersPlugin : BaseUnityPlugin
	{
		[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)]
		public enum Toggle
		{
			On = 1,
			Off = 0
		}

		[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)]
		private class ConfigurationManagerAttributes
		{
			public bool? Browsable = false;
		}

		internal const string ModName = "Outsiders";

		internal const string ModVersion = "1.5.5";

		internal const string Author = "UnJohnny";

		private const string ModGUID = "UnJohnny.Outsiders";

		private static string ConfigFileName = "UnJohnny.Outsiders.cfg";

		private static string ConfigFileFullPath;

		internal static string ConnectionError;

		private readonly Harmony _harmony = new Harmony("UnJohnny.Outsiders");

		public static readonly ManualLogSource OutsidersLogger;

		private static readonly ConfigSync ConfigSync;

		private static ConfigEntry<Toggle> _serverConfigLocked;

		public void Awake()
		{
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_045a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0517: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c6: Unknown result type (might be due to invalid IL or missing references)
			_serverConfigLocked = config("1 - General", "Lock Configuration", Toggle.On, "If on, the configuration is locked and can be changed by server admins only.");
			ConfigSync.AddLockingConfigEntry<Toggle>(_serverConfigLocked);
			AssetBundle val = CreatureManager.PrefabManager.RegisterAssetBundle("outsiders");
			Creature creature = new Creature(val, "Out_Unmaker")
			{
				ConfigurationEnabled = false,
				CanSpawn = false
			};
			creature.Localize().English("Unmaker");
			Item item = new Item(val, "Out_UnmakerScythe");
			Item item2 = new Item(val, "Out_UnmakerCut");
			Item item3 = new Item(val, "Out_VoidBall");
			Item item4 = new Item(val, "Out_VoidSummon");
			Creature creature2 = new Creature(val, "Out_VoidTent")
			{
				ConfigurationEnabled = false,
				CanSpawn = false
			};
			Item item5 = new Item(val, "Out_voidtentacle_attack");
			Creature creature3 = new Creature(val, "Out_Opulence")
			{
				ConfigurationEnabled = false,
				CanSpawn = false
			};
			creature.Localize().English("Opulence");
			Item item6 = new Item(val, "Out_OpulenceSword");
			Item item7 = new Item(val, "Out_OpulenceCut");
			Item item8 = new Item(val, "Out_Opulence_meteor");
			Creature creature4 = new Creature(val, "Out_Wendigo")
			{
				Biome = (Biome)9,
				GroupSize = new CreatureManager.Range(1f, 2f),
				CheckSpawnInterval = 60,
				SpawnChance = 70f,
				SpecificSpawnTime = SpawnTime.Night,
				Maximum = 4
			};
			creature4.Drops["DeerHide"].Amount = new CreatureManager.Range(2f, 4f);
			creature4.Drops["JuteRed"].Amount = new CreatureManager.Range(1f, 3f);
			creature4.Drops["TrophyDeer"].Amount = new CreatureManager.Range(1f, 1f);
			creature4.Drops["TrophyDeer"].DropChance = 50f;
			Item item9 = new Item(val, "Out_Wendigo_claw");
			Item item10 = new Item(val, "Out_Wendigo_jump");
			Creature creature5 = new Creature(val, "Out_BirchElder")
			{
				Biome = (Biome)17,
				GroupSize = new CreatureManager.Range(1f, 1f),
				CheckSpawnInterval = 80,
				SpawnChance = 50f,
				SpecificSpawnTime = SpawnTime.Always,
				Maximum = 2
			};
			creature5.Drops["FineWood"].Amount = new CreatureManager.Range(16f, 20f);
			creature5.Drops["BirchSeeds"].Amount = new CreatureManager.Range(1f, 3f);
			creature5.Drops["AncientSeed"].Amount = new CreatureManager.Range(1f, 1f);
			creature5.Drops["AncientSeed"].DropChance = 50f;
			Item item11 = new Item(val, "Out_Birch_stomp");
			Item item12 = new Item(val, "Out_Birch_attack");
			Creature creature6 = new Creature(val, "Out_Apparition")
			{
				Biome = (Biome)27,
				GroupSize = new CreatureManager.Range(1f, 1f),
				CanHaveStars = false,
				CheckSpawnInterval = 80,
				SpawnChance = 20f,
				SpecificSpawnTime = SpawnTime.Night,
				RequiredWeather = Weather.None,
				Maximum = 1
			};
			Item item13 = new Item(val, "Out_Apparition_claw");
			Item item14 = new Item(val, "Out_Apparition_jump");
			Creature creature7 = new Creature(val, "Out_Yeti")
			{
				Biome = (Biome)4,
				GroupSize = new CreatureManager.Range(1f, 2f),
				CanHaveStars = false,
				CheckSpawnInterval = 80,
				SpawnChance = 40f,
				SpecificSpawnTime = SpawnTime.Always,
				Maximum = 2
			};
			creature7.Drops["WolfPelt"].Amount = new CreatureManager.Range(4f, 6f);
			creature7.Drops["Crystal"].Amount = new CreatureManager.Range(2f, 2f);
			creature7.Drops["WolfClaw"].Amount = new CreatureManager.Range(1f, 3f);
			Item item15 = new Item(val, "Out_Yeti_groundslam");
			Item item16 = new Item(val, "Out_Yeti_punch");
			Item item17 = new Item(val, "Out_Yeti_throw");
			Creature creature8 = new Creature(val, "Out_Voidling")
			{
				Biome = (Biome)8,
				GroupSize = new CreatureManager.Range(2f, 4f),
				CheckSpawnInterval = 40,
				SpawnChance = 50f,
				SpecificSpawnTime = SpawnTime.Night,
				Maximum = 6
			};
			creature8.Drops["Entrails"].Amount = new CreatureManager.Range(1f, 2f);
			creature8.Drops["Out_VoidOrb"].Amount = new CreatureManager.Range(1f, 1f);
			creature8.Drops["Out_VoidOrb"].DropChance = 50f;
			Item item18 = new Item(val, "Out_Voidling_claw");
			Creature creature9 = new Creature(val, "Out_VoidCultist")
			{
				Biome = (Biome)16,
				GroupSize = new CreatureManager.Range(1f, 2f),
				CheckSpawnInterval = 80,
				SpawnChance = 50f,
				SpecificSpawnTime = SpawnTime.Night,
				Maximum = 2
			};
			creature9.Drops["Coins"].Amount = new CreatureManager.Range(50f, 80f);
			creature9.Drops["Out_VoidOrb"].Amount = new CreatureManager.Range(1f, 3f);
			Item item19 = new Item(val, "Out_VoidCultist_summon");
			Item item20 = new Item(val, "Out_VoidCultist_voidball");
			Creature creature10 = new Creature(val, "Out_Voidlord")
			{
				Biome = (Biome)16,
				CheckSpawnInterval = 1000,
				SpawnChance = 3f,
				SpecificSpawnTime = SpawnTime.Night,
				Maximum = 1
			};
			creature10.Drops["Out_VoidOrb"].Amount = new CreatureManager.Range(8f, 10f);
			creature10.Drops["Out_TrophyVoidLord"].Amount = new CreatureManager.Range(1f, 1f);
			Item item21 = new Item(val, "Out_Voidlord_meteor");
			Item item22 = new Item(val, "Out_Voidlord_stomp");
			Item item23 = new Item(val, "Out_Voidlord_Summon");
			Item item24 = new Item(val, "Out_TrophyVoidLord");
			Item item25 = new Item(val, "Out_VoidOrb");
			Item item26 = new Item(val, "Out_Hagalaz");
			item26.Crafting.Add(CraftingTable.None, 0);
			item26.Name.English("Rune of Hagalaz");
			item26.Description.English("Summons forth the ousider of destruction.");
			item26.RequiredItems.Add("Stone", 30);
			item26.RequiredItems.Add("Out_VoidOrb", 10);
			item26.RequiredItems.Add("SurtlingCore", 4);
			Item item27 = new Item(val, "Out_Fehu");
			item27.Crafting.Add(CraftingTable.None, 0);
			item27.Name.English("Rune of Fehu");
			item27.Description.English("Summons forth the ousider of wealth.");
			item27.RequiredItems.Add("Stone", 30);
			item27.RequiredItems.Add("Coins", 200);
			item27.RequiredItems.Add("Ruby", 4);
			ItemManager.PrefabManager.RegisterPrefab(val, "vfx_corpse_destruction_humanoid");
			ItemManager.PrefabManager.RegisterPrefab(val, "vfx_RedBlood");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_un_alerted");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_un_death");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_un_hit");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_un_idle");
			ItemManager.PrefabManager.RegisterPrefab(val, "vfx_spawn_tentacles");
			ItemManager.PrefabManager.RegisterPrefab(val, "vfx_void_death");
			ItemManager.PrefabManager.RegisterPrefab(val, "vfx_VoidBallHit");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_voidball_hit");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_voidsummon");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_voidball_cast");
			ItemManager.PrefabManager.RegisterPrefab(val, "Voidball_projectile");
			ItemManager.PrefabManager.RegisterPrefab(val, "Unmaker_Ragdoll");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_op_alerted");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_op_death");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_op_hit");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_op_idle");
			ItemManager.PrefabManager.RegisterPrefab(val, "fx_gold_hit");
			ItemManager.PrefabManager.RegisterPrefab(val, "Gold_projectile");
			ItemManager.PrefabManager.RegisterPrefab(val, "Opulence_Ragdoll");
			ItemManager.PrefabManager.RegisterPrefab(val, "Wendigo_Ragdoll");
			ItemManager.PrefabManager.RegisterPrefab(val, "BirchElder_Ragdoll");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_apparition_alerted");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_apparition_attack");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_apparition_death");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_apparition_idle");
			ItemManager.PrefabManager.RegisterPrefab(val, "Yeti_throw_projectile");
			ItemManager.PrefabManager.RegisterPrefab(val, "Yeti_Ragdoll");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_Voidling_alerted");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_Voidling_attack");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_Voidling_death");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_Voidling_hit");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_Voidling_idle");
			ItemManager.PrefabManager.RegisterPrefab(val, "Voidling_Ragdoll");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_Voidcultist_alerted");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_Voidcultist_death");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_Voidcultist_hit");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_Voidcultist_idle");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_VoidCultist_ritual");
			ItemManager.PrefabManager.RegisterPrefab(val, "VoidCultist_Ragdoll");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_Voidlord_alerted");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_Voidlord_attack");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_Voidlord_death");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_Voidlord_hit");
			ItemManager.PrefabManager.RegisterPrefab(val, "sfx_Voidlord_idle");
			ItemManager.PrefabManager.RegisterPrefab(val, "Voidlord_Ragdoll");
			ItemManager.PrefabManager.RegisterPrefab(val, "fx_star_hit");
			ItemManager.PrefabManager.RegisterPrefab(val, "fx_voidlord_awake");
			ItemManager.PrefabManager.RegisterPrefab(val, "Star_projectile");
			ItemManager.PrefabManager.RegisterPrefab(val, "fx_voidlord_portal");
			ItemManager.PrefabManager.RegisterPrefab(val, "Out_Monolith");
			ItemManager.PrefabManager.RegisterPrefab(val, "FehuSummon");
			ItemManager.PrefabManager.RegisterPrefab(val, "HagalazSummon");
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			_harmony.PatchAll(executingAssembly);
			SetupWatcher();
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
		}

		private void SetupWatcher()
		{
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
			fileSystemWatcher.Changed += ReadConfigValues;
			fileSystemWatcher.Created += ReadConfigValues;
			fileSystemWatcher.Renamed += ReadConfigValues;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
		}

		private void ReadConfigValues(object sender, FileSystemEventArgs e)
		{
			if (!File.Exists(ConfigFileFullPath))
			{
				return;
			}
			try
			{
				OutsidersLogger.LogDebug((object)"ReadConfigValues called");
				((BaseUnityPlugin)this).Config.Reload();
			}
			catch
			{
				OutsidersLogger.LogError((object)("There was an issue loading your " + ConfigFileName));
				OutsidersLogger.LogError((object)"Please check your config entries for spelling and format!");
			}
		}

		private ConfigEntry<T> config<[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)] T>(string group, string name, T value, ConfigDescription description, bool synchronizedSetting = true)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			ConfigDescription val = new ConfigDescription(description.Description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]"), description.AcceptableValues, description.Tags);
			ConfigEntry<T> val2 = ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, val);
			SyncedConfigEntry<T> syncedConfigEntry = ConfigSync.AddConfigEntry<T>(val2);
			syncedConfigEntry.SynchronizedConfig = synchronizedSetting;
			return val2;
		}

		private ConfigEntry<T> config<[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)] T>(string group, string name, T value, string description, bool synchronizedSetting = true)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting);
		}

		static OutsidersPlugin()
		{
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
			ConnectionError = "";
			OutsidersLogger = Logger.CreateLogSource("Outsiders");
			ConfigSync = new ConfigSync("UnJohnny.Outsiders")
			{
				DisplayName = "Outsiders",
				CurrentVersion = "1.5.5",
				MinimumRequiredVersion = "1.5.5"
			};
			_serverConfigLocked = null;
		}
	}
	[HarmonyPatch(typeof(ZNet), "OnNewConnection")]
	public static class RegisterAndCheckVersion
	{
		[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(1)]
		private static void Prefix(ZNetPeer peer, ref ZNet __instance)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			OutsidersPlugin.OutsidersLogger.LogDebug((object)"Registering version RPC handler");
			peer.m_rpc.Register<ZPackage>("Outsiders_VersionCheck", (Action<ZRpc, ZPackage>)RpcHandlers.RPC_Outsiders_Version);
			OutsidersPlugin.OutsidersLogger.LogDebug((object)"Invoking version check");
			ZPackage val = new ZPackage();
			val.Write("1.5.5");
			val.Write(RpcHandlers.ComputeHashForMod().Replace("-", ""));
			peer.m_rpc.Invoke("Outsiders_VersionCheck", new object[1] { val });
		}
	}
	[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(1)]
	[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
	[HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")]
	public static class VerifyClient
	{
		private static bool Prefix(ZRpc rpc, ZPackage pkg, ref ZNet __instance)
		{
			if (!__instance.IsServer() || RpcHandlers.ValidatedPeers.Contains(rpc))
			{
				return true;
			}
			OutsidersPlugin.OutsidersLogger.LogWarning((object)("Peer (" + rpc.m_socket.GetHostName() + ") never sent version or couldn't due to previous disconnect, disconnecting"));
			rpc.Invoke("Error", new object[1] { 3 });
			return false;
		}

		private static void Postfix(ZNet __instance)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.instance.GetServerPeerID(), "RequestAdminSync", new object[1] { (object)new ZPackage() });
		}
	}
	[HarmonyPatch(typeof(FejdStartup), "ShowConnectError")]
	public class ShowConnectionError
	{
		[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(1)]
		private static void Postfix(FejdStartup __instance)
		{
			if (__instance.m_connectionFailedPanel.activeSelf)
			{
				__instance.m_connectionFailedError.fontSizeMax = 25f;
				__instance.m_connectionFailedError.fontSizeMin = 15f;
				TMP_Text connectionFailedError = __instance.m_connectionFailedError;
				connectionFailedError.text = connectionFailedError.text + "\n" + OutsidersPlugin.ConnectionError;
			}
		}
	}
	[HarmonyPatch(typeof(ZNet), "Disconnect")]
	public static class RemoveDisconnectedPeerFromVerified
	{
		[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(1)]
		private static void Prefix(ZNetPeer peer, ref ZNet __instance)
		{
			if (__instance.IsServer())
			{
				OutsidersPlugin.OutsidersLogger.LogInfo((object)("Peer (" + peer.m_rpc.m_socket.GetHostName() + ") disconnected, removing from validated list"));
				RpcHandlers.ValidatedPeers.Remove(peer.m_rpc);
			}
		}
	}
	[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
	[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(1)]
	public static class RpcHandlers
	{
		public static readonly List<ZRpc> ValidatedPeers = new List<ZRpc>();

		public static void RPC_Outsiders_Version(ZRpc rpc, ZPackage pkg)
		{
			string text = pkg.ReadString();
			string text2 = pkg.ReadString();
			string text3 = ComputeHashForMod().Replace("-", "");
			OutsidersPlugin.OutsidersLogger.LogInfo((object)("Version check, local: 1.5.5,  remote: " + text));
			if (text2 != text3 || text != "1.5.5")
			{
				OutsidersPlugin.ConnectionError = "Outsiders Installed: 1.5.5 " + text3 + "\n Needed: " + text + " " + text2;
				if (ZNet.instance.IsServer())
				{
					OutsidersPlugin.OutsidersLogger.LogWarning((object)("Peer (" + rpc.m_socket.GetHostName() + ") has incompatible version, disconnecting..."));
					rpc.Invoke("Error", new object[1] { 3 });
				}
			}
			else if (!ZNet.instance.IsServer())
			{
				OutsidersPlugin.OutsidersLogger.LogInfo((object)"Received same version from server!");
			}
			else
			{
				OutsidersPlugin.OutsidersLogger.LogInfo((object)("Adding peer (" + rpc.m_socket.GetHostName() + ") to validated list"));
				ValidatedPeers.Add(rpc);
			}
		}

		public static string ComputeHashForMod()
		{
			using SHA256 sHA = SHA256.Create();
			byte[] array = sHA.ComputeHash(File.ReadAllBytes(Assembly.GetExecutingAssembly().Location));
			StringBuilder stringBuilder = new StringBuilder();
			byte[] array2 = array;
			foreach (byte b in array2)
			{
				stringBuilder.Append(b.ToString("X2"));
			}
			return stringBuilder.ToString();
		}
	}
}
namespace LocalizationManager
{
	[PublicAPI]
	[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
	[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(1)]
	public class Localizer
	{
		private static readonly Dictionary<string, Dictionary<string, Func<string>>> PlaceholderProcessors;

		private static readonly Dictionary<string, Dictionary<string, string>> loadedTexts;

		private static readonly ConditionalWeakTable<Localization, string> localizationLanguage;

		private static readonly List<WeakReference<Localization>> localizationObjects;

		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)]
		private static BaseUnityPlugin _plugin;

		private static readonly List<string> fileExtensions;

		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([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t)));
				}
				return _plugin;
			}
		}

		private static void UpdatePlaceholderText(Localization localization, string key)
		{
			localizationLanguage.TryGetValue(localization, out var value);
			string text = loadedTexts[value][key];
			if (PlaceholderProcessors.TryGetValue(key, out var value2))
			{
				text = value2.Aggregate(text, [<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (string current, KeyValuePair<string, Func<string>> kv) => current.Replace("{" + kv.Key + "}", kv.Value()));
			}
			localization.AddWord(key, text);
		}

		public static void AddPlaceholder<T>(string key, string placeholder, ConfigEntry<T> config, [<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(new byte[] { 2, 1, 1 })] Func<T, string> convertConfigValue = null)
		{
			if (convertConfigValue == null)
			{
				convertConfigValue = [<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] [return: <ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(1)] (T val) => val.ToString();
			}
			if (!PlaceholderProcessors.ContainsKey(key))
			{
				PlaceholderProcessors[key] = new Dictionary<string, Func<string>>();
			}
			config.SettingChanged += [<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (object _, EventArgs _) =>
			{
				UpdatePlaceholder();
			};
			if (loadedTexts.ContainsKey(Localization.instance.GetSelectedLanguage()))
			{
				UpdatePlaceholder();
			}
			void UpdatePlaceholder()
			{
				PlaceholderProcessors[key][placeholder] = () => convertConfigValue(config.Value);
				UpdatePlaceholderText(Localization.instance, key);
			}
		}

		public static void AddText(string key, string text)
		{
			List<WeakReference<Localization>> list = new List<WeakReference<Localization>>();
			foreach (WeakReference<Localization> localizationObject in localizationObjects)
			{
				if (localizationObject.TryGetTarget(out var target))
				{
					Dictionary<string, string> dictionary = loadedTexts[localizationLanguage.GetOrCreateValue(target)];
					if (!target.m_translations.ContainsKey(key))
					{
						dictionary[key] = text;
						target.AddWord(key, text);
					}
				}
				else
				{
					list.Add(localizationObject);
				}
			}
			foreach (WeakReference<Localization> item in list)
			{
				localizationObjects.Remove(item);
			}
		}

		public static void Load()
		{
			LoadLocalization(Localization.instance, Localization.instance.GetSelectedLanguage());
		}

		private static void LoadLocalization(Localization __instance, string language)
		{
			if (!localizationLanguage.Remove(__instance))
			{
				localizationObjects.Add(new WeakReference<Localization>(__instance));
			}
			localizationLanguage.Add(__instance, language);
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			foreach (string item in from f in Directory.GetFiles(Path.GetDirectoryName(Paths.PluginPath), plugin.Info.Metadata.Name + ".*", SearchOption.AllDirectories)
				where fileExtensions.IndexOf(Path.GetExtension(f)) >= 0
				select f)
			{
				string text = Path.GetFileNameWithoutExtension(item).Split(new char[1] { '.' })[1];
				if (dictionary.ContainsKey(text))
				{
					Debug.LogWarning((object)("Duplicate key " + text + " found for " + plugin.Info.Metadata.Name + ". The duplicate file found at " + item + " will be skipped."));
				}
				else
				{
					dictionary[text] = item;
				}
			}
			byte[] array = LoadTranslationFromAssembly("English");
			if (array == null)
			{
				throw new Exception("Found no English localizations in mod " + plugin.Info.Metadata.Name + ". Expected an embedded resource translations/English.json or translations/English.yml.");
			}
			Dictionary<string, string> dictionary2 = new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(Encoding.UTF8.GetString(array));
			if (dictionary2 == null)
			{
				throw new Exception("Localization for mod " + plugin.Info.Metadata.Name + " failed: Localization file was empty.");
			}
			string text2 = null;
			if (language != "English")
			{
				if (dictionary.ContainsKey(language))
				{
					text2 = File.ReadAllText(dictionary[language]);
				}
				else
				{
					byte[] array2 = LoadTranslationFromAssembly(language);
					if (array2 != null)
					{
						text2 = Encoding.UTF8.GetString(array2);
					}
				}
			}
			if (text2 == null && dictionary.ContainsKey("English"))
			{
				text2 = File.ReadAllText(dictionary["English"]);
			}
			if (text2 != null)
			{
				foreach (KeyValuePair<string, string> item2 in new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(text2) ?? new Dictionary<string, string>())
				{
					dictionary2[item2.Key] = item2.Value;
				}
			}
			loadedTexts[language] = dictionary2;
			foreach (KeyValuePair<string, string> item3 in dictionary2)
			{
				UpdatePlaceholderText(__instance, item3.Key);
			}
		}

		static Localizer()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			PlaceholderProcessors = new Dictionary<string, Dictionary<string, Func<string>>>();
			loadedTexts = new Dictionary<string, Dictionary<string, string>>();
			localizationLanguage = new ConditionalWeakTable<Localization, string>();
			localizationObjects = new List<WeakReference<Localization>>();
			fileExtensions = new List<string> { ".json", ".yml" };
			Harmony val = new Harmony("org.bepinex.helpers.LocalizationManager");
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Localization), "LoadCSV", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "LoadLocalization", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		[return: <ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)]
		private static byte[] LoadTranslationFromAssembly(string language)
		{
			foreach (string fileExtension in fileExtensions)
			{
				byte[] array = ReadEmbeddedFileBytes("translations." + language + fileExtension);
				if (array != null)
				{
					return array;
				}
			}
			return null;
		}

		[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(2)]
		public static byte[] ReadEmbeddedFileBytes([<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(1)] string resourceFileName, Assembly containingAssembly = null)
		{
			using MemoryStream memoryStream = new MemoryStream();
			if ((object)containingAssembly == null)
			{
				containingAssembly = Assembly.GetCallingAssembly();
			}
			string text = containingAssembly.GetManifestResourceNames().FirstOrDefault([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (string str) => str.EndsWith(resourceFileName, StringComparison.Ordinal));
			if (text != null)
			{
				containingAssembly.GetManifestResourceStream(text)?.CopyTo(memoryStream);
			}
			return (memoryStream.Length == 0L) ? null : memoryStream.ToArray();
		}
	}
}
namespace ItemManager
{
	[PublicAPI]
	public enum CraftingTable
	{
		None,
		[InternalName("piece_workbench")]
		Workbench,
		[InternalName("piece_cauldron")]
		Cauldron,
		[InternalName("forge")]
		Forge,
		[InternalName("piece_artisanstation")]
		ArtisanTable,
		[InternalName("piece_stonecutter")]
		StoneCutter,
		Custom
	}
	[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(1)]
	[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
	public class InternalName : Attribute
	{
		public readonly string internalName;

		public InternalName(string internalName)
		{
			this.internalName = internalName;
		}
	}
	[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(1)]
	[PublicAPI]
	[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
	public class RequiredResourceList
	{
		public readonly List<Requirement> Requirements = new List<Requirement>();

		public void Add(string itemName, int amount)
		{
			Requirements.Add(new Requirement
			{
				itemName = itemName,
				amount = amount
			});
		}
	}
	[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
	[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(1)]
	[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
			});
		}
	}
	public struct Requirement
	{
		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(1)]
		public string itemName;

		public int amount;
	}
	public struct CraftingStationConfig
	{
		public CraftingTable Table;

		public int level;

		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)]
		public string custom;
	}
	[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(1)]
	[PublicAPI]
	[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
	public class Item
	{
		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
		private class ItemConfig
		{
			public ConfigEntry<string> craft = null;

			[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(new byte[] { 2, 1 })]
			public ConfigEntry<string> upgrade;

			public ConfigEntry<CraftingTable> table = null;

			public ConfigEntry<int> tableLevel = null;

			public ConfigEntry<string> customTable = null;

			[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)]
			public ConfigEntry<int> maximumTableLevel;
		}

		[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)]
		private class ConfigurationManagerAttributes
		{
			[UsedImplicitly]
			public int? Order;

			[UsedImplicitly]
			public bool? Browsable;

			[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(new byte[] { 2, 1 })]
			[UsedImplicitly]
			public Action<ConfigEntryBase> CustomDrawer;
		}

		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
		private class SerializedRequirements
		{
			public readonly List<Requirement> Reqs;

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

			public SerializedRequirements(string reqs)
			{
				Reqs = reqs.Split(new char[1] { ',' }).Select([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (string r) =>
				{
					string[] array = r.Split(new char[1] { ':' });
					Requirement result = default(Requirement);
					result.itemName = array[0];
					result.amount = ((array.Length <= 1 || !int.TryParse(array[1], out var result2)) ? 1 : result2);
					return result;
				}).ToList();
			}

			public override string ToString()
			{
				return string.Join(",", Reqs.Select([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (Requirement r) => $"{r.itemName}:{r.amount}"));
			}

			public static Requirement[] toPieceReqs(ObjectDB objectDB, SerializedRequirements craft, SerializedRequirements upgrade)
			{
				//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e5: 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_00ef: Expected O, but got Unknown
				//IL_00f4: Expected O, but got Unknown
				Dictionary<string, Requirement> dictionary = craft.Reqs.Where((Requirement r) => r.itemName != "").ToDictionary((Func<Requirement, string>)([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (Requirement r) => r.itemName), (Func<Requirement, Requirement>)([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (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_001f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0026: Unknown result type (might be due to invalid IL or missing references)
					ItemDrop val5 = ResItem(r);
					return (val5 == null) ? ((Requirement)null) : new Requirement
					{
						m_amount = r.amount,
						m_resItem = val5,
						m_amountPerLevel = 0
					};
				}));
				foreach (Requirement item in upgrade.Reqs.Where((Requirement r) => r.itemName != ""))
				{
					if (!dictionary.TryGetValue(item.itemName, out var value) || value == null)
					{
						ItemDrop val = ResItem(item);
						if (val != null)
						{
							string itemName = item.itemName;
							Requirement val2 = new Requirement
							{
								m_resItem = val,
								m_amount = 0
							};
							Requirement val3 = val2;
							dictionary[itemName] = val2;
							value = val3;
						}
					}
					if (value != null)
					{
						value.m_amountPerLevel = item.amount;
					}
				}
				return dictionary.Values.Where([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (Requirement v) => v != null).ToArray();
				[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(2)]
				ItemDrop ResItem(Requirement r)
				{
					GameObject itemPrefab = objectDB.GetItemPrefab(r.itemName);
					ItemDrop val4 = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null);
					if ((Object)(object)val4 == (Object)null)
					{
						Debug.LogWarning((object)("The required item '" + r.itemName + "' does not exist."));
					}
					return val4;
				}
			}
		}

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

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

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

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

		public static bool ConfigurationEnabled = true;

		public readonly GameObject Prefab;

		public readonly RequiredResourceList RequiredItems = new RequiredResourceList();

		public readonly RequiredResourceList RequiredUpgradeItems = new RequiredResourceList();

		public readonly CraftingStationList Crafting = new CraftingStationList();

		public int CraftAmount = 1;

		public int MaximumRequiredStationLevel = int.MaxValue;

		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)]
		private LocalizeKey _name;

		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)]
		private LocalizeKey _description;

		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)]
		private static Localization _english;

		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)]
		private static BaseUnityPlugin _plugin;

		private static bool hasConfigSync = true;

		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)]
		private static object _configSync;

		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
		{
			get
			{
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Expected O, but got Unknown
				if (_english == null)
				{
					_english = new Localization();
					_english.SetupLanguage("English");
				}
				return _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([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t)));
				}
				return _plugin;
			}
		}

		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)]
		private static object configSync
		{
			[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(2)]
			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)
		{
			Prefab = PrefabManager.RegisterPrefab(bundle, prefabName, addToObjectDb: true);
			registeredItems.Add(this);
			itemDropMap[Prefab.GetComponent<ItemDrop>()] = this;
		}

		internal static void Patch_FejdStartup()
		{
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Expected O, but got Unknown
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Expected O, but got Unknown
			//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0406: Expected O, but got Unknown
			//IL_052c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0536: Expected O, but got Unknown
			Type configManagerType = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (Assembly a) => a.GetName().Name == "ConfigurationManager")?.GetType("ConfigurationManager.ConfigurationManager");
			object configManager = ((configManagerType == null) ? null : Chainloader.ManagerObject.GetComponent(configManagerType));
			if (!ConfigurationEnabled)
			{
				return;
			}
			bool saveOnConfigSet = plugin.Config.SaveOnConfigSet;
			plugin.Config.SaveOnConfigSet = false;
			foreach (Item registeredItem in registeredItems)
			{
				Item item = registeredItem;
				ItemConfig itemConfig2 = (itemConfigs[item] = new ItemConfig());
				ItemConfig cfg = itemConfig2;
				if (item.Crafting.Stations.Count <= 0)
				{
					continue;
				}
				string localizedName = new Regex("['[\"\\]]").Replace(english.Localize(item.Prefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_name), "").Trim();
				int order = 0;
				List<ConfigurationManagerAttributes> hideWhenNoneAttributes = new List<ConfigurationManagerAttributes>();
				cfg.table = config(localizedName, "Crafting Station", item.Crafting.Stations.First().Table, new ConfigDescription("Crafting station where " + localizedName + " is available.", (AcceptableValueBase)null, new object[1]
				{
					new ConfigurationManagerAttributes
					{
						Order = (order -= 1)
					}
				}));
				ConfigurationManagerAttributes customTableAttributes = new ConfigurationManagerAttributes
				{
					Order = (order -= 1),
					Browsable = (cfg.table.Value == CraftingTable.Custom)
				};
				cfg.customTable = config(localizedName, "Custom Crafting Station", item.Crafting.Stations.First().custom ?? "", new ConfigDescription("", (AcceptableValueBase)null, new object[1] { customTableAttributes }));
				cfg.table.SettingChanged += TableConfigChanged;
				cfg.customTable.SettingChanged += TableConfigChanged;
				ConfigurationManagerAttributes configurationManagerAttributes = new ConfigurationManagerAttributes
				{
					Order = (order -= 1),
					Browsable = (cfg.table.Value != CraftingTable.None)
				};
				hideWhenNoneAttributes.Add(configurationManagerAttributes);
				cfg.tableLevel = config(localizedName, "Crafting Station Level", item.Crafting.Stations.First().level, new ConfigDescription("Required crafting station level to craft " + localizedName + ".", (AcceptableValueBase)null, new object[1] { configurationManagerAttributes }));
				cfg.tableLevel.SettingChanged += [<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (object _, EventArgs _) =>
				{
					if (activeRecipes.Count > 0)
					{
						activeRecipes[item].First().m_minStationLevel = cfg.tableLevel.Value;
					}
				};
				if (item.Prefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_maxQuality > 1)
				{
					cfg.maximumTableLevel = config(localizedName, "Maximum Crafting Station Level", (item.MaximumRequiredStationLevel == int.MaxValue) ? (item.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 " + localizedName + ".", (AcceptableValueBase)null, new object[1] { configurationManagerAttributes }));
				}
				cfg.craft = itemConfig("Crafting Costs", new SerializedRequirements(item.RequiredItems.Requirements).ToString(), "Item costs to craft " + localizedName);
				if (item.Prefab.GetComponent<ItemDrop>().m_itemData.m_shared.m_maxQuality > 1)
				{
					cfg.upgrade = itemConfig("Upgrading Costs", new SerializedRequirements(item.RequiredUpgradeItems.Requirements).ToString(), "Item costs per level to upgrade " + localizedName);
				}
				cfg.craft.SettingChanged += ConfigChanged;
				if (cfg.upgrade != null)
				{
					cfg.upgrade.SettingChanged += ConfigChanged;
				}
				void ConfigChanged(object o, EventArgs e)
				{
					if (Object.op_Implicit((Object)(object)ObjectDB.instance) && activeRecipes.ContainsKey(item))
					{
						foreach (Recipe item2 in activeRecipes[item])
						{
							item2.m_resources = SerializedRequirements.toPieceReqs(ObjectDB.instance, new SerializedRequirements(cfg.craft.Value), new SerializedRequirements(cfg.upgrade?.Value ?? ""));
						}
					}
				}
				void TableConfigChanged(object o, EventArgs e)
				{
					if (activeRecipes.Count > 0)
					{
						if (cfg.table.Value == CraftingTable.None)
						{
							activeRecipes[item].First().m_craftingStation = null;
						}
						else if (cfg.table.Value == CraftingTable.Custom)
						{
							Recipe obj = activeRecipes[item].First();
							GameObject prefab = ZNetScene.instance.GetPrefab(cfg.customTable.Value);
							obj.m_craftingStation = ((prefab != null) ? prefab.GetComponent<CraftingStation>() : null);
						}
						else
						{
							activeRecipes[item].First().m_craftingStation = ZNetScene.instance.GetPrefab(((InternalName)typeof(CraftingTable).GetMember(cfg.table.Value.ToString())[0].GetCustomAttributes(typeof(InternalName)).First()).internalName).GetComponent<CraftingStation>();
						}
					}
					customTableAttributes.Browsable = cfg.table.Value == CraftingTable.Custom;
					foreach (ConfigurationManagerAttributes item3 in hideWhenNoneAttributes)
					{
						item3.Browsable = cfg.table.Value != CraftingTable.None;
					}
					reloadConfigDisplay();
				}
				ConfigEntry<string> itemConfig(string name, string value, string desc)
				{
					//IL_007b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0085: Expected O, but got Unknown
					ConfigurationManagerAttributes configurationManagerAttributes2 = new ConfigurationManagerAttributes
					{
						CustomDrawer = drawConfigTable,
						Order = (order -= 1),
						Browsable = (cfg.table.Value != CraftingTable.None)
					};
					hideWhenNoneAttributes.Add(configurationManagerAttributes2);
					return config(localizedName, name, value, new ConfigDescription(desc, (AcceptableValueBase)null, new object[1] { configurationManagerAttributes2 }));
				}
			}
			if (saveOnConfigSet)
			{
				plugin.Config.SaveOnConfigSet = true;
				plugin.Config.Save();
			}
			void reloadConfigDisplay()
			{
				configManagerType?.GetMethod("BuildSettingList").Invoke(configManager, Array.Empty<object>());
			}
		}

		[HarmonyPriority(700)]
		internal static void Patch_ObjectDBInit(ObjectDB __instance)
		{
			if ((Object)(object)__instance.GetItemPrefab("Wood") == (Object)null)
			{
				return;
			}
			foreach (Item registeredItem in registeredItems)
			{
				List<Recipe> list = new List<Recipe>();
				itemConfigs.TryGetValue(registeredItem, out var value);
				foreach (CraftingStationConfig station in registeredItem.Crafting.Stations)
				{
					Recipe val = ScriptableObject.CreateInstance<Recipe>();
					((Object)val).name = ((Object)registeredItem.Prefab).name + "_Recipe_" + station.Table;
					val.m_amount = registeredItem.CraftAmount;
					val.m_enabled = true;
					val.m_item = registeredItem.Prefab.GetComponent<ItemDrop>();
					val.m_resources = SerializedRequirements.toPieceReqs(__instance, (value == null) ? new SerializedRequirements(registeredItem.RequiredItems.Requirements) : new SerializedRequirements(value.craft.Value), (value == null) ? new SerializedRequirements(registeredItem.RequiredUpgradeItems.Requirements) : new SerializedRequirements(value.upgrade?.Value ?? ""));
					if (((value == null || list.Count > 0) ? station.Table : value.table.Value) == CraftingTable.None)
					{
						val.m_craftingStation = null;
					}
					else if (((value == null || list.Count > 0) ? station.Table : value.table.Value) == CraftingTable.Custom)
					{
						GameObject prefab = ZNetScene.instance.GetPrefab((value == null || list.Count > 0) ? station.custom : value.customTable.Value);
						if (prefab != null)
						{
							val.m_craftingStation = prefab.GetComponent<CraftingStation>();
						}
						else
						{
							Debug.LogWarning((object)("Custom crafting station '" + ((value == null || list.Count > 0) ? station.custom : value.customTable.Value) + "' does not exist"));
						}
					}
					else
					{
						val.m_craftingStation = ZNetScene.instance.GetPrefab(((InternalName)typeof(CraftingTable).GetMember(((value == null || list.Count > 0) ? station.Table : value.table.Value).ToString())[0].GetCustomAttributes(typeof(InternalName)).First()).internalName).GetComponent<CraftingStation>();
					}
					val.m_minStationLevel = ((value == null || list.Count > 0) ? station.level : value.tableLevel.Value);
					list.Add(val);
				}
				activeRecipes[registeredItem] = list;
				__instance.m_recipes.AddRange(list);
			}
		}

		internal static void Patch_MaximumRequiredStationLevel(Recipe __instance, ref int __result, int quality)
		{
			if (itemDropMap.TryGetValue(__instance.m_item, out var value))
			{
				__result = Mathf.Min(Mathf.Max(1, __instance.m_minStationLevel) + (quality - 1), itemConfigs[value].maximumTableLevel?.Value ?? value.MaximumRequiredStationLevel);
			}
		}

		private static bool CheckItemIsUpgrade(InventoryGui gui)
		{
			ItemData value = gui.m_selectedRecipe.Value;
			return value != null && value.m_quality > 0;
		}

		internal static IEnumerable<CodeInstruction> Transpile_InventoryGui(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> instrs = instructions.ToList();
			FieldInfo amountField = AccessTools.DeclaredField(typeof(Recipe), "m_amount");
			int i = 0;
			while (i < instrs.Count)
			{
				yield return instrs[i];
				if (i > 1 && instrs[i - 2].opcode == OpCodes.Ldfld && CodeInstructionExtensions.OperandIs(instrs[i - 2], (MemberInfo)amountField) && instrs[i - 1].opcode == OpCodes.Ldc_I4_1 && instrs[i].operand is Label)
				{
					yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
					yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.DeclaredMethod(typeof(Item), "CheckItemIsUpgrade", (Type[])null, (Type[])null));
					yield return new CodeInstruction(OpCodes.Brtrue, instrs[i].operand);
				}
				int num = i + 1;
				i = num;
			}
		}

		private static void drawConfigTable(ConfigEntryBase cfg)
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Expected O, but got Unknown
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Expected O, but got Unknown
			bool valueOrDefault = cfg.Description.Tags.Select([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (object a) => (a.GetType().Name == "ConfigurationManagerAttributes") ? ((bool?)a.GetType().GetField("ReadOnly")?.GetValue(a)) : null).FirstOrDefault((bool? v) => v.HasValue).GetValueOrDefault();
			List<Requirement> list = new List<Requirement>();
			bool flag = false;
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			foreach (Requirement req in new SerializedRequirements((string)cfg.BoxedValue).Reqs)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				int num = req.amount;
				if (int.TryParse(GUILayout.TextField(num.ToString(), new GUIStyle(GUI.skin.textField)
				{
					fixedWidth = 40f
				}, Array.Empty<GUILayoutOption>()), out var result) && result != num && !valueOrDefault)
				{
					num = result;
					flag = true;
				}
				string text = GUILayout.TextField(req.itemName, Array.Empty<GUILayoutOption>());
				string text2 = (valueOrDefault ? req.itemName : text);
				flag = flag || text2 != req.itemName;
				if (GUILayout.Button("x", new GUIStyle(GUI.skin.button)
				{
					fixedWidth = 21f
				}, Array.Empty<GUILayoutOption>()) && !valueOrDefault)
				{
					flag = true;
				}
				else
				{
					list.Add(new Requirement
					{
						amount = num,
						itemName = text2
					});
				}
				if (GUILayout.Button("+", new GUIStyle(GUI.skin.button)
				{
					fixedWidth = 21f
				}, Array.Empty<GUILayoutOption>()) && !valueOrDefault)
				{
					flag = true;
					list.Add(new Requirement
					{
						amount = 1,
						itemName = ""
					});
				}
				GUILayout.EndHorizontal();
			}
			GUILayout.EndVertical();
			if (flag)
			{
				cfg.BoxedValue = new SerializedRequirements(list).ToString();
			}
		}

		private static ConfigEntry<T> config<[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)] 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<[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)] 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>()));
		}
	}
	[PublicAPI]
	[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
	[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(1)]
	public class LocalizeKey
	{
		public readonly string Key;

		public LocalizeKey(string key)
		{
			Key = key.Replace("$", "");
		}

		public LocalizeKey English(string key)
		{
			return addForLang("English", key);
		}

		public LocalizeKey Swedish(string key)
		{
			return addForLang("Swedish", key);
		}

		public LocalizeKey French(string key)
		{
			return addForLang("French", key);
		}

		public LocalizeKey Italian(string key)
		{
			return addForLang("Italian", key);
		}

		public LocalizeKey German(string key)
		{
			return addForLang("German", key);
		}

		public LocalizeKey Spanish(string key)
		{
			return addForLang("Spanish", key);
		}

		public LocalizeKey Russian(string key)
		{
			return addForLang("Russian", key);
		}

		public LocalizeKey Romanian(string key)
		{
			return addForLang("Romanian", key);
		}

		public LocalizeKey Bulgarian(string key)
		{
			return addForLang("Bulgarian", key);
		}

		public LocalizeKey Macedonian(string key)
		{
			return addForLang("Macedonian", key);
		}

		public LocalizeKey Finnish(string key)
		{
			return addForLang("Finnish", key);
		}

		public LocalizeKey Danish(string key)
		{
			return addForLang("Danish", key);
		}

		public LocalizeKey Norwegian(string key)
		{
			return addForLang("Norwegian", key);
		}

		public LocalizeKey Icelandic(string key)
		{
			return addForLang("Icelandic", key);
		}

		public LocalizeKey Turkish(string key)
		{
			return addForLang("Turkish", key);
		}

		public LocalizeKey Lithuanian(string key)
		{
			return addForLang("Lithuanian", key);
		}

		public LocalizeKey Czech(string key)
		{
			return addForLang("Czech", key);
		}

		public LocalizeKey Hungarian(string key)
		{
			return addForLang("Hungarian", key);
		}

		public LocalizeKey Slovak(string key)
		{
			return addForLang("Slovak", key);
		}

		public LocalizeKey Polish(string key)
		{
			return addForLang("Polish", key);
		}

		public LocalizeKey Dutch(string key)
		{
			return addForLang("Dutch", key);
		}

		public LocalizeKey Portuguese_European(string key)
		{
			return addForLang("Portuguese_European", key);
		}

		public LocalizeKey Portuguese_Brazilian(string key)
		{
			return addForLang("Portuguese_Brazilian", key);
		}

		public LocalizeKey Chinese(string key)
		{
			return addForLang("Chinese", key);
		}

		public LocalizeKey Japanese(string key)
		{
			return addForLang("Japanese", key);
		}

		public LocalizeKey Korean(string key)
		{
			return addForLang("Korean", key);
		}

		public LocalizeKey Hindi(string key)
		{
			return addForLang("Hindi", key);
		}

		public LocalizeKey Thai(string key)
		{
			return addForLang("Thai", key);
		}

		public LocalizeKey Abenaki(string key)
		{
			return addForLang("Abenaki", key);
		}

		public LocalizeKey Croatian(string key)
		{
			return addForLang("Croatian", key);
		}

		public LocalizeKey Georgian(string key)
		{
			return addForLang("Georgian", key);
		}

		public LocalizeKey Greek(string key)
		{
			return addForLang("Greek", key);
		}

		public LocalizeKey Serbian(string key)
		{
			return addForLang("Serbian", key);
		}

		public LocalizeKey Ukrainian(string key)
		{
			return addForLang("Ukrainian", key);
		}

		private LocalizeKey addForLang(string lang, string value)
		{
			if (Localization.instance.GetSelectedLanguage() == lang)
			{
				Localization.instance.AddWord(Key, value);
			}
			else if (lang == "English" && !Localization.instance.m_translations.ContainsKey(Key))
			{
				Localization.instance.AddWord(Key, value);
			}
			return this;
		}
	}
	[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(1)]
	[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
	public static class PrefabManager
	{
		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
		private struct BundleId
		{
			[UsedImplicitly]
			public string assetBundleFileName;

			[UsedImplicitly]
			public string folderName;
		}

		private static readonly Dictionary<BundleId, AssetBundle> bundleCache;

		private static readonly List<GameObject> prefabs;

		private static readonly List<GameObject> ZnetOnlyPrefabs;

		static PrefabManager()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Expected O, but got Unknown
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Expected O, but got Unknown
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Expected O, but got Unknown
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Expected O, but got Unknown
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Expected O, but got Unknown
			bundleCache = new Dictionary<BundleId, AssetBundle>();
			prefabs = new List<GameObject>();
			ZnetOnlyPrefabs = new List<GameObject>();
			Harmony val = new Harmony("org.bepinex.helpers.ItemManager");
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ObjectDB), "CopyOtherDB", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(PrefabManager), "Patch_ObjectDBInit", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ObjectDB), "Awake", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(PrefabManager), "Patch_ObjectDBInit", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ObjectDB), "CopyOtherDB", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Item), "Patch_ObjectDBInit", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ObjectDB), "Awake", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Item), "Patch_ObjectDBInit", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(FejdStartup), "Awake", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Item), "Patch_FejdStartup", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(ZNetScene), "Awake", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.DeclaredMethod(typeof(PrefabManager), "Patch_ZNetSceneAwake", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(InventoryGui), "UpdateRecipe", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Item), "Transpile_InventoryGui", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Recipe), "GetRequiredStationLevel", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Item), "Patch_MaximumRequiredStationLevel", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		public static AssetBundle RegisterAssetBundle(string assetBundleFileName, string folderName = "assets")
		{
			BundleId bundleId = default(BundleId);
			bundleId.assetBundleFileName = assetBundleFileName;
			bundleId.folderName = folderName;
			BundleId key = bundleId;
			if (!bundleCache.TryGetValue(key, out var value))
			{
				Dictionary<BundleId, AssetBundle> dictionary = bundleCache;
				AssetBundle? obj = ((IEnumerable<AssetBundle>)Resources.FindObjectsOfTypeAll<AssetBundle>()).FirstOrDefault((Func<AssetBundle, bool>)([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (AssetBundle a) => ((Object)a).name == assetBundleFileName)) ?? AssetBundle.LoadFromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream(Assembly.GetExecutingAssembly().GetName().Name + "." + folderName + "." + assetBundleFileName));
				AssetBundle result = obj;
				dictionary[key] = obj;
				return result;
			}
			return value;
		}

		public static GameObject RegisterPrefab(string assetBundleFileName, string prefabName, string folderName = "assets")
		{
			return RegisterPrefab(RegisterAssetBundle(assetBundleFileName, folderName), prefabName);
		}

		public static GameObject RegisterPrefab(AssetBundle assets, string prefabName, bool addToObjectDb = false)
		{
			GameObject val = assets.LoadAsset<GameObject>(prefabName);
			if (addToObjectDb)
			{
				prefabs.Add(val);
			}
			else
			{
				ZnetOnlyPrefabs.Add(val);
			}
			return val;
		}

		[HarmonyPriority(700)]
		private static void Patch_ObjectDBInit(ObjectDB __instance)
		{
			foreach (GameObject prefab in prefabs)
			{
				if (!__instance.m_items.Contains(prefab))
				{
					__instance.m_items.Add(prefab);
				}
			}
			__instance.UpdateItemHashes();
		}

		[HarmonyPriority(700)]
		private static void Patch_ZNetSceneAwake(ZNetScene __instance)
		{
			foreach (GameObject item in prefabs.Concat(ZnetOnlyPrefabs))
			{
				__instance.m_prefabs.Add(item);
			}
		}
	}
}
namespace CreatureManager
{
	public enum Toggle
	{
		On,
		Off
	}
	[PublicAPI]
	public enum GlobalKey
	{
		[InternalName("")]
		None,
		[InternalName("defeated_bonemass")]
		KilledBonemass,
		[InternalName("defeated_gdking")]
		KilledElder,
		[InternalName("defeated_goblinking")]
		KilledYagluth,
		[InternalName("defeated_dragon")]
		KilledModer,
		[InternalName("defeated_eikthyr")]
		KilledEikthyr,
		[InternalName("KilledTroll")]
		KilledTroll,
		[InternalName("killed_surtling")]
		KilledSurtling
	}
	[Flags]
	[PublicAPI]
	public enum Weather
	{
		[InternalName("")]
		None = 0,
		[InternalName("Clear")]
		ClearSkies = 1,
		[InternalName("Heath clear")]
		MeadowsClearSkies = 4,
		[InternalName("LightRain")]
		LightRain = 8,
		[InternalName("Rain")]
		Rain = 0x10,
		[InternalName("ThunderStorm")]
		ThunderStorm = 0x20,
		[InternalName("nofogts")]
		ClearThunderStorm = 0x40,
		[InternalName("SwampRain")]
		SwampRain = 0x80,
		[InternalName("Darklands_dark")]
		MistlandsDark = 0x100,
		[InternalName("Ashrain")]
		AshlandsAshrain = 0x200,
		[InternalName("Snow")]
		MountainSnow = 0x400,
		[InternalName("SnowStorm")]
		MountainBlizzard = 0x800,
		[InternalName("DeepForest Mist")]
		BlackForestFog = 0x1000,
		[InternalName("Misty")]
		Fog = 0x2000,
		[InternalName("Twilight_Snow")]
		DeepNorthSnow = 0x4000,
		[InternalName("Twilight_SnowStorm")]
		DeepNorthSnowStorm = 0x8000,
		[InternalName("Twilight_Clear")]
		DeepNorthClear = 0x10000,
		[InternalName("Eikthyr")]
		EikthyrsThunderstorm = 0x20000,
		[InternalName("GDKing")]
		EldersHaze = 0x40000,
		[InternalName("Bonemass")]
		BonemassDownpour = 0x80000,
		[InternalName("Moder")]
		ModersVortex = 0x100000,
		[InternalName("GoblinKing")]
		YagluthsMagicBlizzard = 0x200000,
		[InternalName("Crypt")]
		Crypt = 0x400000,
		[InternalName("SunkenCrypt")]
		SunkenCrypt = 0x800000
	}
	[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(1)]
	[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
	public class InternalName : Attribute
	{
		public readonly string internalName;

		public InternalName(string internalName)
		{
			this.internalName = internalName;
		}
	}
	public enum DropOption
	{
		Disabled,
		Default,
		Custom
	}
	public enum SpawnOption
	{
		Disabled,
		Default,
		Custom
	}
	public enum SpawnTime
	{
		Day,
		Night,
		Always
	}
	public enum SpawnArea
	{
		Center,
		Edge,
		Everywhere
	}
	public enum Forest
	{
		Yes,
		No,
		Both
	}
	[PublicAPI]
	public struct Range
	{
		public float min;

		public float max;

		public Range(float min, float max)
		{
			this.min = min;
			this.max = max;
		}
	}
	[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
	[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(1)]
	[PublicAPI]
	public class Creature
	{
		[PublicAPI]
		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
		public class DropList
		{
			[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
			internal class SerializedDrops
			{
				[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(new byte[] { 1, 0, 1, 1 })]
				public readonly List<KeyValuePair<string, Drop>> Drops;

				public SerializedDrops(DropList drops, Creature creature)
				{
					Drops = (drops.drops ?? creature.Prefab.GetComponent<CharacterDrop>()?.m_drops.ToDictionary([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (Drop drop) => ((Object)drop.m_prefab).name, [<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (Drop drop) => new Drop
					{
						Amount = new Range(drop.m_amountMin, drop.m_amountMax),
						DropChance = drop.m_chance,
						DropOnePerPlayer = drop.m_onePerPlayer,
						MultiplyDropByLevel = drop.m_levelMultiplier
					}) ?? new Dictionary<string, Drop>()).ToList();
				}

				public SerializedDrops([<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(new byte[] { 1, 0, 1, 1 })] List<KeyValuePair<string, Drop>> drops)
				{
					Drops = drops;
				}

				public SerializedDrops(string reqs)
				{
					Drops = (from r in reqs.Split(new char[1] { ',' })
						select r.Split(new char[1] { ':' })).ToDictionary([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (string[] l) => l[0], [<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (string[] parts) =>
					{
						Range amount = new Range(1f, 1f);
						if (parts.Length > 1)
						{
							string[] array = parts[1].Split(new char[1] { '-' });
							if (!int.TryParse(array[0], out var result))
							{
								result = 1;
							}
							if (array.Length == 1 || !int.TryParse(array[0], out var result2))
							{
								result2 = result;
							}
							amount = new Range(result, result2);
						}
						float result3;
						return new Drop
						{
							Amount = amount,
							DropChance = ((parts.Length > 2 && float.TryParse(parts[2], out result3)) ? result3 : 100f),
							DropOnePerPlayer = (parts.Length > 3 && parts[3] == "onePerPlayer"),
							MultiplyDropByLevel = (parts.Length > 4 && parts[4] == "multiplyByLevel")
						};
					}).ToList();
				}

				public override string ToString()
				{
					return string.Join(",", Drops.Select([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (KeyValuePair<string, Drop> kv) => string.Format("{0}:{1}-{2}:{3}:{4}:{5}", kv.Key, kv.Value.Amount.min, kv.Value.Amount.max, kv.Value.DropChance, kv.Value.DropOnePerPlayer ? "onePerPlayer" : "unrestricted", kv.Value.MultiplyDropByLevel ? "multiplyByLevel" : "unaffectedByLevel")));
				}
			}

			[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(new byte[] { 2, 1, 1 })]
			private Dictionary<string, Drop> drops = null;

			public Drop this[string prefabName]
			{
				get
				{
					Drop result;
					if (!(drops ?? (drops = new Dictionary<string, Drop>())).TryGetValue(prefabName, out var value))
					{
						Drop drop2 = (drops[prefabName] = new Drop());
						result = drop2;
					}
					else
					{
						result = value;
					}
					return result;
				}
			}

			public void None()
			{
				drops = new Dictionary<string, Drop>();
			}

			[HarmonyPriority(700)]
			internal static void AddDropsToCreature()
			{
				foreach (Creature registeredCreature in registeredCreatures)
				{
					UpdateDrops(registeredCreature);
				}
			}

			internal static void UpdateDrops(Creature creature)
			{
				DropOption dropOption = creatureConfigs[creature].Drops.get();
				if (dropOption == DropOption.Default && creature.Drops.drops == null)
				{
					return;
				}
				CharacterDrop val = creature.Prefab.GetComponent<CharacterDrop>() ?? creature.Prefab.AddComponent<CharacterDrop>();
				DropOption dropOption2 = creatureConfigs[creature].Drops.get();
				if (1 == 0)
				{
				}
				List<KeyValuePair<string, Drop>> source = dropOption2 switch
				{
					DropOption.Custom => new SerializedDrops(creatureConfigs[creature].CustomDrops.get()).Drops, 
					DropOption.Disabled => new List<KeyValuePair<string, Drop>>(), 
					_ => creature.Drops.drops.ToList(), 
				};
				if (1 == 0)
				{
				}
				val.m_drops = (from d in ((IEnumerable<KeyValuePair<string, Drop>>)source).Select((Func<KeyValuePair<string, Drop>, Drop>)([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (KeyValuePair<string, Drop> kv) =>
					{
						//IL_0079: Unknown result type (might be due to invalid IL or missing references)
						//IL_007e: Unknown result type (might be due to invalid IL or missing references)
						//IL_0085: Unknown result type (might be due to invalid IL or missing references)
						//IL_009d: Unknown result type (might be due to invalid IL or missing references)
						//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
						//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
						//IL_00df: Unknown result type (might be due to invalid IL or missing references)
						//IL_00f2: Expected O, but got Unknown
						if (kv.Key == "" || ZNetScene.instance == null)
						{
							return null;
						}
						GameObject prefab = ZNetScene.instance.GetPrefab(kv.Key);
						if (prefab == null)
						{
							Debug.LogWarning((object)("Found invalid prefab name " + kv.Key + " for creature " + ((Object)creature.Prefab).name));
							return null;
						}
						return new Drop
						{
							m_prefab = prefab,
							m_amountMin = (int)kv.Value.Amount.min,
							m_amountMax = (int)kv.Value.Amount.max,
							m_chance = kv.Value.DropChance / 100f,
							m_onePerPlayer = kv.Value.DropOnePerPlayer,
							m_levelMultiplier = kv.Value.MultiplyDropByLevel
						};
					}))
					where d != null
					select d).ToList();
			}
		}

		[PublicAPI]
		[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)]
		public class Drop
		{
			public Range Amount = new Range(1f, 1f);

			public float DropChance = 100f;

			public bool DropOnePerPlayer = false;

			public bool MultiplyDropByLevel = true;
		}

		[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)]
		private class CustomConfig<[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)] T>
		{
			[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(1)]
			public Func<T> get = null;

			[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(new byte[] { 2, 1 })]
			public ConfigEntry<T> config = null;
		}

		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
		private class CreatureConfig
		{
			public readonly CustomConfig<SpawnOption> Spawn = new CustomConfig<SpawnOption>();

			public readonly CustomConfig<Toggle> CanBeTamed = new CustomConfig<Toggle>();

			public readonly CustomConfig<string> ConsumesItemName = new CustomConfig<string>();

			public readonly CustomConfig<SpawnTime> SpecificSpawnTime = new CustomConfig<SpawnTime>();

			public readonly CustomConfig<Range> RequiredAltitude = new CustomConfig<Range>();

			public readonly CustomConfig<Range> RequiredOceanDepth = new CustomConfig<Range>();

			public readonly CustomConfig<GlobalKey> RequiredGlobalKey = new CustomConfig<GlobalKey>();

			public readonly CustomConfig<Range> GroupSize = new CustomConfig<Range>();

			public readonly CustomConfig<Biome> Biome = new CustomConfig<Biome>();

			public readonly CustomConfig<SpawnArea> SpecificSpawnArea = new CustomConfig<SpawnArea>();

			public readonly CustomConfig<Weather> RequiredWeather = new CustomConfig<Weather>();

			public readonly CustomConfig<float> SpawnAltitude = new CustomConfig<float>();

			public readonly CustomConfig<Toggle> CanHaveStars = new CustomConfig<Toggle>();

			public readonly CustomConfig<Toggle> AttackImmediately = new CustomConfig<Toggle>();

			public readonly CustomConfig<int> CheckSpawnInterval = new CustomConfig<int>();

			public readonly CustomConfig<float> SpawnChance = new CustomConfig<float>();

			public readonly CustomConfig<Forest> ForestSpawn = new CustomConfig<Forest>();

			public readonly CustomConfig<int> Maximum = new CustomConfig<int>();

			public readonly CustomConfig<DropOption> Drops = new CustomConfig<DropOption>();

			public readonly CustomConfig<string> CustomDrops = new CustomConfig<string>();
		}

		[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)]
		private class ConfigurationManagerAttributes
		{
			[UsedImplicitly]
			public int? Order;

			[UsedImplicitly]
			public bool? Browsable;

			[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)]
			[UsedImplicitly]
			public string Category;

			[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(new byte[] { 2, 1 })]
			[UsedImplicitly]
			public Action<ConfigEntryBase> CustomDrawer;
		}

		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)]
		private class AcceptableEnumValues<[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(0)] T> : AcceptableValueBase where T : struct, IConvertible
		{
			[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(new byte[] { 1, 0 })]
			[PublicAPI]
			public virtual T[] AcceptableValues
			{
				[return: <ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(new byte[] { 1, 0 })]
				get;
			}

			public AcceptableEnumValues([<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(new byte[] { 1, 0 })] params T[] acceptableValues)
				: base(typeof(T))
			{
				AcceptableValues = acceptableValues;
			}

			public override object Clamp(object value)
			{
				return ((AcceptableValueBase)this).IsValid(value) ? value : ((object)AcceptableValues[0]);
			}

			public override bool IsValid(object value)
			{
				return AcceptableValues.Contains((T)value);
			}

			public override string ToDescriptionString()
			{
				return string.Join(", ", AcceptableValues);
			}
		}

		public bool ConfigurationEnabled = true;

		public readonly GameObject Prefab;

		public DropList Drops = new DropList();

		public bool CanSpawn = true;

		public bool CanBeTamed = false;

		[Description("List of items the creature consumes to get tame.\nFor multiple item names, separate them with a comma.")]
		public string FoodItems;

		[Description("Sets the time of day the creature can spawn.")]
		public SpawnTime SpecificSpawnTime = SpawnTime.Always;

		[Description("Sets the minimum and maximum altitude for the creature to spawn.")]
		public Range RequiredAltitude = new Range(5f, 1000f);

		[Description("Sets the minimum and maximum depth of the ocean for the creature to spawn.")]
		public Range RequiredOceanDepth = new Range(0f, 0f);

		[Description("Sets a global key required for the creature to spawn.")]
		public GlobalKey RequiredGlobalKey = GlobalKey.None;

		[Description("Sets a range for the group size the creature spawns in.")]
		public Range GroupSize = new Range(1f, 1f);

		[Description("Sets the biome the creature spawns in.")]
		public Biome Biome = (Biome)1;

		[Description("Sets spawning area for the creature inside the biome.\nUse SpawnArea.Edge, to make the creature spawn more towards the edge of the biome.\nUse SpawnArea.Center, to make the creature spawn more towards the center of the biome.")]
		public SpawnArea SpecificSpawnArea = SpawnArea.Everywhere;

		[Description("Sets the weather condition for the creature to spawn.\nUse the Weather enum for easy configuration.")]
		public Weather RequiredWeather = Weather.None;

		[Description("Sets altitude relative to the current ground level for the creature to spawn.\nShould be a higher number for flying creatures, so they spawn in the sky.")]
		public float SpawnAltitude = 0.5f;

		public bool CanHaveStars = true;

		[Description("Controls the first AI command right after spawn.\nSet to true for the creature to immediately start to hunt down the player.")]
		public bool AttackImmediately = false;

		[Description("The time between attempts to spawn the creature in.")]
		public int CheckSpawnInterval = 600;

		[Description("The chance in percent for the creature to spawn, every time Valheim checks if it should spawn.")]
		public float SpawnChance = 100f;

		[Description("Can be used to make the creature spawn in forests or prevent it from spawning in forests.\nUse the Forest enum for easy configuration.")]
		public Forest ForestSpawn = Forest.Both;

		[Description("Sets the maximum number of the creature that can be near the player, before Valheim disables its spawn.")]
		public int Maximum = 1;

		private static readonly List<Creature> registeredCreatures = new List<Creature>();

		private static Dictionary<Creature, CreatureConfig> creatureConfigs = new Dictionary<Creature, CreatureConfig>();

		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)]
		private static object configManager;

		private static List<SpawnData> lastRegisteredSpawns = new List<SpawnData>();

		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)]
		private static Localization _english;

		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)]
		private static BaseUnityPlugin _plugin;

		private static bool hasConfigSync = true;

		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)]
		private static object _configSync;

		private static Localization english
		{
			get
			{
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Expected O, but got Unknown
				if (_english == null)
				{
					_english = new Localization();
					_english.SetupLanguage("English");
				}
				return _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([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t)));
				}
				return _plugin;
			}
		}

		[<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)]
		private static object configSync
		{
			[<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(2)]
			get
			{
				if (_configSync == null && hasConfigSync)
				{
					Type type = Assembly.GetExecutingAssembly().GetType("ServerSync.ConfigSync");
					if ((object)type != null)
					{
						_configSync = Activator.CreateInstance(type, plugin.Info.Metadata.GUID + " CreatureManager");
						type.GetField("CurrentVersion").SetValue(_configSync, plugin.Info.Metadata.Version.ToString());
						type.GetProperty("IsLocked").SetValue(_configSync, true);
					}
					else
					{
						hasConfigSync = false;
					}
				}
				return _configSync;
			}
		}

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

		public Creature(AssetBundle bundle, string prefabName)
			: this(PrefabManager.RegisterPrefab(bundle, prefabName))
		{
		}

		public Creature(GameObject creature)
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			Prefab = creature;
			registeredCreatures.Add(this);
			CanBeTamed = Object.op_Implicit((Object)(object)creature.GetComponent<Tameable>());
			FoodItems = string.Join(",", (from i in creature.GetComponent<MonsterAI>()?.m_consumeItems
				where Object.op_Implicit((Object)(object)i.m_itemData.m_dropPrefab)
				select ((Object)i.m_itemData.m_dropPrefab).name) ?? Enumerable.Empty<string>());
		}

		public LocalizeKey Localize()
		{
			return new LocalizeKey(Prefab.GetComponent<Character>().m_name);
		}

		internal static void Patch_FejdStartup()
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Expected O, but got Unknown
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Expected O, but got Unknown
			//IL_06ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d8: Expected O, but got Unknown
			Type configManagerType = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (Assembly a) => a.GetName().Name == "ConfigurationManager")?.GetType("ConfigurationManager.ConfigurationManager");
			configManager = ((configManagerType == null) ? null : Chainloader.ManagerObject.GetComponent(configManagerType));
			if (!TomlTypeConverter.CanConvert(typeof(Range)))
			{
				TomlTypeConverter.AddConverter(typeof(Range), new TypeConverter
				{
					ConvertToObject = [<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (string s, Type _) =>
					{
						Match match = Regex.Match(s, "^(-?\\d+(?:\\.\\d*)?)\\s*-\\s*(-?\\d+(?:\\.\\d*)?)$");
						return match.Success ? new Range(float.Parse(match.Groups[1].Value), float.Parse(match.Groups[2].Value)) : default(Range);
					},
					ConvertToString = [<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (object obj, Type _) =>
					{
						Range range = (Range)obj;
						return $"{range.min} - {range.max}";
					}
				});
			}
			bool saveOnConfigSet = plugin.Config.SaveOnConfigSet;
			plugin.Config.SaveOnConfigSet = false;
			foreach (Creature registeredCreature in registeredCreatures)
			{
				Creature creature = registeredCreature;
				CreatureConfig creatureConfig2 = (creatureConfigs[creature] = new CreatureConfig());
				CreatureConfig cfg = creatureConfig2;
				string name2 = creature.Prefab.GetComponent<Character>().m_name;
				string englishName = new Regex("['[\"\\]]").Replace(english.Localize(name2), "").Trim();
				string localizedName = Localization.instance.Localize(name2).Trim();
				int order = 0;
				ConfigurationManagerAttributes tameConfigVisibility = new ConfigurationManagerAttributes();
				config<Toggle>(cfg.CanBeTamed, () => (!creature.CanBeTamed) ? Toggle.Off : Toggle.On, delegate
				{
					tameConfigVisibility.Browsable = cfg.CanBeTamed.get() == Toggle.On;
					reloadConfigDisplay();
					updateAI();
				}, "Can be tamed", "Decides, if the creature can be tamed.");
				tameConfigVisibility.Browsable = cfg.CanBeTamed.get() == Toggle.On;
				configWithDesc<string>(cfg.ConsumesItemName, [<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] () => creature.FoodItems, updateAI, "Food items", new ConfigDescription("The items the creature consumes to get tame.", (AcceptableValueBase)null, new object[1] { tameConfigVisibility }));
				ConfigurationManagerAttributes spawnConfigVisibility = new ConfigurationManagerAttributes();
				ConfigurationManagerAttributes dropConfigVisibility = new ConfigurationManagerAttributes();
				config<SpawnOption>(cfg.Spawn, () => creature.CanSpawn ? SpawnOption.Default : SpawnOption.Disabled, delegate
				{
					spawnConfigVisibility.Browsable = cfg.Spawn.get() == SpawnOption.Custom;
					reloadConfigDisplay();
					updateAllSpawnConfigs();
				}, "Spawn", "Configures the spawn for the creature.");
				spawnConfigVisibility.Browsable = cfg.Spawn.get() == SpawnOption.Custom;
				spawnConfig<SpawnTime>(cfg.SpecificSpawnTime, () => creature.SpecificSpawnTime, "Spawn time", "Configures the time of day for the creature to spawn.");
				spawnConfig<Range>(cfg.RequiredAltitude, () => creature.RequiredAltitude, "Required altitude", "Configures the altitude required for the creature to spawn.");
				spawnConfig<Range>(cfg.RequiredOceanDepth, () => creature.RequiredOceanDepth, "Required ocean depth", "Configures the ocean depth required for the creature to spawn.");
				spawnConfig<GlobalKey>(cfg.RequiredGlobalKey, () => creature.RequiredGlobalKey, "Required global key", "Configures the global key required for the creature to spawn.");
				spawnConfig<Range>(cfg.GroupSize, () => creature.GroupSize, "Group size", "Configures the size of the groups in which the creature spawns.");
				spawnConfig<Biome>(cfg.Biome, () => creature.Biome, "Biome", "Configures the biome required for the creature to spawn.");
				spawnConfig<SpawnArea>(cfg.SpecificSpawnArea, () => creature.SpecificSpawnArea, "Spawn area", "Configures if the creature spawns more towards the center or the edge of the biome.");
				spawnConfig<Weather>(cfg.RequiredWeather, () => creature.RequiredWeather, "Required weather", "Configures the weather required for the creature to spawn.");
				spawnConfig<float>(cfg.SpawnAltitude, () => creature.SpawnAltitude, "Spawn altitude", "Configures the height from the ground in which the creature will spawn.");
				spawnConfig<Toggle>(cfg.CanHaveStars, () => (!creature.CanHaveStars) ? Toggle.Off : Toggle.On, "Can have stars", "If the creature can have stars.");
				spawnConfig<Toggle>(cfg.AttackImmediately, () => (!creature.AttackImmediately) ? Toggle.Off : Toggle.On, "Hunt player", "Makes the creature immediately hunt down the player after it spawns.");
				spawnConfig<int>(cfg.CheckSpawnInterval, () => creature.CheckSpawnInterval, "Maximum spawn interval", "Configures the timespan that Valheim has to make the creature spawn.");
				spawnConfig<float>(cfg.SpawnChance, () => creature.SpawnChance, "Spawn chance", "Sets the chance for the creature to be spawned, every time Valheim checks the spawn.");
				spawnConfig<Forest>(cfg.ForestSpawn, () => creature.ForestSpawn, "Forest condition", "If the creature can spawn in forests or cannot spawn in forests. Or both.");
				spawnConfig<int>(cfg.Maximum, () => creature.Maximum, "Maximum creature count", "The maximum number of this creature near the player, before Valheim stops spawning it in. Setting this lower than the upper limit of the group size does not make sense.");
				config<DropOption>(cfg.Drops, () => DropOption.Default, delegate
				{
					dropConfigVisibility.Browsable = cfg.Drops.get() == DropOption.Custom;
					reloadConfigDisplay();
					DropList.UpdateDrops(creature);
				}, "Drops", "Configures the drops for the creature.");
				dropConfigVisibility.Browsable = cfg.Drops.get() == DropOption.Custom;
				configWithDesc<string>(cfg.CustomDrops, [<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] () => new DropList.SerializedDrops(creature.Drops, creature).ToString(), delegate
				{
					DropList.UpdateDrops(creature);
				}, "Drop config", new ConfigDescription("", (AcceptableValueBase)null, new object[1] { dropConfigVisibility }));
				void config<T>([<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(new byte[] { 1, 0 })] CustomConfig<T> customConfig, [<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(new byte[] { 1, 0 })] Func<T> getter, Action configChanged, string name, string desc)
				{
					//IL_000e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0018: Expected O, but got Unknown
					configWithDesc<T>(customConfig, getter, configChanged, name, new ConfigDescription(desc, (AcceptableValueBase)null, Array.Empty<object>()));
				}
				void configWithDesc<T>([<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(new byte[] { 1, 0 })] CustomConfig<T> customConfig, [<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(new byte[] { 1, 0 })] Func<T> getter, Action configChanged, string name, ConfigDescription desc)
				{
					//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
					//IL_00f3: Expected O, but got Unknown
					if (creature.ConfigurationEnabled)
					{
						customConfig.config = pluginConfig(englishName, name, getter(), new ConfigDescription(desc.Description, desc.AcceptableValues, desc.Tags.Concat(new ConfigurationManagerAttributes[1]
						{
							new ConfigurationManagerAttributes
							{
								Order = (order -= 1),
								CustomDrawer = ((customConfig == cfg.CustomDrops) ? new Action<ConfigEntryBase>(drawConfigTable) : ((typeof(T) == typeof(Range)) ? new Action<ConfigEntryBase>(drawRange) : null)),
								Category = localizedName
							}
						}).ToArray()));
						customConfig.config.SettingChanged += [<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (object _, EventArgs _) =>
						{
							configChanged();
						};
						customConfig.get = [<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] () => customConfig.config.Value;
					}
					else
					{
						customConfig.get = getter;
					}
				}
				void spawnConfig<T>([<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(new byte[] { 1, 0 })] CustomConfig<T> customConfig, [<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(new byte[] { 1, 0 })] Func<T> getter, string name, string desc, [<ad5c2e39-9f49-4bca-be00-35998cd25028>Nullable(2)] AcceptableValueBase acceptableValues = null)
				{
					//IL_0028: Unknown result type (might be due to invalid IL or missing references)
					//IL_0032: Expected O, but got Unknown
					configWithDesc<T>(customConfig, getter, updateAllSpawnConfigs, name, new ConfigDescription(desc, acceptableValues, new object[1] { spawnConfigVisibility }));
				}
				void updateAI()
				{
					if (Object.op_Implicit((Object)(object)ObjectDB.instance))
					{
						BaseAI[] array2 = Object.FindObjectsOfType<BaseAI>();
						foreach (BaseAI ai in array2)
						{
							creature.updateAi(ai);
						}
						creature.updateAi(creature.Prefab.GetComponent<BaseAI>());
					}
				}
				void updateAllSpawnConfigs()
				{
					SpawnSystem[] array = Object.FindObjectsOfType<SpawnSystem>();
					foreach (SpawnSystem val in array)
					{
						foreach (SpawnSystemList spawnList in val.m_spawnLists)
						{
							foreach (SpawnData spawner in spawnList.m_spawners)
							{
								if ((Object)(object)creature.Prefab == (Object)(object)spawner.m_prefab)
								{
									creature.updateSpawnData(spawner);
								}
							}
						}
					}
				}
			}
			if (saveOnConfigSet)
			{
				plugin.Config.SaveOnConfigSet = true;
				plugin.Config.Save();
			}
			void reloadConfigDisplay()
			{
				configManagerType?.GetMethod("BuildSettingList").Invoke(configManager, Array.Empty<object>());
			}
		}

		private static void drawRange(ConfigEntryBase cfg)
		{
			//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_00c5: Expected O, but got Unknown
			bool valueOrDefault = cfg.Description.Tags.Select([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (object a) => (a.GetType().Name == "ConfigurationManagerAttributes") ? ((bool?)a.GetType().GetField("ReadOnly")?.GetValue(a)) : null).FirstOrDefault((bool? v) => v.HasValue).GetValueOrDefault();
			ConfigEntry<Range> val = (ConfigEntry<Range>)(object)cfg;
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			float.TryParse(GUILayout.TextField(val.Value.min.ToString(CultureInfo.InvariantCulture), Array.Empty<GUILayoutOption>()), out var result);
			GUILayout.Label(" - ", new GUIStyle(GUI.skin.label)
			{
				fixedWidth = 14f
			}, Array.Empty<GUILayoutOption>());
			float.TryParse(GUILayout.TextField(val.Value.max.ToString(CultureInfo.InvariantCulture), Array.Empty<GUILayoutOption>()), out var result2);
			GUILayout.EndHorizontal();
			if (!valueOrDefault && (Math.Abs(val.Value.min - result) > 1E-05f || Math.Abs(val.Value.max - result2) > 1E-05f))
			{
				val.Value = new Range(result, result2);
			}
		}

		private static void drawConfigTable(ConfigEntryBase cfg)
		{
			//IL_0117: 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_0132: Expected O, but got Unknown
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Expected O, but got Unknown
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Expected O, but got Unknown
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Expected O, but got Unknown
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Expected O, but got Unknown
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Expected O, but got Unknown
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Expected O, but got Unknown
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: Expected O, but got Unknown
			//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Expected O, but got Unknown
			//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Unknown result type (might be due to invalid IL or missing references)
			//IL_0415: Unknown result type (might be due to invalid IL or missing references)
			//IL_0485: Unknown result type (might be due to invalid IL or missing references)
			//IL_048a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Expected O, but got Unknown
			bool valueOrDefault = cfg.Description.Tags.Select([<55a4ca74-ec33-47f5-a537-d0fa0131e6ad>NullableContext(0)] (object a) => (a.GetType().Name == "ConfigurationManagerAttributes") ? ((bool?)a.GetType().GetField("ReadOnly")?.GetValue(a)) : null).FirstOrDefault((bool? v) => v.HasValue).GetValueOrDefault();
			List<KeyValuePair<string, Drop>> list = new List<KeyValuePair<string, Drop>>();
			bool flag = false;
			int num = (int)(configManager?.GetType().GetProperty("RightColumnWidth", BindingFlags.Instance | BindingFlags.NonPublic).GetGetMethod(nonPublic: true)
				.Invoke(configManager, Array.Empty<object>()) ?? ((object)130));
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			foreach (KeyValuePair<string, Drop> drop in new DropList.SerializedDrops((string)cfg.BoxedValue).Drops)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				int num2 = Mathf.RoundToInt(drop.Value.Amount.min);
				if (int.TryParse(GUILayout.TextField(num2.ToString(), new GUIStyle(GUI.skin.textField)
				{
					fixedWidth = 35f
				}, Array.Empty<GUILayoutOption>()), out var result) && result != num2 && !valueOrDefault)
				{
					num2 = result;
					flag = true;
				}
				GUILayout.Label(" - ", new GUIStyle(GUI.skin.label)
				{
					fixedWidth = 14f
				}, Array.Empty<GUILayoutOption>());
				int num3 = Mathf.RoundToInt(drop.Value.Amount.max);
				if (int.TryParse(GUILayout.TextField(num3.ToString(), new GUIStyle(GUI.skin.textField)
				{
					fixedWidth = 35f
				}, Array.Empty<GUILayoutOption>()), out var result2) && result2 != num3 && !valueOrDefault)
				{
					num3 = result2;
					flag = true;
				}
				GUILayout.Label(" ", new GUIStyle(GUI.skin.label)
				{
					fixedWidth = 10f
				}, Array.Empty<GUILayoutOption>());
				string text = GUILayout.TextField(drop.Key, new GUIStyle(GUI.skin.textField)
				{
					fixedWidth = num - 35 - 14 - 35 - 10 - 21 - 18
				}, Array.Empty<GUILayoutOption>());
				string text2 = (valueOrDefault ? drop.Key : text);
				flag = flag || text2 != drop.Key;
				bool flag2 = GUILayout.Button("x", new GUIStyle(GUI.skin.button)
				{
					fixedWidth = 21f
				}, Array.Empty<GUILayoutOption>()) && !valueOrDefault;
				GUILayout.EndHorizontal();
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				float num4 = drop.Value.DropChance;
				if (float.TryParse(GUILayout.TextField(num4.ToString(CultureInfo.InvariantCulture), new GUIStyle(GUI.skin.textField)
				{
					fixedWidth = 45f
				}, Array.Empty<GUILayoutOption>()), out var result3) && Math.Abs(result3 - num4) > 1E-05f && !valueOrDefault)
				{
					num4 = result3;
					flag = true;
				}
				GUILayout.Label("% ", Array.Empty<GUILayoutOption>());
				string tooltip = GUI.tooltip;
				bool flag3 = drop.Value.MultiplyDropByLevel;
				bool flag4 = GUILayout.Toggle(flag3, new GUIContent(flag3 ? "per level" : "fixed", "Loot is multiplied by the creature's level."), Array.Empty<GUILayoutOption>());
				if (flag4 != flag3 && !valueOrDefault)
				{
					flag3 = flag4;
					flag = true;
				}
				bool flag5 = drop.Value.DropOnePerPlayer;
				bool flag6 = GUILayout.Toggle(flag5, new GUIContent(flag5 ? "per player" : "independent", "Drops one per player."), Array.Empty<GUILayoutOption>());
				if (flag6 != flag5 && !valueOrDefault