using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using TMPro; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+569a8b5a78374531199316528de1df5e850fb82e")] [assembly: AssemblyVersion("1.0.0.0")] public class AedenthornUtils { public static bool IgnoreKeyPresses(bool extra = false) { if (!extra) { if (!((Object)(object)ZNetScene.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && !Minimap.IsOpen() && !Console.IsVisible() && !TextInput.IsVisible() && !ZNet.instance.InPasswordDialog()) { Chat instance = Chat.instance; if (instance == null || !instance.HasFocus()) { return Menu.IsVisible(); } } return true; } if (!((Object)(object)ZNetScene.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && !Minimap.IsOpen() && !Console.IsVisible() && !TextInput.IsVisible() && !ZNet.instance.InPasswordDialog()) { Chat instance2 = Chat.instance; if ((instance2 == null || !instance2.HasFocus()) && !StoreGui.IsVisible() && !InventoryGui.IsVisible() && !Menu.IsVisible()) { TextViewer instance3 = TextViewer.instance; if (instance3 == null) { return false; } return instance3.IsVisible(); } } return true; } public static bool CheckKeyDown(string value) { try { return Input.GetKeyDown(value.ToLower()); } catch { return false; } } public static bool CheckKeyHeld(string value, bool req = true) { try { return Input.GetKey(value.ToLower()); } catch { return !req; } } } namespace LockableDoors; [BepInPlugin("aedenthorn.LockableDoors", "Lockable Doors", "0.6.3")] public class BepInExPlugin : BaseUnityPlugin { [HarmonyPatch(typeof(Player), "TryPlacePiece")] public static class Player_PlacePiece_Patch { public static void Postfix(bool __result, Piece piece, GameObject ___m_placementGhost) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) if (!modEnabled.Value || !__result || (Object)(object)piece == (Object)null || (Object)(object)___m_placementGhost == (Object)null || !AedenthornUtils.CheckKeyHeld(modKey.Value) || (Object)(object)((Component)piece).gameObject.GetComponent() == (Object)null) { return; } Vector3 position = ___m_placementGhost.transform.position; Dbgl($"LockModKey held while placing door at {position}; creating lockable door + key(s)."); Guid guid = Guid.NewGuid(); newDoors[position] = guid; if (promptNameOnCreate.Value) { Guid guid2 = guid; RenameDoor(guid2.ToString() ?? ""); } GameObject prefab = ZNetScene.instance.GetPrefab("DoorKey"); if ((Object)(object)prefab == (Object)null) { ((BaseUnityPlugin)context).Logger.LogError((object)"DoorKey prefab not found in ZNetScene; no keys spawned."); return; } Dbgl($"Spawning door key(s) amount: {duplicateKeysOnCreate.Value}"); for (int i = 0; i < duplicateKeysOnCreate.Value; i++) { ItemData itemData = Object.Instantiate(prefab, ((Component)Player.m_localPlayer).transform.position + Vector3.up, Quaternion.identity).GetComponent().m_itemData; Guid guid2 = guid; itemData.m_crafterName = guid2.ToString() ?? ""; Dbgl($"Spawned door key for door {guid} at {position}"); } } } [HarmonyPatch(typeof(ZNetScene), "Awake")] public static class ZNetScene_Awake_Patch { public static bool Prefix(ZNetScene __instance) { TryRegisterFabs(__instance); return true; } } [HarmonyPatch(typeof(ObjectDB), "Awake")] public static class ObjectDB_Awake_Patch { public static void Postfix() { RegisterItems(); } } [HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")] public static class ObjectDB_CopyOtherDB_Patch { public static void Postfix() { RegisterItems(); } } [HarmonyPatch(typeof(Door), "UpdateState")] public static class Door_UpdateState_Patch { public static void Postfix(Door __instance, ZNetView ___m_nview) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) if (modEnabled.Value && ___m_nview.IsValid() && newDoors.Count != 0 && newDoors.TryGetValue(((Component)__instance).transform.position, out var value)) { ZDO zDO = ___m_nview.GetZDO(); zDO.Set("LockedDoor", true); zDO.Set("DoorLocked", true); Guid guid = value; zDO.Set("DoorGUID", guid.ToString() ?? ""); Dbgl($"Set door {value} as lockable at {((Component)__instance).transform.position}"); newDoors.Remove(((Component)__instance).transform.position); } } } [HarmonyPatch(typeof(Door), "Interact")] public static class Door_Interact_Patch { public static bool Prefix(Door __instance, ZNetView ___m_nview, ref bool __result, Humanoid character) { //IL_02fa: Unknown result type (might be due to invalid IL or missing references) //IL_0281: Unknown result type (might be due to invalid IL or missing references) //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_02d8: Unknown result type (might be due to invalid IL or missing references) ZDO val = (((Object)(object)___m_nview == (Object)null) ? null : ___m_nview.GetZDO()); if (modEnabled.Value && val != null) { Player val2 = (Player)(object)((character is Player) ? character : null); if (val2 != null && val.GetBool("LockedDoor", false)) { string guid = val.GetString("DoorGUID", ""); bool flag = ((Humanoid)val2).GetInventory().GetAllItems().Exists((ItemData i) => i.m_crafterName == guid); Dbgl("trying to open door " + guid); if (AedenthornUtils.CheckKeyHeld(copyModKey.Value)) { __result = true; if (!flag) { ((Character)character).Message((MessageType)2, string.Format(copyNeedKeyMessage.Value, GetDoorName(guid)), 0, (Sprite)null); } else { ItemData val3 = ((Humanoid)val2).GetInventory().GetAllItems().Find(IsBlankKey); if (val3 == null) { ((Character)character).Message((MessageType)2, copyNoBlankMessage.Value, 0, (Sprite)null); } else { val3.m_crafterID = 0L; val3.m_crafterName = guid; AccessTools.Method(typeof(Inventory), "Changed", (Type[])null, (Type[])null)?.Invoke(((Humanoid)val2).GetInventory(), null); ((Character)character).Message((MessageType)2, string.Format(copiedMessage.Value, GetDoorName(guid)), 0, (Sprite)null); Dbgl("Bound blank key to door " + guid); } } return false; } if (AedenthornUtils.CheckKeyHeld(modKey.Value) && flag) { if (!___m_nview.IsOwner()) { ___m_nview.ClaimOwnership(); } val.Set("DoorLocked", !val.GetBool("DoorLocked", false)); __result = true; ((Character)character).Message((MessageType)2, string.Format(lockedMessage.Value, val.GetBool("DoorLocked", false)), 0, (Sprite)null); Dbgl(string.Format("Door locked: {0}", val.GetBool("DoorLocked", false))); return false; } if (AedenthornUtils.CheckKeyHeld(renameModKey.Value) && flag) { __result = true; RenameDoor(guid); Dbgl("Renaming door " + guid); return false; } if (val.GetBool("DoorLocked", false) && (needKeyToClose.Value || val.GetInt("state", 0) == 0)) { if (!flag) { __instance.m_lockedEffects.Create(((Component)__instance).transform.position, ((Component)__instance).transform.rotation, (Transform)null, 1f, -1); ((Character)character).Message((MessageType)2, Localization.instance.Localize("$msg_door_needkey", new string[1] { GetDoorName(guid) }), 0, (Sprite)null); __result = true; Dbgl($"player doesn't have key for {((Component)__instance).transform.position}"); return false; } Dbgl($"player has key for {((Component)__instance).transform.position}"); } return true; } } return true; } } [HarmonyPatch(typeof(Door), "HaveKey")] public static class HaveKey_Patch { public static void Postfix(Door __instance, ZNetView ___m_nview, ref bool __result, Humanoid player) { if (modEnabled.Value && __result && !((Object)(object)__instance.m_keyItem == (Object)null) && ___m_nview.GetZDO() != null && player is Player && !((player is Player) ? player : null).GetInventory().GetAllItems().Exists((ItemData i) => i.m_shared.m_name == __instance.m_keyItem.m_itemData.m_shared.m_name && (i.m_crafterID != 0L || i.m_crafterName.Length != 36))) { __result = false; Dbgl("Tried to open crypt with door key"); } } } [HarmonyPatch(typeof(Door), "GetHoverText")] public static class Door_GetHoverText_Patch { public static void Postfix(Door __instance, ref string __result, ZNetView ___m_nview) { if (modEnabled.Value && ___m_nview.GetZDO() != null && ___m_nview.GetZDO().GetBool("LockedDoor", false)) { __result = __result.Replace(Localization.instance.Localize(__instance.m_name), string.Format(doorName.Value, GetDoorName(___m_nview.GetZDO().GetString("DoorGUID", "")), ___m_nview.GetZDO().GetBool("DoorLocked", false))); } } } [HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[] { typeof(ItemData), typeof(int), typeof(bool), typeof(float), typeof(int) })] public static class GetTooltip_Patch { public static void Postfix(ItemData item, ref string __result) { if (modEnabled.Value && !string.IsNullOrEmpty(item.m_shared.m_description)) { if (IsDoorKey(item)) { __result = __result.Replace(item.m_shared.m_description, string.Format(keyDescription.Value, GetDoorName(item.m_crafterName))); } else if (IsBlankKey(item)) { __result = __result.Replace(item.m_shared.m_description, string.Format(blankKeyDescription.Value, copyModKey.Value)); } } } } [HarmonyPatch(typeof(Character), "ShowPickupMessage")] public static class ShowPickupMessage_Patch { public static bool Prefix(Character __instance, ItemData item, int amount) { if (!modEnabled.Value || !IsDoorKey(item)) { return true; } __instance.Message((MessageType)1, "$msg_added " + string.Format(keyName.Value, GetDoorName(item.m_crafterName), amount, item.GetIcon()), 0, (Sprite)null); return false; } } [HarmonyPatch(typeof(ItemDrop), "GetHoverText")] public static class ItemDrop_GetHoverText_Patch { public static void Postfix(ItemDrop __instance, ref string __result) { if (modEnabled.Value && IsDoorKey(__instance.m_itemData)) { __result = __result.Replace(Localization.instance.Localize(__instance.m_itemData.m_shared.m_name), string.Format(keyName.Value, GetDoorName(__instance.m_itemData.m_crafterName))); } } } [HarmonyPatch(typeof(InventoryGrid), "CreateItemTooltip")] public static class CreateItemTooltip_Patch { public static void Postfix(ItemData item, UITooltip tooltip) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) if (modEnabled.Value && IsDoorKey(item)) { tooltip.Set(string.Format(keyName.Value, GetDoorName(item.m_crafterName)), tooltip.m_text, (RectTransform)null, default(Vector2)); } } } [HarmonyPatch(typeof(ItemData), "GetIcon")] public static class GetIcon_Patch { public static void Postfix(ItemData __instance, ref Sprite __result) { //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) if (!modEnabled.Value || !IsDoorKey(__instance)) { return; } if ((Object)(object)icon == (Object)null) { string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), typeof(BepInExPlugin).Namespace, "icon.png"); if (!File.Exists(path)) { return; } Texture2D val = new Texture2D(2, 2); byte[] array = File.ReadAllBytes(path); MethodInfo methodInfo = AccessTools.Method(typeof(ImageConversion), "LoadImage", new Type[2] { typeof(Texture2D), typeof(byte[]) }, (Type[])null); if (methodInfo != null) { methodInfo.Invoke(null, new object[2] { val, array }); } else { AccessTools.Method(typeof(ImageConversion), "LoadImage", new Type[3] { typeof(Texture2D), typeof(byte[]), typeof(bool) }, (Type[])null)?.Invoke(null, new object[3] { val, array, false }); } icon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), Vector2.zero); } __result = icon; } } [HarmonyPatch(typeof(Terminal), "InputText")] public static class InputText_Patch { public static bool Prefix(Terminal __instance) { if (!modEnabled.Value) { return true; } string text = ((TMP_InputField)__instance.m_input).text; if (text.ToLower().Equals(typeof(BepInExPlugin).Namespace.ToLower() + " reset")) { ((BaseUnityPlugin)context).Config.Reload(); ((BaseUnityPlugin)context).Config.Save(); icon = null; LoadDoorNames(); Traverse.Create((object)__instance).Method("AddString", new object[1] { text }).GetValue(); Traverse.Create((object)__instance).Method("AddString", new object[1] { ((BaseUnityPlugin)context).Info.Metadata.Name + " config reloaded" }).GetValue(); return false; } return true; } } public static BepInExPlugin context; public static ConfigEntry modEnabled; public static ConfigEntry isDebug; public static ConfigEntry nexusID; public static ConfigEntry needKeyToClose; public static ConfigEntry modKey; public static ConfigEntry renameModKey; public static ConfigEntry copyModKey; public static ConfigEntry duplicateKeysOnCreate; public static ConfigEntry allowKeyCrafting; public static ConfigEntry keyRecipe; public static ConfigEntry keyCraftingStation; public static ConfigEntry keyStationLevel; public static ConfigEntry blankKeyName; public static ConfigEntry blankKeyDescription; public static ConfigEntry copiedMessage; public static ConfigEntry copyNeedKeyMessage; public static ConfigEntry copyNoBlankMessage; public static ConfigEntry doorName; public static ConfigEntry keyName; public static ConfigEntry keyDescription; public static ConfigEntry lockedMessage; public static ConfigEntry namePrompt; public static ConfigEntry doorNames; public static ConfigEntry defaultName; public static ConfigEntry promptNameOnCreate; public static ConfigEntry maxDoorNames; public static GameObject aedenkey; public static Dictionary newDoors = new Dictionary(); public static Dictionary doorNameDict = new Dictionary(); public static Sprite icon = null; public static void Dbgl(string str = "", bool pref = true) { if (isDebug.Value) { Debug.Log((object)((pref ? (typeof(BepInExPlugin).Namespace + " ") : "") + str)); } } public void Awake() { //IL_039e: Unknown result type (might be due to invalid IL or missing references) //IL_03a4: Expected O, but got Unknown context = this; modEnabled = ((BaseUnityPlugin)this).Config.Bind("General", "Enabled", true, "Enable this mod"); isDebug = ((BaseUnityPlugin)this).Config.Bind("General", "IsDebug", false, "Enable debug logs"); nexusID = ((BaseUnityPlugin)this).Config.Bind("General", "NexusID", 1346, "Nexus mod ID for updates"); modKey = ((BaseUnityPlugin)this).Config.Bind("Options", "LockModKey", "left ctrl", "Modifier key used to create and lock/unlock a lockable door when interacting."); renameModKey = ((BaseUnityPlugin)this).Config.Bind("Options", "RenameModKey", "left alt", "Modifier key used to rename a lockable door when interacting."); copyModKey = ((BaseUnityPlugin)this).Config.Bind("Options", "CopyModKey", "b", "Modifier key held while interacting with a locked door to bind a blank key to it (copy)."); duplicateKeysOnCreate = ((BaseUnityPlugin)this).Config.Bind("Options", "DuplicateKeysOnCreate", 1, "Amount of duplicate keys to be created per door."); keyRecipe = ((BaseUnityPlugin)this).Config.Bind("Options", "KeyRecipe", "Bronze:1", "Crafting cost for a blank key as PrefabName:amount pairs, comma-separated (e.g. Bronze:1,Wood:2)."); keyCraftingStation = ((BaseUnityPlugin)this).Config.Bind("Options", "KeyCraftingStation", "$piece_forge", "Name token of the crafting station required to craft blank keys (e.g. $piece_forge, $piece_workbench). Empty = craftable by hand."); keyStationLevel = ((BaseUnityPlugin)this).Config.Bind("Options", "KeyStationLevel", 1, "Minimum crafting station level required to craft blank keys."); doorName = ((BaseUnityPlugin)this).Config.Bind("Strings", "DoorName", "{0} Door [Locked:{1}]", "Name of door - replaces {0} with the door coordinates or name and {1} with locked status."); keyName = ((BaseUnityPlugin)this).Config.Bind("Strings", "KeyName", "{0} Door Key", "Name of key - replaces {0} with the door coordinates."); keyDescription = ((BaseUnityPlugin)this).Config.Bind("Strings", "KeyDescription", "Opens {0} Door.", "Description of key in tooltip - replaces {0} with the door name."); lockedMessage = ((BaseUnityPlugin)this).Config.Bind("Strings", "LockedMessage", "Door locked: {0}", "Message to show when locking/unlocking the door. Replaces {0} with true or false."); namePrompt = ((BaseUnityPlugin)this).Config.Bind("Strings", "NamePrompt", "Enter Name for Door:", "Prompt to show when naming a door / key pair."); defaultName = ((BaseUnityPlugin)this).Config.Bind("Strings", "DefaultName", "Locked", "Default name for a door if left blank."); blankKeyName = ((BaseUnityPlugin)this).Config.Bind("Strings", "BlankKeyName", "Blank Door Key", "Name shown for an unbound (blank) key."); blankKeyDescription = ((BaseUnityPlugin)this).Config.Bind("Strings", "BlankKeyDescription", "Hold [{0}] and interact with a locked door while carrying its key to bind this blank key.", "Tooltip for a blank key - replaces {0} with the copy modifier key."); copiedMessage = ((BaseUnityPlugin)this).Config.Bind("Strings", "CopiedMessage", "Copied key: {0}", "Message when a blank key is bound to a door. Replaces {0} with the door name."); copyNeedKeyMessage = ((BaseUnityPlugin)this).Config.Bind("Strings", "CopyNeedKeyMessage", "You need this door's key to copy it", "Message when trying to copy without the door's key."); copyNoBlankMessage = ((BaseUnityPlugin)this).Config.Bind("Strings", "CopyNoBlankMessage", "You have no blank keys to bind", "Message when trying to copy without a blank key in inventory."); needKeyToClose = ((BaseUnityPlugin)this).Config.Bind("Toggles", "NeedKeyToClose", false, "Require key in order to close a door as well as open it."); promptNameOnCreate = ((BaseUnityPlugin)this).Config.Bind("Toggles", "PromptNameOnCreate", true, "Prompt to enter a name for the door / key pair on creation."); allowKeyCrafting = ((BaseUnityPlugin)this).Config.Bind("Toggles", "AllowKeyCrafting", true, "Register a crafting recipe for blank door keys."); maxDoorNames = ((BaseUnityPlugin)this).Config.Bind("Variables", "maxDoorNames", 20, "Max door names before removing old names."); doorNames = ((BaseUnityPlugin)this).Config.Bind("ZAuto", "DoorNames", "", "List of doorName:coord pairs, populated when renaming your doors."); LoadAssets(); LoadDoorNames(); Harmony val = new Harmony("aedenthorn.LockableDoors"); int num = 0; Type[] types = Assembly.GetExecutingAssembly().GetTypes(); foreach (Type type in types) { if (type.GetCustomAttributes(typeof(HarmonyPatch), inherit: true).Length != 0) { try { val.ProcessorForAnnotatedClass(type).Patch(); } catch (Exception ex) { num++; ((BaseUnityPlugin)this).Logger.LogError((object)("Failed to apply patch " + type.Name + " (likely a game update): " + ex.Message)); } } } if (num > 0) { ((BaseUnityPlugin)this).Logger.LogWarning((object)$"LockableDoors: {num} patch class(es) failed to apply; some features may be disabled."); } } public static void TryRegisterFabs(ZNetScene zNetScene) { if (!((Object)(object)zNetScene == (Object)null) && zNetScene.m_prefabs != null && zNetScene.m_prefabs.Count > 0 && !((Object)(object)aedenkey == (Object)null) && !zNetScene.m_prefabs.Contains(aedenkey)) { zNetScene.m_prefabs.Add(aedenkey); } } public static AssetBundle GetAssetBundleFromResources(string filename) { Assembly executingAssembly = Assembly.GetExecutingAssembly(); string name = executingAssembly.GetManifestResourceNames().Single((string str) => str.EndsWith(filename)); using Stream stream = executingAssembly.GetManifestResourceStream(name); return AssetBundle.LoadFromStream(stream); } public static void LoadAssets() { AssetBundle assetBundleFromResources = GetAssetBundleFromResources("aedenkey"); aedenkey = assetBundleFromResources.LoadAsset("DoorKey"); if (assetBundleFromResources != null) { assetBundleFromResources.Unload(false); } } public static void RegisterItems() { if ((Object)(object)ObjectDB.instance == (Object)null || ObjectDB.instance.m_items.Count == 0 || (Object)(object)ObjectDB.instance.GetItemPrefab("Amber") == (Object)null) { Dbgl("Waiting for game to initialize before adding prefabs."); return; } ItemDrop val = (((Object)(object)aedenkey == (Object)null) ? null : aedenkey.GetComponent()); if ((Object)(object)val == (Object)null) { ((BaseUnityPlugin)context).Logger.LogError((object)"DoorKey prefab is missing or has no ItemDrop; cannot register item."); return; } val.m_itemData.m_shared.m_maxStackSize = 1; if (!ObjectDB.instance.m_items.Contains(aedenkey)) { Dbgl("Adding DoorKey to ObjectDB"); ObjectDB.instance.m_items.Add(aedenkey); } AddLocalizedWord("item_aeden_doorkey", blankKeyName.Value); string description = val.m_itemData.m_shared.m_description; if (!string.IsNullOrEmpty(description) && description.StartsWith("$")) { AddLocalizedWord(description.Substring(1), string.Format(blankKeyDescription.Value, copyModKey.Value)); } TryRegisterKeyRecipe(val); } public static void AddLocalizedWord(string key, string value) { try { AccessTools.Method(typeof(Localization), "AddWord", (Type[])null, (Type[])null)?.Invoke(Localization.instance, new object[2] { key, value }); } catch (Exception ex) { Dbgl("AddWord('" + key + "') failed: " + ex.Message); } } public static void TryRegisterKeyRecipe(ItemDrop keyDrop) { //IL_01c1: Unknown result type (might be due to invalid IL or missing references) //IL_01c6: Unknown result type (might be due to invalid IL or missing references) //IL_01d3: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Expected O, but got Unknown if (!allowKeyCrafting.Value || ObjectDB.instance.m_recipes.Exists((Recipe r) => (Object)(object)r != (Object)null && (Object)(object)r.m_item == (Object)(object)keyDrop)) { return; } CraftingStation val = null; string text = keyCraftingStation.Value.Trim(); if (text.Length > 0) { foreach (Recipe recipe in ObjectDB.instance.m_recipes) { if ((Object)(object)recipe != (Object)null && (Object)(object)recipe.m_craftingStation != (Object)null && recipe.m_craftingStation.m_name == text) { val = recipe.m_craftingStation; break; } } if ((Object)(object)val == (Object)null) { Dbgl("No recipe using station '" + text + "' found yet; will retry on next ObjectDB load."); return; } } List list = new List(); string[] array = keyRecipe.Value.Split(new char[1] { ',' }); foreach (string text2 in array) { string[] array2 = text2.Trim().Split(new char[1] { ':' }); if (array2.Length != 2 || !int.TryParse(array2[1].Trim(), out var result) || result < 1) { ((BaseUnityPlugin)context).Logger.LogWarning((object)("KeyRecipe entry '" + text2 + "' is not PrefabName:amount; blank key recipe not registered.")); return; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(array2[0].Trim()); if ((Object)(object)itemPrefab == (Object)null || (Object)(object)itemPrefab.GetComponent() == (Object)null) { ((BaseUnityPlugin)context).Logger.LogWarning((object)("KeyRecipe resource '" + array2[0].Trim() + "' not found in ObjectDB; blank key recipe not registered.")); return; } list.Add(new Requirement { m_resItem = itemPrefab.GetComponent(), m_amount = result }); } if (list.Count != 0) { Recipe val2 = ScriptableObject.CreateInstance(); ((Object)val2).name = "Recipe_AedenDoorKey"; val2.m_item = keyDrop; val2.m_amount = 1; val2.m_enabled = true; val2.m_craftingStation = val; val2.m_minStationLevel = keyStationLevel.Value; val2.m_resources = list.ToArray(); ObjectDB.instance.m_recipes.Add(val2); Dbgl(string.Format("Registered blank DoorKey recipe ({0} @ {1} lvl {2})", keyRecipe.Value, ((Object)(object)val == (Object)null) ? "hands" : text, keyStationLevel.Value)); } } public static void LoadDoorNames() { doorNameDict.Clear(); if (doorNames.Value.Length == 0) { return; } string[] array = doorNames.Value.Split(new char[1] { ';' }); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(new char[1] { ':' }, 2); if (array2.Length == 2 && array2[0].Length > 0) { doorNameDict[array2[0]] = array2[1]; } } } public static void SetDoorName(string guid, string text) { doorNameDict[guid] = text?.Replace(":", "").Replace(";", "") ?? ""; while (doorNameDict.Count > maxDoorNames.Value) { string text2 = null; using (Dictionary.KeyCollection.Enumerator enumerator = doorNameDict.Keys.GetEnumerator()) { if (enumerator.MoveNext()) { text2 = enumerator.Current; } } if (text2 == guid) { break; } doorNameDict.Remove(text2); } List list = new List(); foreach (KeyValuePair item in doorNameDict) { list.Add(item.Key + ":" + item.Value); } doorNames.Value = string.Join(";", list); } public static string GetDoorName(string guid) { if (!doorNameDict.TryGetValue(guid, out var value) || value.Length <= 0) { return defaultName.Value; } return value; } public static void RenameDoor(string guid) { if (!((Object)(object)TextInput.instance == (Object)null)) { MyTextReceiver myTextReceiver = new MyTextReceiver(guid); if (doorNameDict.TryGetValue(guid, out var value)) { myTextReceiver.text = value; } TextInput.instance.RequestText((TextReceiver)(object)myTextReceiver, namePrompt.Value, 255); } } public static bool IsDoorKey(ItemData i) { if (i.m_shared.m_name == "$item_aeden_doorkey" && i.m_crafterID == 0L) { return i.m_crafterName.Length == 36; } return false; } public static bool IsBlankKey(ItemData i) { if (i.m_shared.m_name == "$item_aeden_doorkey") { return !IsDoorKey(i); } return false; } } public class MyTextReceiver : TextReceiver { public string text; public string guid; public MyTextReceiver(string guid) { this.guid = guid; } public string GetText() { return text; } public void SetText(string text) { this.text = text; BepInExPlugin.SetDoorName(guid, text); } }