Decompiled source of BiomeLock v1.1.1

plugins/BiomeLock.dll

Decompiled 4 days 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.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using LocalizationManager;
using Microsoft.CodeAnalysis;
using ServerSync;
using TMPro;
using UnityEngine;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Core.ObjectPool;
using YamlDotNet.Core.Tokens;
using YamlDotNet.Helpers;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.BufferedDeserialization;
using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators;
using YamlDotNet.Serialization.Callbacks;
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: Guid("E74EB49A-461D-48EA-85BC-F462D60C98C4")]
[assembly: ComVisible(false)]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyProduct("BiomeLock")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyTitle("BiomeLock")]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyFileVersion("1.1.1")]
[assembly: AssemblyCompany("Radamanto")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
[module: <e74ed34b-eec2-454d-8b38-cdd76ed0123f>RefSafetyRules(11)]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[<35a3a4e4-495a-45f0-9c21-36092d9a9194>Embedded]
	internal sealed class <35a3a4e4-495a-45f0-9c21-36092d9a9194>EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[<35a3a4e4-495a-45f0-9c21-36092d9a9194>Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	[CompilerGenerated]
	internal sealed class <772b41c4-974b-4eba-9a88-345304c073ea>NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public <772b41c4-974b-4eba-9a88-345304c073ea>NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public <772b41c4-974b-4eba-9a88-345304c073ea>NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[<35a3a4e4-495a-45f0-9c21-36092d9a9194>Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class <01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public <01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	[<35a3a4e4-495a-45f0-9c21-36092d9a9194>Embedded]
	internal sealed class <e74ed34b-eec2-454d-8b38-cdd76ed0123f>RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public <e74ed34b-eec2-454d-8b38-cdd76ed0123f>RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LocalizationManager
{
	[PublicAPI]
	[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
	[<01abcb44-c760-4aa0-b992-dd354ce3dc11>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;

		[<772b41c4-974b-4eba-9a88-345304c073ea>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([<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)] (TypeInfo t) => t.IsClass && typeof(BaseUnityPlugin).IsAssignableFrom(t)));
				}
				return _plugin;
			}
		}

		[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(2)]
		[method: <01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(2)]
		[field: <772b41c4-974b-4eba-9a88-345304c073ea>Nullable(2)]
		public static event Action OnLocalizationComplete;

		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, [<01abcb44-c760-4aa0-b992-dd354ce3dc11>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, [<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(new byte[] { 2, 1, 1 })] Func<T, string> convertConfigValue = null)
		{
			if (convertConfigValue == null)
			{
				convertConfigValue = (T val) => val.ToString();
			}
			if (!PlaceholderProcessors.ContainsKey(key))
			{
				PlaceholderProcessors[key] = new Dictionary<string, Func<string>>();
			}
			config.SettingChanged += [<01abcb44-c760-4aa0-b992-dd354ce3dc11>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()
		{
			_ = plugin;
		}

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

		public static void SafeCallLocalizeComplete()
		{
			Localizer.OnLocalizationComplete?.Invoke();
		}

		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[] array = Path.GetFileNameWithoutExtension(item).Split(new char[1] { '.' });
				if (array.Length >= 2)
				{
					string text = array[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[] array2 = LoadTranslationFromAssembly("English");
			if (array2 == 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.");
			}
			string input = Encoding.UTF8.GetString(array2).TrimStart(new char[1] { '\ufeff' });
			Dictionary<string, string> dictionary2 = new DeserializerBuilder().IgnoreFields().Build().Deserialize<Dictionary<string, string>>(input);
			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.TryGetValue(language, out var value))
				{
					text2 = File.ReadAllText(value);
				}
				else
				{
					byte[] array3 = LoadTranslationFromAssembly(language);
					if (array3 != null)
					{
						text2 = Encoding.UTF8.GetString(array3);
					}
				}
			}
			if (text2 == null && dictionary.TryGetValue("English", out var value2))
			{
				text2 = File.ReadAllText(value2);
			}
			if (text2 != null)
			{
				text2 = text2.TrimStart(new char[1] { '\ufeff' });
				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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: 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>(2) { ".json", ".yml" };
			Harmony val = new Harmony("org.bepinex.helpers.LocalizationManager");
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(Localization), "SetupLanguage", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "LoadLocalization", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(FejdStartup), "SetupGui", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "LoadLocalizationLater", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)AccessTools.DeclaredMethod(typeof(FejdStartup), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.DeclaredMethod(typeof(Localizer), "SafeCallLocalizeComplete", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		[return: <772b41c4-974b-4eba-9a88-345304c073ea>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;
		}

		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(2)]
		public static byte[] ReadEmbeddedFileBytes([<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(1)] string resourceFileName, Assembly containingAssembly = null)
		{
			using MemoryStream memoryStream = new MemoryStream();
			if ((object)containingAssembly == null)
			{
				containingAssembly = Assembly.GetCallingAssembly();
			}
			string text = containingAssembly.GetManifestResourceNames().FirstOrDefault([<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)] (string str) => str.EndsWith(resourceFileName, StringComparison.Ordinal));
			if (text != null)
			{
				containingAssembly.GetManifestResourceStream(text)?.CopyTo(memoryStream);
			}
			return (memoryStream.Length == 0L) ? null : memoryStream.ToArray();
		}
	}
	public static class LocalizationManagerVersion
	{
		[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(1)]
		public const string Version = "1.4.1";
	}
}
namespace BiomeLock
{
	[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
	[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
	public static class BiomeLockAPI
	{
		public const string PrivatePrefix = "bl_";

		private static bool _resolved;

		[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(2)]
		private static Type _tKeys;

		[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(2)]
		private static FieldInfo _fiPrivateKeys;

		[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(2)]
		private static MethodInfo _miNormalizeKey;

		[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(new byte[] { 2, 1 })]
		[method: <772b41c4-974b-4eba-9a88-345304c073ea>Nullable(new byte[] { 2, 1 })]
		[field: <772b41c4-974b-4eba-9a88-345304c073ea>Nullable(new byte[] { 2, 1 })]
		public static event Action<string> OnPrivateKeyAdded;

		[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(new byte[] { 2, 1 })]
		[method: <772b41c4-974b-4eba-9a88-345304c073ea>Nullable(new byte[] { 2, 1 })]
		[field: <772b41c4-974b-4eba-9a88-345304c073ea>Nullable(new byte[] { 2, 1 })]
		public static event Action<string> OnPrivateKeyRemoved;

		[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(2)]
		[method: <01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(2)]
		[field: <772b41c4-974b-4eba-9a88-345304c073ea>Nullable(2)]
		public static event Action OnPrivateKeysReset;

		public static bool HasPrivateKey(string globalOrPrivateKey)
		{
			if (!IsAvailable())
			{
				return false;
			}
			string text = ToPrivateKey(globalOrPrivateKey);
			if (text.Length == 0)
			{
				return false;
			}
			HashSet<string> hashSet = TryGetPrivateKeysRef();
			if (hashSet == null)
			{
				return false;
			}
			lock (hashSet)
			{
				return hashSet.Contains(text);
			}
		}

		internal static void RaisePrivateKeyAdded(string privateKey)
		{
			try
			{
				privateKey = ToPrivateKey(privateKey);
				if (privateKey.Length != 0)
				{
					BiomeLockAPI.OnPrivateKeyAdded?.Invoke(privateKey);
				}
			}
			catch
			{
			}
		}

		internal static void RaisePrivateKeyRemoved(string privateKey)
		{
			try
			{
				privateKey = ToPrivateKey(privateKey);
				if (privateKey.Length != 0)
				{
					BiomeLockAPI.OnPrivateKeyRemoved?.Invoke(privateKey);
				}
			}
			catch
			{
			}
		}

		internal static void RaisePrivateKeysReset()
		{
			try
			{
				BiomeLockAPI.OnPrivateKeysReset?.Invoke();
			}
			catch
			{
			}
		}

		private static bool IsAvailable()
		{
			try
			{
				return (Object)(object)ZNetScene.instance != (Object)null && (Object)(object)Player.m_localPlayer != (Object)null;
			}
			catch
			{
				return false;
			}
		}

		private static string NormalizeKey(string key)
		{
			if (key == null)
			{
				return string.Empty;
			}
			ResolveOnce();
			try
			{
				if (_miNormalizeKey != null)
				{
					return (string)_miNormalizeKey.Invoke(null, new object[1] { key });
				}
			}
			catch
			{
			}
			return key.Trim().ToLowerInvariant();
		}

		private static string ToPrivateKey(string globalOrPrivateKey)
		{
			string text = NormalizeKey(globalOrPrivateKey);
			if (text.Length == 0)
			{
				return string.Empty;
			}
			if (text.StartsWith("bl_", StringComparison.Ordinal))
			{
				return text;
			}
			return "bl_" + text;
		}

		[return: <772b41c4-974b-4eba-9a88-345304c073ea>Nullable(new byte[] { 2, 1 })]
		private static HashSet<string> TryGetPrivateKeysRef()
		{
			ResolveOnce();
			if (_fiPrivateKeys == null)
			{
				return null;
			}
			try
			{
				return _fiPrivateKeys.GetValue(null) as HashSet<string>;
			}
			catch
			{
				return null;
			}
		}

		private static void ResolveOnce()
		{
			if (_resolved)
			{
				return;
			}
			_resolved = true;
			_tKeys = Type.GetType("BiomeLock.BiomeLockPrivateKeys, " + typeof(BiomeLockPlugin).Assembly.GetName().Name, throwOnError: false);
			if (_tKeys == null)
			{
				_tKeys = typeof(BiomeLockPlugin).Assembly.GetType("BiomeLock.BiomeLockPrivateKeys", throwOnError: false);
			}
			if (!(_tKeys == null))
			{
				_fiPrivateKeys = _tKeys.GetField("PrivateKeys", BindingFlags.Static | BindingFlags.NonPublic);
				if (_fiPrivateKeys == null)
				{
					_fiPrivateKeys = _tKeys.GetField("PrivateKeys", BindingFlags.Static | BindingFlags.Public);
				}
				_miNormalizeKey = _tKeys.GetMethod("NormalizeKey", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[1] { typeof(string) }, null) ?? _tKeys.GetMethod("NormalizeKey", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(string) }, null);
			}
		}
	}
	[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
	[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
	internal static class AssetLoader
	{
		private const string ResourceName = "BiomeLock.assets.rd_biome";

		private static AssetBundle _bundle;

		internal static void LoadBundle()
		{
			if ((Object)(object)_bundle != (Object)null)
			{
				return;
			}
			try
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				using Stream stream = executingAssembly.GetManifestResourceStream("BiomeLock.assets.rd_biome");
				if (stream != null)
				{
					byte[] array = new byte[stream.Length];
					stream.Read(array, 0, array.Length);
					_bundle = AssetBundle.LoadFromMemory(array);
				}
			}
			catch
			{
			}
		}

		internal static Sprite GetSprite(string name)
		{
			LoadBundle();
			if ((Object)(object)_bundle == (Object)null)
			{
				return null;
			}
			try
			{
				return _bundle.LoadAsset<Sprite>(name);
			}
			catch
			{
				return null;
			}
		}
	}
	[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
	[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
	[HarmonyPatch(typeof(Terminal), "InitTerminal")]
	internal static class BL_Commands
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
			public static readonly <>c <>9 = new <>c();

			[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
			public static ConsoleEvent <>9__1_0;

			[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
			public static ConsoleEvent <>9__1_1;

			[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
			public static ConsoleEvent <>9__1_2;

			[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
			public static ConsoleEvent <>9__1_3;

			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
			internal void <Postfix>b__1_0(ConsoleEventArgs args)
			{
				if (!RequireAdmin(args))
				{
					return;
				}
				if (args.Length < 2)
				{
					args.Context.AddString("Syntax: bl_setkey bl_<key> [optional: player name]");
					return;
				}
				if (!TryGetPrivateKeyArg(args[1], out var privateKey, out var error))
				{
					args.Context.AddString(error);
					return;
				}
				long uid = 0L;
				string text = "";
				bool flag = true;
				if (args.Length >= 3)
				{
					string text2 = JoinName(args, 2).Trim();
					text = text2;
					flag = IsLocalPlayerName(text2);
					if (!flag && !BiomeLockPrivateKeys.TryResolveUidByPlayerName(text2, out uid))
					{
						args.Context.AddString("Player not found: " + text2);
						return;
					}
				}
				if (ZRoutedRpc.instance == null)
				{
					args.Context.AddString("ZRoutedRpc not ready.");
					return;
				}
				if (uid == 0)
				{
					uid = ZNet.GetUID();
				}
				ZRoutedRpc.instance.InvokeRoutedRPC(uid, "BL_SetPrivateKey", new object[1] { privateKey });
				args.Context.AddString(flag ? ("Key added to you: " + privateKey) : ("Key added to player: " + text + " -> " + privateKey));
			}

			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
			internal void <Postfix>b__1_1(ConsoleEventArgs args)
			{
				if (!RequireAdmin(args))
				{
					return;
				}
				if (args.Length < 2)
				{
					args.Context.AddString("Syntax: bl_removekey bl_<key> [optional: player name]");
					return;
				}
				if (!TryGetPrivateKeyArg(args[1], out var privateKey, out var error))
				{
					args.Context.AddString(error);
					return;
				}
				long uid = 0L;
				string text = "";
				bool flag = true;
				if (args.Length >= 3)
				{
					string text2 = JoinName(args, 2).Trim();
					text = text2;
					flag = IsLocalPlayerName(text2);
					if (!flag && !BiomeLockPrivateKeys.TryResolveUidByPlayerName(text2, out uid))
					{
						args.Context.AddString("Player not found: " + text2);
						return;
					}
				}
				if (ZRoutedRpc.instance == null)
				{
					args.Context.AddString("ZRoutedRpc not ready.");
					return;
				}
				if (uid == 0)
				{
					uid = ZNet.GetUID();
				}
				ZRoutedRpc.instance.InvokeRoutedRPC(uid, "BL_RemovePrivateKey", new object[1] { privateKey });
				args.Context.AddString(flag ? ("Key removed from you: " + privateKey) : ("Key removed from player: " + text + " -> " + privateKey));
			}

			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
			internal void <Postfix>b__1_2(ConsoleEventArgs args)
			{
				if (!RequireAdmin(args))
				{
					return;
				}
				long uid = 0L;
				string text = "";
				bool flag = true;
				if (args.Length >= 2)
				{
					string text2 = JoinName(args, 1).Trim();
					text = text2;
					flag = IsLocalPlayerName(text2);
					if (!flag && !BiomeLockPrivateKeys.TryResolveUidByPlayerName(text2, out uid))
					{
						args.Context.AddString("Player not found: " + text2);
						return;
					}
				}
				if (ZRoutedRpc.instance == null)
				{
					args.Context.AddString("ZRoutedRpc not ready.");
					return;
				}
				if (uid == 0)
				{
					uid = ZNet.GetUID();
				}
				ZRoutedRpc.instance.InvokeRoutedRPC(uid, "BL_ResetPrivateKeys", Array.Empty<object>());
				args.Context.AddString(flag ? "Keys reset for you." : ("Keys reset for player: " + text + "."));
			}

			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
			internal void <Postfix>b__1_3(ConsoleEventArgs args)
			{
				if (!RequireAdmin(args))
				{
					return;
				}
				if (args.Length == 1)
				{
					args.Context.AddString("Listing local keys:");
					args.Context.AddString("Total Keys: " + BiomeLockPrivateKeys.PrivateKeys.Count);
					{
						foreach (string privateKey in BiomeLockPrivateKeys.PrivateKeys)
						{
							args.Context.AddString(privateKey);
						}
						return;
					}
				}
				string text = JoinName(args, 1).Trim();
				if (IsLocalPlayerName(text))
				{
					args.Context.AddString("Listing local keys:");
					args.Context.AddString("Total Keys: " + BiomeLockPrivateKeys.PrivateKeys.Count);
					{
						foreach (string privateKey2 in BiomeLockPrivateKeys.PrivateKeys)
						{
							args.Context.AddString(privateKey2);
						}
						return;
					}
				}
				if (!BiomeLockPrivateKeys.TryResolveUidByPlayerName(text, out var uid))
				{
					args.Context.AddString("Player not found: " + text);
					return;
				}
				if (ZRoutedRpc.instance == null)
				{
					args.Context.AddString("ZRoutedRpc not ready.");
					return;
				}
				ZRoutedRpc.instance.InvokeRoutedRPC("BL_ServerListKeys", new object[1] { uid });
			}
		}

		[HarmonyPriority(800)]
		private static void Prefix(out bool __state)
		{
			__state = Terminal.m_terminalInitialized;
		}

		private static void Postfix(bool __state)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			if (__state)
			{
				return;
			}
			object obj = <>c.<>9__1_0;
			if (obj == null)
			{
				ConsoleEvent val = [<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)] (ConsoleEventArgs args) =>
				{
					if (RequireAdmin(args))
					{
						string privateKey2;
						string error2;
						if (args.Length < 2)
						{
							args.Context.AddString("Syntax: bl_setkey bl_<key> [optional: player name]");
						}
						else if (!TryGetPrivateKeyArg(args[1], out privateKey2, out error2))
						{
							args.Context.AddString(error2);
						}
						else
						{
							long uid4 = 0L;
							string text6 = "";
							bool flag3 = true;
							if (args.Length >= 3)
							{
								string text7 = JoinName(args, 2).Trim();
								text6 = text7;
								flag3 = IsLocalPlayerName(text7);
								if (!flag3 && !BiomeLockPrivateKeys.TryResolveUidByPlayerName(text7, out uid4))
								{
									args.Context.AddString("Player not found: " + text7);
									return;
								}
							}
							if (ZRoutedRpc.instance == null)
							{
								args.Context.AddString("ZRoutedRpc not ready.");
							}
							else
							{
								if (uid4 == 0)
								{
									uid4 = ZNet.GetUID();
								}
								ZRoutedRpc.instance.InvokeRoutedRPC(uid4, "BL_SetPrivateKey", new object[1] { privateKey2 });
								args.Context.AddString(flag3 ? ("Key added to you: " + privateKey2) : ("Key added to player: " + text6 + " -> " + privateKey2));
							}
						}
					}
				};
				<>c.<>9__1_0 = val;
				obj = (object)val;
			}
			new ConsoleCommand("bl_setkey", "[bl_key] [optional: player name]", (ConsoleEvent)obj, true, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			object obj2 = <>c.<>9__1_1;
			if (obj2 == null)
			{
				ConsoleEvent val2 = [<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)] (ConsoleEventArgs args) =>
				{
					if (RequireAdmin(args))
					{
						string privateKey;
						string error;
						if (args.Length < 2)
						{
							args.Context.AddString("Syntax: bl_removekey bl_<key> [optional: player name]");
						}
						else if (!TryGetPrivateKeyArg(args[1], out privateKey, out error))
						{
							args.Context.AddString(error);
						}
						else
						{
							long uid3 = 0L;
							string text4 = "";
							bool flag2 = true;
							if (args.Length >= 3)
							{
								string text5 = JoinName(args, 2).Trim();
								text4 = text5;
								flag2 = IsLocalPlayerName(text5);
								if (!flag2 && !BiomeLockPrivateKeys.TryResolveUidByPlayerName(text5, out uid3))
								{
									args.Context.AddString("Player not found: " + text5);
									return;
								}
							}
							if (ZRoutedRpc.instance == null)
							{
								args.Context.AddString("ZRoutedRpc not ready.");
							}
							else
							{
								if (uid3 == 0)
								{
									uid3 = ZNet.GetUID();
								}
								ZRoutedRpc.instance.InvokeRoutedRPC(uid3, "BL_RemovePrivateKey", new object[1] { privateKey });
								args.Context.AddString(flag2 ? ("Key removed from you: " + privateKey) : ("Key removed from player: " + text4 + " -> " + privateKey));
							}
						}
					}
				};
				<>c.<>9__1_1 = val2;
				obj2 = (object)val2;
			}
			new ConsoleCommand("bl_removekey", "[bl_key] [optional: player name]", (ConsoleEvent)obj2, true, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			object obj3 = <>c.<>9__1_2;
			if (obj3 == null)
			{
				ConsoleEvent val3 = [<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)] (ConsoleEventArgs args) =>
				{
					if (RequireAdmin(args))
					{
						long uid2 = 0L;
						string text2 = "";
						bool flag = true;
						if (args.Length >= 2)
						{
							string text3 = JoinName(args, 1).Trim();
							text2 = text3;
							flag = IsLocalPlayerName(text3);
							if (!flag && !BiomeLockPrivateKeys.TryResolveUidByPlayerName(text3, out uid2))
							{
								args.Context.AddString("Player not found: " + text3);
								return;
							}
						}
						if (ZRoutedRpc.instance == null)
						{
							args.Context.AddString("ZRoutedRpc not ready.");
						}
						else
						{
							if (uid2 == 0)
							{
								uid2 = ZNet.GetUID();
							}
							ZRoutedRpc.instance.InvokeRoutedRPC(uid2, "BL_ResetPrivateKeys", Array.Empty<object>());
							args.Context.AddString(flag ? "Keys reset for you." : ("Keys reset for player: " + text2 + "."));
						}
					}
				};
				<>c.<>9__1_2 = val3;
				obj3 = (object)val3;
			}
			new ConsoleCommand("bl_resetkeys", "[optional: player name]", (ConsoleEvent)obj3, true, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
			object obj4 = <>c.<>9__1_3;
			if (obj4 == null)
			{
				ConsoleEvent val4 = [<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)] (ConsoleEventArgs args) =>
				{
					if (RequireAdmin(args))
					{
						if (args.Length == 1)
						{
							args.Context.AddString("Listing local keys:");
							args.Context.AddString("Total Keys: " + BiomeLockPrivateKeys.PrivateKeys.Count);
							{
								foreach (string privateKey3 in BiomeLockPrivateKeys.PrivateKeys)
								{
									args.Context.AddString(privateKey3);
								}
								return;
							}
						}
						string text = JoinName(args, 1).Trim();
						if (IsLocalPlayerName(text))
						{
							args.Context.AddString("Listing local keys:");
							args.Context.AddString("Total Keys: " + BiomeLockPrivateKeys.PrivateKeys.Count);
							{
								foreach (string privateKey4 in BiomeLockPrivateKeys.PrivateKeys)
								{
									args.Context.AddString(privateKey4);
								}
								return;
							}
						}
						if (!BiomeLockPrivateKeys.TryResolveUidByPlayerName(text, out var uid))
						{
							args.Context.AddString("Player not found: " + text);
						}
						else if (ZRoutedRpc.instance == null)
						{
							args.Context.AddString("ZRoutedRpc not ready.");
						}
						else
						{
							ZRoutedRpc.instance.InvokeRoutedRPC("BL_ServerListKeys", new object[1] { uid });
						}
					}
				};
				<>c.<>9__1_3 = val4;
				obj4 = (object)val4;
			}
			new ConsoleCommand("bl_listkeys", "[optional: player name]", (ConsoleEvent)obj4, true, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false);
		}

		private static bool IsLocalPlayerName(string name)
		{
			try
			{
				if ((Object)(object)Player.m_localPlayer == (Object)null)
				{
					return false;
				}
				string playerName = Player.m_localPlayer.GetPlayerName();
				if (string.IsNullOrEmpty(playerName))
				{
					return false;
				}
				return string.Equals(playerName, name, StringComparison.OrdinalIgnoreCase);
			}
			catch
			{
				return false;
			}
		}

		private static bool RequireAdmin(ConsoleEventArgs args)
		{
			bool flag = false;
			try
			{
				flag = BiomeLockPlugin.IsLocalPlayerAdmin();
			}
			catch
			{
			}
			if (!flag)
			{
				flag = IsVanillaAdmin();
			}
			if (!flag)
			{
				args.Context.AddString("Admin only.");
			}
			return flag;
		}

		private static bool IsVanillaAdmin()
		{
			try
			{
				if ((Object)(object)ZNet.instance == (Object)null)
				{
					return false;
				}
				if ((Object)(object)Player.m_localPlayer != (Object)null)
				{
					return ZNet.instance.IsAdmin(Player.m_localPlayer.GetPlayerName());
				}
				return false;
			}
			catch
			{
				return false;
			}
		}

		private static string JoinName(ConsoleEventArgs args, int startIndex)
		{
			string text = args[startIndex];
			for (int i = startIndex + 1; i < args.Length; i++)
			{
				text = text + " " + args[i];
			}
			return text;
		}

		private static bool TryGetPrivateKeyArg(string arg, out string privateKey, out string error)
		{
			privateKey = "";
			error = "";
			string text = BiomeLockPrivateKeys.NormalizeKey(arg);
			if (!text.StartsWith("bl_", StringComparison.Ordinal))
			{
				error = "Key must include prefix. Example: bl_defeated_eikthyr";
				return false;
			}
			string text2 = text.Substring("bl_".Length);
			if (string.IsNullOrEmpty(text2))
			{
				error = "Invalid key.";
				return false;
			}
			if (!BiomeLockPrivateKeys.IsBossGlobalKey(text2))
			{
				error = "Invalid key: " + text;
				return false;
			}
			privateKey = text;
			return true;
		}
	}
	[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
	[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
	[BepInPlugin("radamanto.BiomeLock", "BiomeLock", "1.1.1")]
	public class BiomeLockPlugin : BaseUnityPlugin
	{
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		private class ConfigurationManagerAttributes
		{
			public bool? Browsable = false;
		}

		[CompilerGenerated]
		private sealed class <ReloadConfigAfterQuietPeriod>d__58 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
			private object <>2__current;

			public float quietSeconds;

			[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
			public BiomeLockPlugin <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				[return: <772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				[return: <772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <ReloadConfigAfterQuietPeriod>d__58(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if ((DateTime.UtcNow - <>4__this._lastCfgWriteUtc).TotalSeconds < (double)quietSeconds)
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				try
				{
					if (<>4__this._configWatcher == null || !<>4__this._watcherReady)
					{
						return false;
					}
					<>4__this._configWatcher.EnableRaisingEvents = false;
					if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer())
					{
						((BaseUnityPlugin)<>4__this).Config.Reload();
						<>4__this._ignoreEventsUntilUtc = DateTime.UtcNow.AddSeconds(1.0);
						((BaseUnityPlugin)<>4__this).Config.Save();
					}
				}
				catch
				{
				}
				finally
				{
					if (<>4__this._configWatcher != null)
					{
						<>4__this._configWatcher.EnableRaisingEvents = true;
					}
					<>4__this._reloadScheduled = false;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		internal const string ModGUID = "radamanto.BiomeLock";

		internal const string ModName = "BiomeLock";

		internal const string ModVersion = "1.1.1";

		[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(2)]
		internal static ManualLogSource Log;

		private Harmony _harmony = null;

		internal static ConfigEntry<bool> CE_SE_AdminBypass;

		internal static ConfigEntry<string> CE_SE_BlockedBiomes;

		internal static ConfigEntry<bool> CE_SE_Block_DungeonTeleport;

		internal static ConfigEntry<bool> CE_SE_Block_MapExplore;

		internal static ConfigEntry<bool> CE_SE_Block_AutoPickup;

		internal static ConfigEntry<bool> CE_SE_Block_Pickup;

		internal static ConfigEntry<bool> CE_SE_Block_GenericInteract;

		internal static ConfigEntry<bool> CE_SE_Block_ItemDropInteract;

		internal static ConfigEntry<bool> CE_SE_Block_PickableInteract;

		internal static ConfigEntry<bool> CE_SE_Block_ContainerInteract;

		internal static ConfigEntry<bool> CE_SE_Block_AttackBlock;

		internal static ConfigEntry<bool> CE_SE_Block_Hammer;

		internal static ConfigEntry<bool> CE_SE_Block_TerrainHoe;

		internal static ConfigEntry<bool> CE_SE_Broadcast_Enabled;

		internal static ConfigEntry<float> CE_SE_Broadcast_Interval;

		internal static ConfigEntry<bool> CE_GuardianPower_Enabled;

		internal static ConfigEntry<bool> CE_BossPrevKey_Enabled;

		internal static ConfigEntry<bool> CE_BossDay_Enabled;

		internal static ConfigEntry<int> CE_BossDay_Eikthyr;

		internal static ConfigEntry<int> CE_BossDay_Elder;

		internal static ConfigEntry<int> CE_BossDay_Bonemass;

		internal static ConfigEntry<int> CE_BossDay_Moder;

		internal static ConfigEntry<int> CE_BossDay_Yagluth;

		internal static ConfigEntry<int> CE_BossDay_Queen;

		internal static ConfigEntry<int> CE_BossDay_Fader;

		internal static ConfigEntry<bool> CE_SE_Block_SpawnBlock;

		internal static ConfigEntry<bool> CE_SE_Block_MapPins;

		internal static ConfigEntry<bool> CE_GlobalKeys_PrivateKeys;

		internal static ConfigEntry<bool> CE_SE_Block_TraderInteract;

		internal static ConfigEntry<bool> CE_SE_Block_HildirMapTable;

		internal static ConfigEntry<bool> CE_SkillCap_Enabled;

		internal static ConfigEntry<int> CE_SkillCap_Eikthyr;

		internal static ConfigEntry<int> CE_SkillCap_Elder;

		internal static ConfigEntry<int> CE_SkillCap_Bonemass;

		internal static ConfigEntry<int> CE_SkillCap_Moder;

		internal static ConfigEntry<int> CE_SkillCap_Yagluth;

		internal static ConfigEntry<int> CE_SkillCap_Queen;

		internal static ConfigEntry<int> CE_SkillCap_Fader;

		[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(2)]
		internal static ConfigSync ConfigSync;

		[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(2)]
		private static ConfigEntry<bool> _serverConfigLocked;

		[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(2)]
		private FileSystemWatcher _configWatcher;

		private DateTime _lastCfgWriteUtc = DateTime.MinValue;

		private bool _reloadScheduled;

		private bool _watcherReady;

		private DateTime _ignoreEventsUntilUtc = DateTime.MinValue;

		private void Awake()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			Localizer.Load();
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony = new Harmony("radamanto.BiomeLock");
			SetupServerSyncAndWatcher();
			SetupSEBinds();
			_harmony.PatchAll();
		}

		public static bool IsLocalPlayerAdmin()
		{
			return ConfigSync != null && ConfigSync.IsAdmin;
		}

		private void SetupSEBinds()
		{
			CE_SE_AdminBypass = Cfg("01 - General", "AdminBypass", defaultValue: true, "If true, administrators bypass restrictions.");
			CE_GlobalKeys_PrivateKeys = Cfg("01 - General", "PrivateKeys", defaultValue: true, "If true, redirects content unlocks based on Global Keys to per-player Private Keys.");
			CE_SE_BlockedBiomes = Cfg("02 - BiomeLock", "02.1 - BlockedBiomes", "BlackForest,Swamp,Mountain,Plains,Mistlands,AshLands,DeepNorth", "The biomes listed here will be blocked for players who have not defeated the previous biome’s boss.\nAllowed values: BlackForest, Swamp, Mountain, Plains, Mistlands, AshLands, DeepNorth, Ocean");
			CE_SE_Block_TraderInteract = Cfg("03 - Traders", "03.01 - TraderInteract", defaultValue: true, "If true, blocks interaction with the traders Haldor and the Bog Witch.");
			CE_SE_Block_HildirMapTable = Cfg("03 - Traders", "03.02 - HildirMapTable", defaultValue: true, "If true, blocks interaction on Hildir's map table.");
			CE_SE_Block_DungeonTeleport = Cfg("04 - SE Blocks", "04.01 - Dungeon", defaultValue: true, "If true, blocks dungeon teleport entrances/exits.");
			CE_SE_Block_MapExplore = Cfg("04 - SE Blocks", "04.02 - MapExplore", defaultValue: true, "If true, blocks map exploration.");
			CE_SE_Block_AutoPickup = Cfg("04 - SE Blocks", "04.03 - AutoPickup", defaultValue: true, "If true, blocks automatic pickup.");
			CE_SE_Block_Pickup = Cfg("04 - SE Blocks", "04.04 - Pickup", defaultValue: true, "If true, blocks manual pickup.");
			CE_SE_Block_GenericInteract = Cfg("04 - SE Blocks", "04.05 - Interact", defaultValue: true, "If true, blocks interactions.");
			CE_SE_Block_ItemDropInteract = Cfg("04 - SE Blocks", "04.06 - ItemDropInteract", defaultValue: true, "If true, blocks item drop interactions.");
			CE_SE_Block_PickableInteract = Cfg("04 - SE Blocks", "04.07 - PickableInteract", defaultValue: true, "If true, blocks pickable interactions.");
			CE_SE_Block_ContainerInteract = Cfg("04 - SE Blocks", "04.08 - ContainerInteract", defaultValue: true, "If true, blocks container interactions.");
			CE_SE_Block_AttackBlock = Cfg("04 - SE Blocks", "04.09 - AttackBlock", defaultValue: true, "If true, blocks all player attacks.");
			CE_SE_Block_Hammer = Cfg("04 - SE Blocks", "04.10 - Hammer", defaultValue: true, "If true, blocks hammer actions.");
			CE_SE_Block_TerrainHoe = Cfg("04 - SE Blocks", "04.11 - Hoe/Cultivator", defaultValue: true, "If true, blocks terrain modification by hoe/cultivator.");
			CE_SE_Block_MapPins = Cfg("04 - SE Blocks", "04.12 - MapPins", defaultValue: true, "If true, blocks placing pins on the map.");
			CE_SE_Block_SpawnBlock = Cfg("04 - SE Blocks", "04.13 - MobSpawn", defaultValue: true, "If true, blocks mob spawning.");
			CE_SE_Broadcast_Enabled = Cfg("05 - SE Broadcast", "05.01 - Enable", defaultValue: true, "Displays messages in the center of the screen while the SE_BiomeLock is active.");
			CE_SE_Broadcast_Interval = Cfg("05 - SE Broadcast", "05.02 - IntervalSeconds", 8f, "Interval (in seconds) between BiomeLock broadcast messages.");
			CE_GuardianPower_Enabled = Cfg("06 - Guardian Power", "06.01 - Enable", defaultValue: true, "If true, blocks claiming guardian powers at the altar until the player has the required private key.");
			CE_BossPrevKey_Enabled = Cfg("07 - Boss Summon Key", "07.01 - Enable", defaultValue: true, "If true, blocks boss altar interaction until the player has defeated the previous boss.");
			CE_BossDay_Enabled = Cfg("08 - Boss Summon Day", "08.01 - Enable", defaultValue: true, "If true, blocks boss altar interaction until the configured day.");
			CE_BossDay_Eikthyr = Cfg("08 - Boss Summon Day", "08.02 - Eikthyr", 100, "Minimum day required to summon Eikthyr. (0 = disabled)");
			CE_BossDay_Elder = Cfg("08 - Boss Summon Day", "08.03 - Elder", 200, "Minimum day required to summon Elder. (0 = disabled)");
			CE_BossDay_Bonemass = Cfg("08 - Boss Summon Day", "08.04 - Bonemass", 300, "Minimum day required to summon Bonemass. (0 = disabled)");
			CE_BossDay_Moder = Cfg("08 - Boss Summon Day", "08.05 - Moder", 400, "Minimum day required to summon Moder. (0 = disabled)");
			CE_BossDay_Yagluth = Cfg("08 - Boss Summon Day", "08.06 - Yagluth", 500, "Minimum day required to summon Yagluth. (0 = disabled)");
			CE_BossDay_Queen = Cfg("08 - Boss Summon Day", "08.07 - Queen", 600, "Minimum day required to summon The Queen. (0 = disabled)");
			CE_BossDay_Fader = Cfg("08 - Boss Summon Day", "08.08 - Fader", 700, "Minimum day required to summon Fader. (0 = disabled)");
			CE_SkillCap_Enabled = Cfg("09 - Skill Cap", "09.01 - Enable", defaultValue: true, "If true, caps skill (all skills) levels by boss private keys.");
			CE_SkillCap_Eikthyr = Cfg("09 - Skill Cap", "09.02 - Eikthyr", 0, "Maximum skill level (all skills) allowed while the player does NOT have Eikthyr private key. (0 = disabled)");
			CE_SkillCap_Elder = Cfg("09 - Skill Cap", "09.03 - Elder", 0, "Maximum skill level (all skills) allowed while the player does NOT have Elder private key. (0 = disabled)");
			CE_SkillCap_Bonemass = Cfg("09 - Skill Cap", "09.04 - Bonemass", 0, "Maximum skill level (all skills) allowed while the player does NOT have Bonemass private key. (0 = disabled)");
			CE_SkillCap_Moder = Cfg("09 - Skill Cap", "09.05 - Moder", 0, "Maximum skill level (all skills) allowed while the player does NOT have Moder private key. (0 = disabled)");
			CE_SkillCap_Yagluth = Cfg("09 - Skill Cap", "09.06 - Yagluth", 0, "Maximum skill level (all skills) allowed while the player does NOT have Yagluth private key. (0 = disabled)");
			CE_SkillCap_Queen = Cfg("09 - Skill Cap", "09.07 - Queen", 0, "Maximum skill level (all skills) allowed while the player does NOT have The Queen private key. (0 = disabled)");
			CE_SkillCap_Fader = Cfg("09 - Skill Cap", "09.08 - Fader", 0, "Maximum skill level (all skills) allowed while the player does NOT have Fader private key. Example: (0 = disabled)");
		}

		public void SetupServerSyncAndWatcher()
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			bool flag = false;
			try
			{
				((BaseUnityPlugin)this).Config.SaveOnConfigSet = false;
				ConfigSync = new ConfigSync(((BaseUnityPlugin)this).Info.Metadata.GUID)
				{
					DisplayName = ((BaseUnityPlugin)this).Info.Metadata.Name,
					CurrentVersion = ((BaseUnityPlugin)this).Info.Metadata.Version.ToString(),
					MinimumRequiredVersion = ((BaseUnityPlugin)this).Info.Metadata.Version.ToString()
				};
				_serverConfigLocked = ((BaseUnityPlugin)this).Config.Bind<bool>("01 - General", "LockConfiguration", true, new ConfigDescription("If true, the server locks synchronized configs.", (AcceptableValueBase)null, new object[1]
				{
					new ConfigurationManagerAttributes
					{
						Browsable = false
					}
				}));
				ConfigSync.AddLockingConfigEntry<bool>(_serverConfigLocked);
				SetupConfigWatcher();
				flag = true;
			}
			catch
			{
			}
			finally
			{
				((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
				if (flag)
				{
					((BaseUnityPlugin)this).Config.Save();
				}
			}
		}

		protected ConfigEntry<T> Cfg<[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(2)] T>(string section, string key, T defaultValue, string description, bool synced = true)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			return config(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), synced);
		}

		private ConfigEntry<T> config<[<772b41c4-974b-4eba-9a88-345304c073ea>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);
			try
			{
				SyncedConfigEntry<T> syncedConfigEntry = ((ConfigSync != null) ? ConfigSync.AddConfigEntry<T>(val2) : null);
				if (syncedConfigEntry != null)
				{
					syncedConfigEntry.SynchronizedConfig = synchronizedSetting;
				}
			}
			catch
			{
			}
			return val2;
		}

		private void SetupConfigWatcher()
		{
			try
			{
				if (_configWatcher != null)
				{
					_configWatcher.Dispose();
				}
				string configPath = Paths.ConfigPath;
				string fileName = Path.GetFileName(((BaseUnityPlugin)this).Config.ConfigFilePath);
				_configWatcher = new FileSystemWatcher(configPath, fileName)
				{
					IncludeSubdirectories = false,
					NotifyFilter = (NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite | NotifyFilters.CreationTime)
				};
				FileSystemEventHandler onChanged = [<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)] (object _, FileSystemEventArgs __) =>
				{
					if (!(DateTime.UtcNow < _ignoreEventsUntilUtc))
					{
						_lastCfgWriteUtc = DateTime.UtcNow;
						if (!_reloadScheduled)
						{
							_reloadScheduled = true;
							((MonoBehaviour)this).StartCoroutine(ReloadConfigAfterQuietPeriod(0.75f));
						}
					}
				};
				_configWatcher.Changed += onChanged;
				_configWatcher.Created += onChanged;
				_configWatcher.Renamed += [<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)] (object _, RenamedEventArgs __) =>
				{
					onChanged(_, __);
				};
				_configWatcher.EnableRaisingEvents = true;
				_watcherReady = true;
			}
			catch
			{
			}
		}

		[IteratorStateMachine(typeof(<ReloadConfigAfterQuietPeriod>d__58))]
		private IEnumerator ReloadConfigAfterQuietPeriod(float quietSeconds)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ReloadConfigAfterQuietPeriod>d__58(0)
			{
				<>4__this = this,
				quietSeconds = quietSeconds
			};
		}
	}
	[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
	[HarmonyPatch]
	[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
	internal static class BiomeLock_ZoneSystem_GetGlobalKey_RedirectPrivateKeys
	{
		private static readonly HashSet<string> RedirectedKeys = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
		{
			"defeated_eikthyr", "defeated_gdking", "defeated_bonemass", "defeated_dragon", "defeated_goblinking", "defeated_queen", "defeated_fader", "defeated_serpent", "KilledTroll", "killed_surtling",
			"KilledBat", "Hildir1", "Hildir2", "Hildir3"
		};

		private static MethodBase TargetMethod()
		{
			return AccessTools.Method(typeof(ZoneSystem), "GetGlobalKey", new Type[2]
			{
				typeof(string),
				typeof(string).MakeByRefType()
			}, (Type[])null);
		}

		private static bool Prefix(string name, ref string value, ref bool __result)
		{
			try
			{
				if (string.IsNullOrWhiteSpace(name))
				{
					return true;
				}
				if ((Object)(object)ZNet.instance == (Object)null || ZNet.instance.IsDedicated())
				{
					return true;
				}
				if (!BiomeLockPlugin.CE_GlobalKeys_PrivateKeys.Value)
				{
					return true;
				}
				if (BiomeLockPlugin.CE_SE_AdminBypass.Value && BiomeLockPlugin.IsLocalPlayerAdmin())
				{
					return true;
				}
				if (!RedirectedKeys.Contains(name))
				{
					return true;
				}
				__result = BiomeLockAPI.HasPrivateKey(name);
				value = string.Empty;
				return false;
			}
			catch
			{
				return true;
			}
		}
	}
	[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(2)]
	[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
	internal static class BiomeLock_KeyRefresh
	{
		private static bool _pending;

		private static float _nextRunAt;

		private static MethodInfo _miStoreGui_FillList;

		private static MethodInfo _miInventoryGui_UpdateCraftingPanel;

		private static MethodInfo _miInventoryGui_UpdateRecipeList;

		private static MethodInfo _miPlayer_UpdateKnownRecipesList;

		private static MethodInfo _miPlayer_UpdateAvailablePiecesList;

		internal static void NotifyKeysChanged()
		{
			try
			{
				_pending = true;
				float time = Time.time;
				if (_nextRunAt < time)
				{
					_nextRunAt = time + 0.05f;
				}
			}
			catch
			{
			}
		}

		private static void EnsureMethods()
		{
			if (_miStoreGui_FillList == null)
			{
				_miStoreGui_FillList = AccessTools.Method(typeof(StoreGui), "FillList", (Type[])null, (Type[])null);
			}
			if (_miInventoryGui_UpdateCraftingPanel == null)
			{
				_miInventoryGui_UpdateCraftingPanel = AccessTools.Method(typeof(InventoryGui), "UpdateCraftingPanel", (Type[])null, (Type[])null);
			}
			if (_miInventoryGui_UpdateRecipeList == null)
			{
				_miInventoryGui_UpdateRecipeList = AccessTools.Method(typeof(InventoryGui), "UpdateRecipeList", (Type[])null, (Type[])null);
			}
			if (_miPlayer_UpdateKnownRecipesList == null)
			{
				_miPlayer_UpdateKnownRecipesList = AccessTools.Method(typeof(Player), "UpdateKnownRecipesList", (Type[])null, (Type[])null);
			}
			if (_miPlayer_UpdateAvailablePiecesList == null)
			{
				_miPlayer_UpdateAvailablePiecesList = AccessTools.Method(typeof(Player), "UpdateAvailablePiecesList", (Type[])null, (Type[])null);
			}
		}

		internal static void TryRunPending()
		{
			try
			{
				if (!_pending || Time.time < _nextRunAt)
				{
					return;
				}
				_pending = false;
				if ((Object)(object)ZNet.instance == (Object)null || ZNet.instance.IsDedicated() || (Object)(object)Player.m_localPlayer == (Object)null)
				{
					return;
				}
				EnsureMethods();
				Player localPlayer = Player.m_localPlayer;
				try
				{
					if (_miPlayer_UpdateKnownRecipesList != null)
					{
						_miPlayer_UpdateKnownRecipesList.Invoke(localPlayer, Array.Empty<object>());
					}
					if (_miPlayer_UpdateAvailablePiecesList != null)
					{
						_miPlayer_UpdateAvailablePiecesList.Invoke(localPlayer, Array.Empty<object>());
					}
				}
				catch
				{
				}
				try
				{
					localPlayer.UpdateEvents();
				}
				catch
				{
				}
				try
				{
					if ((Object)(object)InventoryGui.instance != (Object)null)
					{
						if (_miInventoryGui_UpdateCraftingPanel != null)
						{
							_miInventoryGui_UpdateCraftingPanel.Invoke(InventoryGui.instance, Array.Empty<object>());
						}
						if (_miInventoryGui_UpdateRecipeList != null)
						{
							_miInventoryGui_UpdateRecipeList.Invoke(InventoryGui.instance, Array.Empty<object>());
						}
					}
				}
				catch
				{
				}
				try
				{
					if ((Object)(object)StoreGui.instance != (Object)null && StoreGui.IsVisible() && _miStoreGui_FillList != null)
					{
						_miStoreGui_FillList.Invoke(StoreGui.instance, Array.Empty<object>());
					}
				}
				catch
				{
				}
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch(typeof(Hud), "Update")]
	internal static class BL_KeyRefresh_HudUpdate
	{
		private static void Postfix()
		{
			BiomeLock_KeyRefresh.TryRunPending();
		}
	}
	[HarmonyPatch]
	internal static class BL_KeyRefresh_RPC_SetPrivateKey
	{
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
		private static MethodBase TargetMethod()
		{
			return AccessTools.Method(typeof(BiomeLockPrivateKeys), "RPC_BL_SetPrivateKey", (Type[])null, (Type[])null);
		}

		private static void Postfix()
		{
			BiomeLock_KeyRefresh.NotifyKeysChanged();
		}
	}
	[HarmonyPatch]
	internal static class BL_KeyRefresh_RPC_RemovePrivateKey
	{
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
		private static MethodBase TargetMethod()
		{
			return AccessTools.Method(typeof(BiomeLockPrivateKeys), "RPC_BL_RemovePrivateKey", (Type[])null, (Type[])null);
		}

		private static void Postfix()
		{
			BiomeLock_KeyRefresh.NotifyKeysChanged();
		}
	}
	[HarmonyPatch]
	internal static class BL_KeyRefresh_RPC_ResetPrivateKeys
	{
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
		private static MethodBase TargetMethod()
		{
			return AccessTools.Method(typeof(BiomeLockPrivateKeys), "RPC_BL_ResetPrivateKeys", (Type[])null, (Type[])null);
		}

		private static void Postfix()
		{
			BiomeLock_KeyRefresh.NotifyKeysChanged();
		}
	}
	[HarmonyPatch]
	internal static class BL_KeyRefresh_LoadKeysFromPlayer
	{
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
		private static MethodBase TargetMethod()
		{
			return AccessTools.Method(typeof(BiomeLockPrivateKeys), "LoadKeysFromPlayer", (Type[])null, (Type[])null);
		}

		private static void Postfix()
		{
			BiomeLock_KeyRefresh.NotifyKeysChanged();
		}
	}
	[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
	[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
	internal static class BiomeLockPrivateKeys
	{
		internal const string PrivatePrefix = "bl_";

		internal const string PlayerSaveKey = "BL_PrivateKeys";

		internal const string RPC_SetPrivateKey = "BL_SetPrivateKey";

		internal const string RPC_RemovePrivateKey = "BL_RemovePrivateKey";

		internal const string RPC_ResetPrivateKeys = "BL_ResetPrivateKeys";

		internal const string RPC_ClientListKeysBegin = "BL_ClientListKeysBegin";

		internal const string RPC_ClientListKeysLine = "BL_ClientListKeysLine";

		internal const string RPC_ClientListKeysEnd = "BL_ClientListKeysEnd";

		internal const string RPC_ServerListKeys = "BL_ServerListKeys";

		internal const string RPC_ServerSetPrivateKeys = "BL_ServerSetPrivateKeys";

		internal const string RPC_ServerSetPrivateKey = "BL_ServerSetPrivateKey";

		internal const string RPC_ServerRemovePrivateKey = "BL_ServerRemovePrivateKey";

		internal const float ShareRadiusMeters = 120f;

		internal static HashSet<string> PrivateKeys = new HashSet<string>(StringComparer.Ordinal);

		internal static readonly Dictionary<long, HashSet<string>> ServerPrivateKeysByUid = new Dictionary<long, HashSet<string>>();

		private static readonly HashSet<string> BossGlobalKeys = new HashSet<string>(StringComparer.Ordinal)
		{
			"defeated_eikthyr", "defeated_gdking", "defeated_bonemass", "defeated_dragon", "defeated_goblinking", "defeated_queen", "defeated_fader", "defeated_serpent", "KilledTroll", "killed_surtling",
			"KilledBat", "Hildir1", "Hildir2", "Hildir3"
		};

		internal static bool IsInMainScene()
		{
			try
			{
				return (Object)(object)ZNetScene.instance != (Object)null && (Object)(object)Player.m_localPlayer != (Object)null;
			}
			catch
			{
				return false;
			}
		}

		internal static string NormalizeKey(string key)
		{
			return (key ?? string.Empty).Trim().ToLowerInvariant();
		}

		internal static bool IsBossGlobalKey(string globalKeyLower)
		{
			return BossGlobalKeys.Contains(globalKeyLower);
		}

		internal static string ToPrivateKey(string globalKeyLower)
		{
			return "bl_" + globalKeyLower;
		}

		internal static void EnsurePlayerRpcRegistered()
		{
			if (ZRoutedRpc.instance == null)
			{
				return;
			}
			try
			{
				ZRoutedRpc.instance.Register<string>("BL_SetPrivateKey", (Action<long, string>)RPC_BL_SetPrivateKey);
				ZRoutedRpc.instance.Register<string>("BL_RemovePrivateKey", (Action<long, string>)RPC_BL_RemovePrivateKey);
				ZRoutedRpc.instance.Register("BL_ResetPrivateKeys", (Action<long>)RPC_BL_ResetPrivateKeys);
				ZRoutedRpc.instance.Register<long, int>("BL_ClientListKeysBegin", (Action<long, long, int>)RPC_BL_ClientListKeysBegin);
				ZRoutedRpc.instance.Register<long, string>("BL_ClientListKeysLine", (Action<long, long, string>)RPC_BL_ClientListKeysLine);
				ZRoutedRpc.instance.Register<long>("BL_ClientListKeysEnd", (Action<long, long>)RPC_BL_ClientListKeysEnd);
			}
			catch
			{
			}
		}

		internal static void EnsureServerRpcRegistered()
		{
			if (ZRoutedRpc.instance == null || (Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
			{
				return;
			}
			try
			{
				ZRoutedRpc.instance.Register<long>("BL_ServerListKeys", (Action<long, long>)RPC_BL_ServerListKeys);
				ZRoutedRpc.instance.Register<string, long>("BL_ServerSetPrivateKeys", (Action<long, string, long>)RPC_BL_ServerSetPrivateKeys);
				ZRoutedRpc.instance.Register<string, long>("BL_ServerSetPrivateKey", (Action<long, string, long>)RPC_BL_ServerSetPrivateKey);
				ZRoutedRpc.instance.Register<string, long>("BL_ServerRemovePrivateKey", (Action<long, string, long>)RPC_BL_ServerRemovePrivateKey);
			}
			catch
			{
			}
		}

		private static void RPC_BL_SetPrivateKey(long sender, string privateKey)
		{
			try
			{
				if (!IsInMainScene())
				{
					return;
				}
				privateKey = NormalizeKey(privateKey);
				if (privateKey.Length == 0 || !PrivateKeys.Add(privateKey))
				{
					return;
				}
				try
				{
					if ((Object)(object)Player.m_localPlayer != (Object)null)
					{
						SaveKeysToPlayer(Player.m_localPlayer);
					}
				}
				catch
				{
				}
				BiomeLockAPI.RaisePrivateKeyAdded(privateKey);
				try
				{
					if (ZRoutedRpc.instance != null && (Object)(object)ZNet.instance != (Object)null)
					{
						long uID = ZNet.GetUID();
						ZRoutedRpc.instance.InvokeRoutedRPC("BL_ServerSetPrivateKey", new object[2] { privateKey, uID });
					}
				}
				catch
				{
				}
			}
			catch (Exception ex)
			{
				BiomeLockPlugin.Log.LogError((object)("[RPC_BL_SetPrivateKey] " + ex));
			}
		}

		private static void RPC_BL_RemovePrivateKey(long sender, string privateKey)
		{
			try
			{
				if (!IsInMainScene())
				{
					return;
				}
				privateKey = NormalizeKey(privateKey);
				if (privateKey.Length == 0 || !PrivateKeys.Remove(privateKey))
				{
					return;
				}
				try
				{
					if ((Object)(object)Player.m_localPlayer != (Object)null)
					{
						SaveKeysToPlayer(Player.m_localPlayer);
					}
				}
				catch
				{
				}
				BiomeLockAPI.RaisePrivateKeyRemoved(privateKey);
				try
				{
					if (ZRoutedRpc.instance != null && (Object)(object)ZNet.instance != (Object)null)
					{
						long uID = ZNet.GetUID();
						ZRoutedRpc.instance.InvokeRoutedRPC("BL_ServerRemovePrivateKey", new object[2] { privateKey, uID });
					}
				}
				catch
				{
				}
			}
			catch (Exception ex)
			{
				BiomeLockPlugin.Log.LogError((object)("[RPC_BL_RemovePrivateKey] " + ex));
			}
		}

		private static void RPC_BL_ResetPrivateKeys(long sender)
		{
			try
			{
				if (!IsInMainScene())
				{
					return;
				}
				PrivateKeys = new HashSet<string>(StringComparer.Ordinal);
				try
				{
					if ((Object)(object)Player.m_localPlayer != (Object)null)
					{
						SaveKeysToPlayer(Player.m_localPlayer);
					}
				}
				catch
				{
				}
				BiomeLockAPI.RaisePrivateKeysReset();
				try
				{
					if (ZRoutedRpc.instance != null && (Object)(object)ZNet.instance != (Object)null)
					{
						long uID = ZNet.GetUID();
						ZRoutedRpc.instance.InvokeRoutedRPC("BL_ServerSetPrivateKeys", new object[2] { "", uID });
					}
				}
				catch
				{
				}
			}
			catch (Exception ex)
			{
				BiomeLockPlugin.Log.LogError((object)("[RPC_BL_ResetPrivateKeys] " + ex));
			}
		}

		private static void ClientConsoleAdd(string msg)
		{
			try
			{
				if ((Object)(object)Console.instance != (Object)null)
				{
					((Terminal)Console.instance).AddString(msg);
				}
			}
			catch
			{
			}
		}

		private static void RPC_BL_ClientListKeysBegin(long sender, long targetUid, int count)
		{
			try
			{
				if (IsInMainScene())
				{
					ClientConsoleAdd($"[BL] TotalKeys: {count}");
				}
			}
			catch (Exception ex)
			{
				BiomeLockPlugin.Log.LogError((object)("[RPC_BL_ClientListKeysBegin] " + ex));
			}
		}

		private static void RPC_BL_ClientListKeysLine(long sender, long targetUid, string key)
		{
			try
			{
				if (IsInMainScene())
				{
					key = NormalizeKey(key);
					if (key.Length != 0)
					{
						ClientConsoleAdd(key ?? "");
					}
				}
			}
			catch (Exception ex)
			{
				BiomeLockPlugin.Log.LogError((object)("[RPC_BL_ClientListKeysLine] " + ex));
			}
		}

		private static void RPC_BL_ClientListKeysEnd(long sender, long targetUid)
		{
			try
			{
				if (IsInMainScene())
				{
				}
			}
			catch (Exception ex)
			{
				BiomeLockPlugin.Log.LogError((object)("[RPC_BL_ClientListKeysEnd] " + ex));
			}
		}

		internal static void ClientDistributeBossPrivateKey(string globalKeyLower)
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!IsInMainScene() || (Object)(object)ZNet.instance == (Object)null || ZNet.instance.IsDedicated() || ZRoutedRpc.instance == null || !IsBossGlobalKey(globalKeyLower))
				{
					return;
				}
				string text = ToPrivateKey(globalKeyLower);
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer == (Object)null)
				{
					return;
				}
				List<Player> list = new List<Player>();
				Player.GetPlayersInRange(((Component)localPlayer).transform.position, 120f, list);
				if (list == null || list.Count == 0)
				{
					return;
				}
				for (int i = 0; i < list.Count; i++)
				{
					Player val = list[i];
					if (!((Object)(object)val == (Object)null))
					{
						string playerName = val.GetPlayerName();
						if (!string.IsNullOrEmpty(playerName) && TryResolveUidByPlayerName(playerName, out var uid) && uid != 0)
						{
							ZRoutedRpc.instance.InvokeRoutedRPC(uid, "BL_SetPrivateKey", new object[1] { text });
						}
					}
				}
			}
			catch (Exception ex)
			{
				BiomeLockPlugin.Log.LogError((object)("[ClientDistributeBossPrivateKey] " + ex));
			}
		}

		private static void RPC_BL_ServerListKeys(long sender, long targetUid)
		{
			try
			{
				if (!IsSenderAdmin(sender))
				{
					return;
				}
				long num = ((targetUid != 0L) ? targetUid : sender);
				if (!ServerPrivateKeysByUid.TryGetValue(num, out var value) || value == null)
				{
					try
					{
						if (ZRoutedRpc.instance != null)
						{
							ZRoutedRpc.instance.InvokeRoutedRPC(sender, "BL_ClientListKeysBegin", new object[2] { num, 0 });
							ZRoutedRpc.instance.InvokeRoutedRPC(sender, "BL_ClientListKeysEnd", new object[1] { num });
						}
						return;
					}
					catch
					{
						return;
					}
				}
				try
				{
					if (ZRoutedRpc.instance != null)
					{
						List<string> list = value.OrderBy<string, string>([<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)] (string s) => s, StringComparer.Ordinal).ToList();
						ZRoutedRpc.instance.InvokeRoutedRPC(sender, "BL_ClientListKeysBegin", new object[2] { num, list.Count });
						for (int i = 0; i < list.Count; i++)
						{
							ZRoutedRpc.instance.InvokeRoutedRPC(sender, "BL_ClientListKeysLine", new object[2]
							{
								num,
								list[i]
							});
						}
						ZRoutedRpc.instance.InvokeRoutedRPC(sender, "BL_ClientListKeysEnd", new object[1] { num });
					}
				}
				catch
				{
				}
			}
			catch (Exception ex)
			{
				BiomeLockPlugin.Log.LogError((object)("[RPC_BL_ServerListKeys] " + ex));
			}
		}

		private static bool AllowTrackingOrAdmin(long sender, long targetUid)
		{
			try
			{
				long num = ((targetUid != 0L) ? targetUid : sender);
				if (num == sender)
				{
					return true;
				}
				return IsSenderAdmin(sender);
			}
			catch
			{
				return false;
			}
		}

		private static void RPC_BL_ServerSetPrivateKeys(long sender, string keysCsv, long targetUid)
		{
			try
			{
				long num = ((targetUid != 0L) ? targetUid : sender);
				if (!AllowTrackingOrAdmin(sender, num))
				{
					return;
				}
				HashSet<string> hashSet = new HashSet<string>(StringComparer.Ordinal);
				if (!string.IsNullOrEmpty(keysCsv))
				{
					string[] array = keysCsv.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
					foreach (string key in array)
					{
						string text = NormalizeKey(key);
						if (text.Length != 0 && text.StartsWith("bl_", StringComparison.Ordinal))
						{
							hashSet.Add(text);
						}
					}
				}
				ServerPrivateKeysByUid[num] = hashSet;
			}
			catch (Exception ex)
			{
				BiomeLockPlugin.Log.LogError((object)("[RPC_BL_ServerSetPrivateKeys] " + ex));
			}
		}

		private static void RPC_BL_ServerSetPrivateKey(long sender, string privateKey, long targetUid)
		{
			try
			{
				long num = ((targetUid != 0L) ? targetUid : sender);
				if (!AllowTrackingOrAdmin(sender, num))
				{
					return;
				}
				privateKey = NormalizeKey(privateKey);
				if (privateKey.Length == 0 || !privateKey.StartsWith("bl_", StringComparison.Ordinal))
				{
					return;
				}
				if (!ServerPrivateKeysByUid.TryGetValue(num, out var value) || value == null)
				{
					value = new HashSet<string>(StringComparer.Ordinal);
					ServerPrivateKeysByUid[num] = value;
				}
				value.Add(privateKey);
				try
				{
					if (num != sender && ZRoutedRpc.instance != null)
					{
						ZRoutedRpc.instance.InvokeRoutedRPC(num, "BL_SetPrivateKey", new object[1] { privateKey });
					}
				}
				catch
				{
				}
			}
			catch (Exception ex)
			{
				BiomeLockPlugin.Log.LogError((object)("[RPC_BL_ServerSetPrivateKey] " + ex));
			}
		}

		private static void RPC_BL_ServerRemovePrivateKey(long sender, string privateKey, long targetUid)
		{
			try
			{
				long num = ((targetUid != 0L) ? targetUid : sender);
				if (!AllowTrackingOrAdmin(sender, num))
				{
					return;
				}
				privateKey = NormalizeKey(privateKey);
				if (privateKey.Length == 0 || !privateKey.StartsWith("bl_", StringComparison.Ordinal))
				{
					return;
				}
				if (ServerPrivateKeysByUid.TryGetValue(num, out var value))
				{
					value?.Remove(privateKey);
				}
				try
				{
					if (num != sender && ZRoutedRpc.instance != null)
					{
						ZRoutedRpc.instance.InvokeRoutedRPC(num, "BL_RemovePrivateKey", new object[1] { privateKey });
					}
				}
				catch
				{
				}
			}
			catch (Exception ex)
			{
				BiomeLockPlugin.Log.LogError((object)("[RPC_BL_ServerRemovePrivateKey] " + ex));
			}
		}

		private static bool IsSenderAdmin(long senderUid)
		{
			try
			{
				if ((Object)(object)ZNet.instance == (Object)null || !ZNet.instance.IsServer())
				{
					return false;
				}
				try
				{
					if (BiomeLockPlugin.IsLocalPlayerAdmin())
					{
						return true;
					}
				}
				catch
				{
				}
				if (!TryGetPeerByUid(senderUid, out var peer))
				{
					return false;
				}
				string hostName = peer.m_socket.GetHostName();
				if (string.IsNullOrEmpty(hostName))
				{
					return false;
				}
				return ZNet.instance.IsAdmin(hostName);
			}
			catch
			{
				return false;
			}
		}

		internal static bool TryGetPeerByUid(long uid, out ZNetPeer peer)
		{
			peer = null;
			if ((Object)(object)ZNet.instance == (Object)null)
			{
				return false;
			}
			try
			{
				List<ZNetPeer> peers = ZNet.instance.GetPeers();
				if (peers == null)
				{
					return false;
				}
				for (int i = 0; i < peers.Count; i++)
				{
					ZNetPeer val = peers[i];
					if (val != null && val.m_uid == uid)
					{
						peer = val;
						return true;
					}
				}
			}
			catch
			{
			}
			return false;
		}

		internal static bool TryResolveUidByPlayerName(string playerName, out long uid)
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: 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)
			uid = 0L;
			try
			{
				if (string.IsNullOrEmpty(playerName))
				{
					return false;
				}
				if ((Object)(object)Player.m_localPlayer != (Object)null)
				{
					string playerName2 = Player.m_localPlayer.GetPlayerName();
					if (!string.IsNullOrEmpty(playerName2) && string.Equals(playerName2, playerName, StringComparison.OrdinalIgnoreCase))
					{
						uid = ZNet.GetUID();
						return uid != 0;
					}
				}
				try
				{
					if ((Object)(object)ZNet.instance != (Object)null)
					{
						List<PlayerInfo> playerList = ZNet.instance.GetPlayerList();
						if (playerList != null)
						{
							for (int i = 0; i < playerList.Count; i++)
							{
								PlayerInfo val = playerList[i];
								if (string.Equals(val.m_name, playerName, StringComparison.OrdinalIgnoreCase))
								{
									uid = ((ZDOID)(ref val.m_characterID)).UserID;
									return uid != 0;
								}
							}
						}
					}
				}
				catch
				{
				}
			}
			catch
			{
			}
			try
			{
				if ((Object)(object)ZNet.instance == (Object)null)
				{
					return false;
				}
				List<ZNetPeer> peers = ZNet.instance.GetPeers();
				if (peers == null)
				{
					return false;
				}
				for (int j = 0; j < peers.Count; j++)
				{
					ZNetPeer val2 = peers[j];
					if (val2 != null && string.Equals(val2.m_playerName, playerName, StringComparison.OrdinalIgnoreCase))
					{
						uid = val2.m_uid;
						return uid != 0;
					}
				}
			}
			catch
			{
			}
			return false;
		}

		internal static void LoadKeysFromPlayer(Player p)
		{
			PrivateKeys = new HashSet<string>(StringComparer.Ordinal);
			if (p.m_customData == null || !p.m_customData.TryGetValue("BL_PrivateKeys", out var value) || string.IsNullOrEmpty(value))
			{
				return;
			}
			string[] array = value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries);
			foreach (string key in array)
			{
				string text = NormalizeKey(key);
				if (text.Length > 0)
				{
					PrivateKeys.Add(text);
				}
			}
		}

		internal static void SaveKeysToPlayer(Player p)
		{
			if (p.m_customData == null)
			{
				p.m_customData = new Dictionary<string, string>();
			}
			string value = string.Join(",", PrivateKeys.OrderBy<string, string>([<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)] (string s) => s, StringComparer.Ordinal));
			p.m_customData["BL_PrivateKeys"] = value;
		}

		internal static string GetPrivateKeysCsv()
		{
			return string.Join(",", PrivateKeys.OrderBy<string, string>([<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)] (string s) => s, StringComparer.Ordinal));
		}
	}
	[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
	[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
	[HarmonyPatch]
	internal static class BL_Patches_Player_LoadSaveAndRpc
	{
		[HarmonyPatch(typeof(Player), "EquipInventoryItems")]
		[HarmonyPrefix]
		private static void Player_EquipInventoryItems_Prefix(Player __instance)
		{
			try
			{
				if (!BiomeLockPrivateKeys.IsInMainScene())
				{
					return;
				}
				BiomeLockPrivateKeys.LoadKeysFromPlayer(__instance);
				BiomeLockPrivateKeys.EnsurePlayerRpcRegistered();
				try
				{
					if (ZRoutedRpc.instance != null && (Object)(object)ZNet.instance != (Object)null && !ZNet.instance.IsDedicated())
					{
						long uID = ZNet.GetUID();
						ZRoutedRpc.instance.InvokeRoutedRPC("BL_ServerSetPrivateKeys", new object[2]
						{
							BiomeLockPrivateKeys.GetPrivateKeysCsv(),
							uID
						});
					}
				}
				catch
				{
				}
			}
			catch (Exception ex)
			{
				BiomeLockPlugin.Log.LogError((object)("[Player_EquipInventoryItems_Prefix] " + ex));
			}
		}

		[HarmonyPatch(typeof(Player), "Save", new Type[] { typeof(ZPackage) })]
		[HarmonyPrefix]
		private static void Player_Save_Prefix(Player __instance)
		{
			try
			{
				if (!BiomeLockPrivateKeys.IsInMainScene())
				{
					BiomeLockPrivateKeys.PrivateKeys = new HashSet<string>(StringComparer.Ordinal);
				}
				else
				{
					BiomeLockPrivateKeys.SaveKeysToPlayer(__instance);
				}
			}
			catch (Exception ex)
			{
				BiomeLockPlugin.Log.LogError((object)("[Player_Save_Prefix] " + ex));
			}
		}
	}
	[HarmonyPatch]
	internal static class BL_Patches_Server_RegisterAnd_Distribute
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(ZoneSystem), "Load")]
		private static void ZoneSystem_Load_Postfix()
		{
			try
			{
				BiomeLockPrivateKeys.EnsureServerRpcRegistered();
			}
			catch (Exception ex)
			{
				BiomeLockPlugin.Log.LogError((object)("[ZoneSystem_Load_Postfix] " + ex));
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ZoneSystem), "SetGlobalKey", new Type[] { typeof(string) })]
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
		private static void ZoneSystem_SetGlobalKey_Postfix(string name)
		{
			try
			{
				string text = BiomeLockPrivateKeys.NormalizeKey(name);
				if (text.Length != 0 && BiomeLockPrivateKeys.IsBossGlobalKey(text))
				{
					BiomeLockPrivateKeys.ClientDistributeBossPrivateKey(text);
				}
			}
			catch (Exception ex)
			{
				BiomeLockPlugin.Log.LogError((object)("[ZoneSystem_SetGlobalKey_Postfix] " + ex));
			}
		}

		[HarmonyPatch(typeof(ZoneSystem), "RPC_SetGlobalKey")]
		[HarmonyPostfix]
		private static void ZoneSystem_RPC_SetGlobalKey_Postfix()
		{
		}
	}
	[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
	[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
	internal static class BiomeLock_SE
	{
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		[HarmonyPatch(typeof(Vegvisir), "Interact")]
		private static class Vegvisir_Interact_Block_HildirMapTable
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static bool Prefix(Vegvisir __instance)
			{
				try
				{
					if (!BiomeLockPlugin.CE_SE_Block_HildirMapTable.Value)
					{
						return true;
					}
					if ((Object)(object)__instance == (Object)null)
					{
						return true;
					}
					if (IsHildirMapTable(__instance))
					{
						return false;
					}
					return true;
				}
				catch
				{
					return true;
				}
			}
		}

		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		[HarmonyPatch(typeof(Vegvisir), "GetHoverText")]
		private static class Vegvisir_GetHoverText_Block_HildirMapTable
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static bool Prefix(Vegvisir __instance, ref string __result)
			{
				try
				{
					if (!BiomeLockPlugin.CE_SE_Block_HildirMapTable.Value)
					{
						return true;
					}
					if ((Object)(object)__instance == (Object)null)
					{
						return true;
					}
					if (IsHildirMapTable(__instance))
					{
						__result = string.Empty;
						return false;
					}
					return true;
				}
				catch
				{
					return true;
				}
			}
		}

		[HarmonyPatch(typeof(Vegvisir), "GetHoverName")]
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		private static class Vegvisir_GetHoverName_Block_HildirMapTable
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static bool Prefix(Vegvisir __instance, ref string __result)
			{
				try
				{
					if (!BiomeLockPlugin.CE_SE_Block_HildirMapTable.Value)
					{
						return true;
					}
					if ((Object)(object)__instance == (Object)null)
					{
						return true;
					}
					if (IsHildirMapTable(__instance))
					{
						__result = string.Empty;
						return false;
					}
					return true;
				}
				catch
				{
					return true;
				}
			}
		}

		[HarmonyPatch(typeof(Trader), "Interact", new Type[]
		{
			typeof(Humanoid),
			typeof(bool),
			typeof(bool)
		})]
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		private static class Trader_Interact_Block
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static bool Prefix(Trader __instance, Humanoid character, bool hold, bool alt)
			{
				if (hold)
				{
					return true;
				}
				if (BiomeLockPlugin.CE_SE_AdminBypass.Value && BiomeLockPlugin.IsLocalPlayerAdmin())
				{
					return true;
				}
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer == (Object)null)
				{
					return true;
				}
				if ((Object)(object)character != (Object)(object)localPlayer)
				{
					return true;
				}
				if (TraderAllowedByApiRule(__instance))
				{
					return true;
				}
				string text = LocalizeBlockedTraderMessage(__instance);
				if (!string.IsNullOrEmpty(text))
				{
					MessageHud instance = MessageHud.instance;
					if (instance != null)
					{
						instance.ShowMessage((MessageType)2, text, 0, (Sprite)null, false);
					}
				}
				return false;
			}
		}

		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		[HarmonyPatch(typeof(Humanoid), "StartAttack")]
		private static class Humanoid_StartAttack_Block_All
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static bool Prefix(Humanoid __instance, ref bool __result)
			{
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (!BiomeLockPlugin.CE_SE_Block_AttackBlock.Value)
					{
						return true;
					}
					Player val = (Player)(object)((__instance is Player) ? __instance : null);
					if ((Object)(object)val == (Object)null)
					{
						return true;
					}
					ItemData currentWeapon = ((Humanoid)val).GetCurrentWeapon();
					if (IsBow(currentWeapon))
					{
						return true;
					}
					if (!ShouldBlockAtPosition(val, ((Component)val).transform.position))
					{
						return true;
					}
					ShowAttackBlockedMessage(val);
					__result = false;
					return false;
				}
				catch
				{
					return true;
				}
			}
		}

		[HarmonyPatch(typeof(Humanoid), "IsBlocking")]
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		private static class Humanoid_IsBlocking_Block_Parry
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static bool Prefix(Humanoid __instance, ref bool __result)
			{
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (!BiomeLockPlugin.CE_SE_Block_AttackBlock.Value)
					{
						return true;
					}
					Player val = (Player)(object)((__instance is Player) ? __instance : null);
					if ((Object)(object)val == (Object)null)
					{
						return true;
					}
					if (!IsTryingToBlock((Humanoid)(object)val))
					{
						return true;
					}
					ItemData currentBlockerItem = GetCurrentBlockerItem((Humanoid)(object)val);
					if (currentBlockerItem == null)
					{
						return true;
					}
					if (!ShouldBlockAtPosition(val, ((Component)val).transform.position))
					{
						return true;
					}
					__result = false;
					return false;
				}
				catch
				{
					return true;
				}
			}
		}

		[HarmonyPatch(typeof(Attack), "OnAttackTrigger")]
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		private static class Attack_OnAttackTrigger_Block_All
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static bool Prefix(Attack __instance)
			{
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (!BiomeLockPlugin.CE_SE_Block_AttackBlock.Value)
					{
						return true;
					}
					Player localPlayer = Player.m_localPlayer;
					if ((Object)(object)localPlayer == (Object)null)
					{
						return true;
					}
					if ((Object)(object)__instance.m_character != (Object)(object)localPlayer)
					{
						return true;
					}
					if (!ShouldBlockAtPosition(localPlayer, ((Component)localPlayer).transform.position))
					{
						return true;
					}
					ShowAttackBlockedMessage(localPlayer);
					return false;
				}
				catch
				{
					return true;
				}
			}
		}

		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		[HarmonyPatch(typeof(Player), "UpdateAttackBowDraw")]
		private static class Player_UpdateAttackBowDraw_Block_Draw
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static bool Prefix(Player __instance, ItemData weapon, float dt)
			{
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (!BiomeLockPlugin.CE_SE_Block_AttackBlock.Value)
					{
						return true;
					}
					if ((Object)(object)__instance == (Object)null)
					{
						return true;
					}
					if (!ShouldBlockAtPosition(__instance, ((Component)__instance).transform.position))
					{
						return true;
					}
					((Humanoid)__instance).m_attackDrawTime = -1f;
					if (weapon != null && weapon.m_shared != null && weapon.m_shared.m_attack != null && !string.IsNullOrEmpty(weapon.m_shared.m_attack.m_drawAnimationState))
					{
						((Character)__instance).m_zanim.SetBool(weapon.m_shared.m_attack.m_drawAnimationState, false);
					}
					return false;
				}
				catch
				{
					return true;
				}
			}
		}

		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		[HarmonyPatch(typeof(SpawnSystem), "GetPlayersInZone")]
		private static class SpawnSystem_GetPlayersInZone_FilterRestrictedPlayers
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static void Postfix(List<Player> players)
			{
				//IL_003f: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (players == null || players.Count == 0)
					{
						return;
					}
					for (int num = players.Count - 1; num >= 0; num--)
					{
						Player val = players[num];
						if (!((Object)(object)val == (Object)null) && ShouldBlockAtPosition(val, ((Component)val).transform.position))
						{
							players.RemoveAt(num);
						}
					}
				}
				catch
				{
				}
			}
		}

		[HarmonyPatch(typeof(Player), "IsPlayerInRange", new Type[]
		{
			typeof(Vector3),
			typeof(float)
		})]
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		private static class Player_IsPlayerInRange_IgnoreRestrictedPlayers
		{
			private static bool Prefix(Vector3 point, float range, ref bool __result)
			{
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_0067: Unknown result type (might be due to invalid IL or missing references)
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					List<Player> allPlayers = Player.GetAllPlayers();
					if (allPlayers == null || allPlayers.Count == 0)
					{
						__result = false;
						return false;
					}
					float num = range * range;
					for (int i = 0; i < allPlayers.Count; i++)
					{
						Player val = allPlayers[i];
						if (!((Object)(object)val == (Object)null) && !ShouldBlockAtPosition(val, point))
						{
							Vector3 val2 = ((Component)val).transform.position - point;
							if (((Vector3)(ref val2)).sqrMagnitude <= num)
							{
								__result = true;
								return false;
							}
						}
					}
					__result = false;
					return false;
				}
				catch
				{
					return true;
				}
			}
		}

		[HarmonyPatch(typeof(Hud), "Update")]
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		private static class Hud_Update_Broadcast
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static void Postfix(Hud __instance)
			{
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				if (!BiomeLockPlugin.CE_SE_Broadcast_Enabled.Value)
				{
					return;
				}
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer == (Object)null || !ShouldBlockAtPosition(localPlayer, ((Component)localPlayer).transform.position))
				{
					return;
				}
				float time = Time.time;
				float num = Mathf.Max(2f, BiomeLockPlugin.CE_SE_Broadcast_Interval.Value);
				if (time < _nextBroadcastTime)
				{
					return;
				}
				_nextBroadcastTime = time + num;
				if (BroadcastTokens.Length != 0)
				{
					string text = BroadcastTokens[Random.Range(0, BroadcastTokens.Length)];
					string text2 = ((Localization.instance != null) ? Localization.instance.Localize(text) : text);
					MessageHud instance = MessageHud.instance;
					if (instance != null)
					{
						instance.ShowMessage((MessageType)2, text2, 0, (Sprite)null, false);
					}
				}
			}
		}

		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		private static class ObjectDB_Awake_RegisterSE
		{
			private static void Postfix()
			{
				try
				{
					EnsureSERegistered();
				}
				catch
				{
				}
			}
		}

		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		[HarmonyPatch(typeof(Player), "UpdateBiome")]
		private static class Player_UpdateBiome_ApplySE
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static void Postfix(Player __instance)
			{
				try
				{
					if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer))
					{
						ApplyOrRemove(__instance);
					}
				}
				catch
				{
				}
			}
		}

		[HarmonyPatch(typeof(Teleport), "Interact")]
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		private static class Teleport_Interact_BlockDungeon
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static bool Prefix(Teleport __instance, Humanoid character, bool hold, bool alt)
			{
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (!BiomeLockPlugin.CE_SE_Block_DungeonTeleport.Value)
					{
						return true;
					}
					if (hold)
					{
						return true;
					}
					Player val = (Player)(object)((character is Player) ? character : null);
					if ((Object)(object)val == (Object)null)
					{
						return true;
					}
					if (!ShouldBlockAtPosition(val, ((Component)__instance).transform.position))
					{
						return true;
					}
					string text = Localization.instance.Localize("$biomelock_dungeon_blocked");
					((Character)val).Message((MessageType)2, text, 0, (Sprite)null);
					return false;
				}
				catch
				{
					return true;
				}
			}
		}

		[HarmonyPatch(typeof(Player), "UpdatePlacement")]
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		private static class Player_UpdatePlacement_Block
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static bool Prefix(Player __instance)
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				if (!BiomeLockPlugin.CE_SE_Block_Hammer.Value)
				{
					return true;
				}
				return !ShouldBlockAtPosition(__instance, ((Component)__instance).transform.position);
			}
		}

		[HarmonyPatch(typeof(Player), "PlacePiece")]
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		private static class Player_PlacePiece_Block
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static bool Prefix(Player __instance)
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				if (!BiomeLockPlugin.CE_SE_Block_Hammer.Value)
				{
					return true;
				}
				if (!ShouldBlockAtPosition(__instance, ((Component)__instance).transform.position))
				{
					return true;
				}
				ShowHammerBlockedMessage(__instance);
				return false;
			}
		}

		[HarmonyPatch(typeof(Player), "Repair")]
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		private static class Player_Repair_Block
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static bool Prefix(Player __instance)
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				if (!BiomeLockPlugin.CE_SE_Block_Hammer.Value)
				{
					return true;
				}
				if (!ShouldBlockAtPosition(__instance, ((Component)__instance).transform.position))
				{
					return true;
				}
				ShowHammerBlockedMessage(__instance);
				return false;
			}
		}

		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		[HarmonyPatch(typeof(Player), "RemovePiece")]
		private static class Player_RemovePiece_Block
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static bool Prefix(Player __instance)
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				if (!BiomeLockPlugin.CE_SE_Block_Hammer.Value)
				{
					return true;
				}
				if (!ShouldBlockAtPosition(__instance, ((Component)__instance).transform.position))
				{
					return true;
				}
				ShowHammerBlockedMessage(__instance);
				return false;
			}
		}

		[HarmonyPatch(typeof(Hud), "TogglePieceSelection")]
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		private static class Hud_TogglePieceSelection_Block
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static bool Prefix(Hud __instance)
			{
				//IL_0032: Unknown result type (might be due to invalid IL or missing references)
				if (!BiomeLockPlugin.CE_SE_Block_Hammer.Value)
				{
					return true;
				}
				Player localPlayer = Player.m_localPlayer;
				if ((Object)(object)localPlayer == (Object)null)
				{
					return true;
				}
				if (!ShouldBlockAtPosition(localPlayer, ((Component)localPlayer).transform.position))
				{
					return true;
				}
				if ((Object)(object)__instance != (Object)null && (Object)(object)__instance.m_pieceSelectionWindow != (Object)null && __instance.m_pieceSelectionWindow.activeSelf)
				{
					return true;
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(Player), "AutoPickup")]
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		private static class Player_AutoPickup_Block
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static bool Prefix(Player __instance)
			{
				if (!BiomeLockPlugin.CE_SE_Block_AutoPickup.Value)
				{
					return true;
				}
				return !ShouldBlock(__instance);
			}
		}

		[HarmonyPatch(typeof(Humanoid), "Pickup")]
		[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(0)]
		private static class Humanoid_Pickup_Block
		{
			[<01abcb44-c760-4aa0-b992-dd354ce3dc11>NullableContext(1)]
			private static bool Prefix(Humanoid __instance)
			{
				if (!BiomeLockPlugin.CE_SE_Block_Pickup.Value)
				{
					return true;
				}
				Player val = (Player)(object)((__instance is Player) ? __instance : null);
				if ((Object)(object)val == (Object)null)
				{
					return true;
				}
				if (!ShouldBlock(val))
				{
					return true;
				}
				ShowPickupBlockedMessage(val);
				return false;
			}
		}

		[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
		[HarmonyPatch]
		private static class Interact_Implementations_Block_UserHoldAlt
		{
			[CompilerGenerated]
			private sealed class <TargetMethods>d__0 : IEnumerable<MethodBase>, IEnumerable, IEnumerator<MethodBase>, IDisposable, IEnumerator
			{
				private int <>1__state;

				private MethodBase <>2__current;

				private int <>l__initialThreadId;

				[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
				private Assembly <asm>5__1;

				[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
				private Type <interactable>5__2;

				[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(new byte[] { 0, 1 })]
				private Type[] <types>5__3;

				[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
				private ReflectionTypeLoadException <e>5__4;

				private int <i>5__5;

				[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
				private Type <t>5__6;

				[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
				private MethodInfo <m>5__7;

				[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(new byte[] { 0, 1 })]
				private ParameterInfo[] <ps>5__8;

				MethodBase IEnumerator<MethodBase>.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				object IEnumerator.Current
				{
					[DebuggerHidden]
					[return: <772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
					get
					{
						return <>2__current;
					}
				}

				[DebuggerHidden]
				public <TargetMethods>d__0(int <>1__state)
				{
					this.<>1__state = <>1__state;
					<>l__initialThreadId = Environment.CurrentManagedThreadId;
				}

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<asm>5__1 = null;
					<interactable>5__2 = null;
					<types>5__3 = null;
					<e>5__4 = null;
					<t>5__6 = null;
					<m>5__7 = null;
					<ps>5__8 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					int num = <>1__state;
					if (num != 0)
					{
						if (num != 1)
						{
							return false;
						}
						<>1__state = -1;
						<t>5__6 = null;
						<m>5__7 = null;
						<ps>5__8 = null;
						goto IL_0211;
					}
					<>1__state = -1;
					<asm>5__1 = typeof(Interactable).Assembly;
					<interactable>5__2 = typeof(Interactable);
					try
					{
						<types>5__3 = <asm>5__1.GetTypes();
					}
					catch (ReflectionTypeLoadException ex)
					{
						<e>5__4 = ex;
						<types>5__3 = <e>5__4.Types ?? Array.Empty<Type>();
					}
					<i>5__5 = 0;
					goto IL_0223;
					IL_0223:
					if (<i>5__5 < <types>5__3.Length)
					{
						<t>5__6 = <types>5__3[<i>5__5];
						if (!(<t>5__6 == null) && !<t>5__6.IsInterface && !<t>5__6.IsAbstract && <interactable>5__2.IsAssignableFrom(<t>5__6))
						{
							<m>5__7 = <t>5__6.GetMethod("Interact", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[3]
							{
								typeof(Humanoid),
								typeof(bool),
								typeof(bool)
							}, null);
							if (!(<m>5__7 == null) && <m>5__7.GetMethodBody() != null)
							{
								<ps>5__8 = <m>5__7.GetParameters();
								if (<ps>5__8.Length == 3 && string.Equals(<ps>5__8[0].Name, "user", StringComparison.Ordinal) && string.Equals(<ps>5__8[1].Name, "hold", StringComparison.Ordinal))
								{
									<>2__current = <m>5__7;
									<>1__state = 1;
									return true;
								}
							}
						}
						goto IL_0211;
					}
					return false;
					IL_0211:
					int num2 = <i>5__5 + 1;
					<i>5__5 = num2;
					goto IL_0223;
				}

				bool IEnumerator.MoveNext()
				{
					//ILSpy generated this explicit interface implementation from .override directive in MoveNext
					return this.MoveNext();
				}

				[DebuggerHidden]
				void IEnumerator.Reset()
				{
					throw new NotSupportedException();
				}

				[DebuggerHidden]
				[return: <772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
				IEnumerator<MethodBase> IEnumerable<MethodBase>.GetEnumerator()
				{
					if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
					{
						<>1__state = 0;
						return this;
					}
					return new <TargetMethods>d__0(0);
				}

				[DebuggerHidden]
				[return: <772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
				IEnumerator IEnumerable.GetEnumerator()
				{
					return ((IEnumerable<MethodBase>)this).GetEnumerator();
				}
			}

			[IteratorStateMachine(typeof(<TargetMethods>d__0))]
			private static IEnumerable<MethodBase> TargetMethods()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <TargetMethods>d__0(-2);
			}

			private static bool Prefix(object __instance, Humanoid user, bool hold, bool alt, ref bool __result)
			{
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				try
				{
					if (!BiomeLockPlugin.CE_SE_Block_GenericInteract.Value)
					{
						return true;
					}
					Player val = (Player)(object)((user is Player) ? user : null);
					if ((Object)(object)val == (Object)null)
					{
						return true;
					}
					Component val2 = (Component)((__instance is Component) ? __instance : null);
					if ((Object)(object)val2 != (Object)null)
					{
						if (IsAllowedInteractableGO(val2.gameObject))
						{
							return true;
						}
						if (!ShouldBlockAtPosition(val, val2.transform.position))
						{
							return true;
						}
					}
					else if (!ShouldBlock(val))
					{
						return true;
					}
					ShowGenericInteractBlockedMessage(val);
					__result = false;
					return false;
				}
				catch
				{
					return true;
				}
			}
		}

		[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
		[HarmonyPatch]
		private static class Interact_Implementations_Block_CharacterRepeatAlt
		{
			[CompilerGenerated]
			private sealed class <TargetMethods>d__0 : IEnumerable<MethodBase>, IEnumerable, IEnumerator<MethodBase>, IDisposable, IEnumerator
			{
				private int <>1__state;

				private MethodBase <>2__current;

				private int <>l__initialThreadId;

				[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
				private Assembly <asm>5__1;

				[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
				private Type <interactable>5__2;

				[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(new byte[] { 0, 1 })]
				private Type[] <types>5__3;

				[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
				private ReflectionTypeLoadException <e>5__4;

				private int <i>5__5;

				[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
				private Type <t>5__6;

				[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
				private MethodInfo <m>5__7;

				[<772b41c4-974b-4eba-9a88-345304c073ea>Nullable(new byte[] { 0, 1 })]
				private ParameterInfo[] <ps>5__8;

				MethodBase IEnumerator<MethodBase>.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				object IEnumerator.Current
				{
					[DebuggerHidden]
					[return: <772b41c4-974b-4eba-9a88-345304c073ea>Nullable(0)]
					get
					{
						return <>2__current;
					}
				}

				[DebuggerHidden]
				public <TargetMethods>d__0(int <>1__state)
				{
					this.<>1__state = <>1__state;
					<>l__initialThreadId = Environment.CurrentManagedThreadId;
				}

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<asm>5__1 = null;
					<interactable>5__2 = null;
					<types>5__3 = null;
					<e>5__4 = null;
					<t>5__6 = null;
					<m>5__7 = null;
					<ps>5__8 =