Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of KeyWarden v1.0.1
KeyWarden.dll
Decompiled a day agousing System; using System.Collections; 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.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.Rendering; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = "")] [assembly: AssemblyCompany("KeyWarden")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: AssemblyInformationalVersion("1.0.1+5713a14ac7b1235a3a2e3bd9ffc3eda0c889457d")] [assembly: AssemblyProduct("KeyWarden")] [assembly: AssemblyTitle("KeyWarden")] [assembly: AssemblyVersion("1.0.1.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Keychain { internal static class AzuEpiSlot { internal const string Guid = "Azumatt.AzuExtendedPlayerInventory"; private const string SlotName = "Keychain"; private static MethodInfo _isEquipmentCell; private static float _nextCheck; private static readonly FieldRef<InventoryGui, ItemData> DragItem = AccessTools.FieldRefAccess<InventoryGui, ItemData>("m_dragItem"); internal static bool Active { get; private set; } internal static void Tick() { if (!Active || _isEquipmentCell == null || Time.time < _nextCheck) { return; } _nextCheck = Time.time + 0.5f; Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)localPlayer)) { return; } InventoryGui instance = InventoryGui.instance; if (Object.op_Implicit((Object)(object)instance) && DragItem.Invoke(instance) != null) { return; } Inventory inventory = ((Humanoid)localPlayer).GetInventory(); ItemData[] array = inventory.GetAllItems().ToArray(); foreach (ItemData val in array) { if (KeychainItem.IsKeychain(val)) { bool flag; try { flag = (bool)_isEquipmentCell.Invoke(null, new object[4] { inventory, val.m_gridPos.x, val.m_gridPos.y, 0 }); } catch { break; } if (flag && !val.m_equipped) { ((Humanoid)localPlayer).EquipItem(val, false); } else if (!flag && val.m_equipped) { ((Humanoid)localPlayer).UnequipItem(val, false); } } } } internal static void TryAdd() { try { if (!Plugin.AzuSlot.Value) { Logger.LogInfo((object)"Keychain: AzuEPI slot switched off in the settings"); } else { if (!Chainloader.PluginInfos.TryGetValue("Azumatt.AzuExtendedPlayerInventory", out var value) || !Object.op_Implicit((Object)(object)value.Instance)) { return; } Assembly asm = ((object)value.Instance).GetType().Assembly; Type[] argTypes = new Type[4] { typeof(string), typeof(Func<Player, ItemData>), typeof(Func<ItemData, bool>), typeof(int) }; MethodInfo methodInfo = (from n in new string[2] { "AzuEPI.API", "AzuExtendedPlayerInventory.API" } select asm.GetType(n) into t where t != null select AccessTools.Method(t, "AddSlot", argTypes, (Type[])null)).FirstOrDefault((MethodInfo m) => m != null); if (methodInfo == null) { Logger.LogWarning((object)"Keychain: AzuEPI found but not its AddSlot; the keychain works from the bag"); return; } Func<Player, ItemData> func = delegate(Player p) { if (!Object.op_Implicit((Object)(object)p)) { return (ItemData)null; } Inventory inventory = ((Humanoid)p).GetInventory(); return (inventory == null) ? null : ((IEnumerable<ItemData>)inventory.GetAllItems()).FirstOrDefault((Func<ItemData, bool>)((ItemData i) => KeychainItem.IsKeychain(i) && i.m_equipped)); }; Func<ItemData, bool> func2 = KeychainItem.IsKeychain; Active = (bool)methodInfo.Invoke(null, new object[4] { "Keychain", func, func2, -1 }); Type type = asm.GetType("AzuEPI.API"); _isEquipmentCell = ((type == null) ? null : AccessTools.Method(type, "IsEquipmentCell", new Type[4] { typeof(Inventory), typeof(int), typeof(int), typeof(int).MakeByRefType() }, (Type[])null)); Logger.LogInfo((object)(Active ? "Keychain: added AzuEPI's Keychain slot" : "Keychain: AzuEPI refused the Keychain slot (removed in its config?)")); } } catch (Exception ex) { Logger.LogWarning((object)("Keychain: AzuEPI slot not added: " + ex.Message)); } } } internal static class KeychainCompat { internal static void Install(Harmony harmony) { Safe("Recycle_N_Reclaim check", delegate { Hook(harmony, "Recycle_N_Reclaim.GamePatches.Recycling.Reclaimer", "TryAnalyzeOneItem", null, "BlockAnalysis"); }); Safe("Recycle_N_Reclaim recycle", delegate { Hook(harmony, "Recycle_N_Reclaim.GamePatches.Recycling.Reclaimer", "DoInventoryChanges", "BlockChanges"); }); Safe("Recycle_N_Reclaim drop spot", delegate { Hook(harmony, "Recycle_N_Reclaim.GamePatches.Utils", "InventoryRecycleItem", "BlockDropSpot"); }); } internal static bool Holds(ItemData item) { if (!KeychainItem.IsKeychain(item)) { return false; } if (KeychainStore.IsBroken(item)) { return true; } if (KeychainStore.HasHidden(item)) { return true; } Inventory val = KeychainStore.Get(item); if (val != null) { return val.NrOfItems() > 0; } return item.m_customData.ContainsKey("KeyWarden.keys"); } internal static void SayEmptyFirst() { Player localPlayer = Player.m_localPlayer; if (Object.op_Implicit((Object)(object)localPlayer)) { ((Character)localPlayer).Message((MessageType)2, "$keychain_emptyfirst", 0, (Sprite)null, false); } } private static void Safe(string what, Action a) { try { a(); } catch (Exception ex) { Logger.LogWarning((object)("Keychain: " + what + " not hooked: " + ex.Message)); } } private static void Hook(Harmony h, string type, string method, string prefix = null, string postfix = null) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) Type type2 = AccessTools.TypeByName(type); MethodInfo methodInfo = ((type2 == null) ? null : AccessTools.Method(type2, method, (Type[])null, (Type[])null)); if (!(methodInfo == null)) { h.Patch((MethodBase)methodInfo, (prefix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(KeychainCompat), prefix, (Type[])null), (postfix == null) ? ((HarmonyMethod)null) : new HarmonyMethod(typeof(KeychainCompat), postfix, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Logger.LogInfo((object)("Keychain: guarding " + type + "." + method)); } } private static ItemData ItemOf(object analysisContext) { if (analysisContext != null) { object? obj = AccessTools.Field(analysisContext.GetType(), "Item")?.GetValue(analysisContext); return (ItemData)((obj is ItemData) ? obj : null); } return null; } private static void BlockAnalysis(object __0) { if (Holds(ItemOf(__0))) { Type type = __0.GetType(); ((AccessTools.Property(type, "RecyclingImpediments")?.GetValue(__0) ?? AccessTools.Field(type, "RecyclingImpediments")?.GetValue(__0)) as IList)?.Add(Localization.instance.Localize("$keychain_emptyfirst")); } } private static bool BlockChanges(object __0) { if (!Holds(ItemOf(__0))) { return true; } SayEmptyFirst(); return false; } private static bool BlockDropSpot(ItemData __0) { if (!Holds(__0)) { return true; } SayEmptyFirst(); return false; } } internal static class KeychainEquip { [HarmonyPatch(typeof(Humanoid), "EquipItem")] private static class EquipPatch { private static bool Prefix(Humanoid __instance, ItemData item, ref bool __result) { if (!KeychainItem.IsKeychain(item)) { return true; } __result = false; if (!AzuEpiSlot.Active) { item.m_equipped = false; return false; } Inventory inventory = __instance.GetInventory(); if (inventory == null || !inventory.ContainsItem(item)) { return false; } foreach (ItemData allItem in inventory.GetAllItems()) { if (allItem != item && KeychainItem.IsKeychain(allItem)) { allItem.m_equipped = false; } } item.m_equipped = true; __result = true; return false; } } [HarmonyPatch(typeof(Humanoid), "UnequipItem")] private static class UnequipPatch { private static bool Prefix(ItemData item) { if (!KeychainItem.IsKeychain(item)) { return true; } item.m_equipped = false; return false; } } [HarmonyPatch(typeof(Humanoid), "UnequipAllItems")] private static class UnequipAllPatch { private static void Postfix(Humanoid __instance) { Inventory inventory = __instance.GetInventory(); if (inventory == null) { return; } foreach (ItemData allItem in inventory.GetAllItems()) { if (KeychainItem.IsKeychain(allItem)) { allItem.m_equipped = false; } } } } [HarmonyPatch(typeof(Humanoid), "IsItemEquiped")] private static class IsEquipedPatch { private static void Postfix(Humanoid __instance, ItemData item, ref bool __result) { if (KeychainItem.IsKeychain(item)) { Inventory inventory = __instance.GetInventory(); __result = item.m_equipped && inventory != null && inventory.ContainsItem(item); } } } } internal static class KeychainIcons { private sealed class EnvBackup { private readonly AmbientMode _mode = RenderSettings.ambientMode; private readonly Color _light = RenderSettings.ambientLight; private readonly float _intensity = RenderSettings.ambientIntensity; private readonly SphericalHarmonicsL2 _probe = RenderSettings.ambientProbe; private readonly DefaultReflectionMode _reflMode = RenderSettings.defaultReflectionMode; private readonly Texture _refl = RenderSettings.customReflectionTexture; private readonly float _reflIntensity = RenderSettings.reflectionIntensity; public void Restore() { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) RenderSettings.ambientMode = _mode; RenderSettings.ambientLight = _light; RenderSettings.ambientIntensity = _intensity; RenderSettings.ambientProbe = _probe; RenderSettings.defaultReflectionMode = _reflMode; RenderSettings.customReflectionTexture = _refl; RenderSettings.reflectionIntensity = _reflIntensity; } } [HarmonyPatch(typeof(ItemData), "GetIcon")] private static class GetIconPatch { private static void Postfix(ItemData __instance, ref Sprite __result) { if (KeychainItem.IsKeychain(__instance)) { Sprite val = For(__instance); if (Object.op_Implicit((Object)(object)val)) { __result = val; } } } } private const int Big = 256; private const int Size = 64; private const int Layer = 31; private static readonly Quaternion View = Quaternion.AngleAxis(40f, Vector3.forward) * Quaternion.AngleAxis(15f, Vector3.right) * Quaternion.AngleAxis(-25f, Vector3.up); private static readonly Dictionary<string, Sprite> Cache = new Dictionary<string, Sprite>(); private static readonly HashSet<string> Failed = new HashSet<string>(); internal static float KeyLight = 1.6f; internal static float FillLight = 0.5f; internal static float RimLight = 0.8f; internal static float Ambient = 0.55f; internal static float Reflection = 0.7f; internal static float Warmth = 0.25f; private static Cubemap _greyWorld; private static float _greyWorldLevel = -1f; internal static void ClearCache() { Cache.Clear(); Failed.Clear(); } private static Cubemap GreyWorld() { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)_greyWorld) && Mathf.Approximately(_greyWorldLevel, Reflection)) { return _greyWorld; } _greyWorld = new Cubemap(8, (TextureFormat)4, false); Color[] array = (Color[])(object)new Color[64]; for (int i = 0; i < 6; i++) { float num = Reflection * i switch { 3 => 0.7f, 2 => 1.15f, _ => 1f, }; for (int j = 0; j < array.Length; j++) { array[j] = new Color(num, num, num * 1.03f, 1f); } _greyWorld.SetPixels(array, (CubemapFace)i); } _greyWorld.Apply(); _greyWorldLevel = Reflection; return _greyWorld; } internal static Sprite For(ItemData chain) { List<string> list = KeychainStore.ShownKeys(chain); if (list == null) { return null; } string text = string.Join(",", list); if (Cache.TryGetValue(text, out var value) && Object.op_Implicit((Object)(object)value)) { return value; } if (Failed.Contains(text)) { return null; } value = Render(list); if (Object.op_Implicit((Object)(object)value)) { Cache[text] = value; } else { Failed.Add(text); } return value; } private static Sprite Render(IList<string> keys) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_020a: Unknown result type (might be due to invalid IL or missing references) //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_0257: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_025e: Unknown result type (might be due to invalid IL or missing references) //IL_0272: Unknown result type (might be due to invalid IL or missing references) //IL_027c: 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_0293: Unknown result type (might be due to invalid IL or missing references) //IL_029d: Unknown result type (might be due to invalid IL or missing references) //IL_02b4: Unknown result type (might be due to invalid IL or missing references) //IL_02be: Unknown result type (might be due to invalid IL or missing references) //IL_02d5: Unknown result type (might be due to invalid IL or missing references) //IL_02df: Unknown result type (might be due to invalid IL or missing references) //IL_0308: Unknown result type (might be due to invalid IL or missing references) //IL_0364: Unknown result type (might be due to invalid IL or missing references) //IL_036b: Expected O, but got Unknown //IL_0377: Unknown result type (might be due to invalid IL or missing references) //IL_037e: Expected O, but got Unknown //IL_046b: Unknown result type (might be due to invalid IL or missing references) //IL_047a: Unknown result type (might be due to invalid IL or missing references) //IL_03e7: Unknown result type (might be due to invalid IL or missing references) //IL_03fc: Unknown result type (might be due to invalid IL or missing references) //IL_0401: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)ObjectDB.instance)) { return null; } GameObject val = new GameObject("Keychain_IconModel"); GameObject val2 = new GameObject("Keychain_IconRig"); List<(Light, int)> list = new List<(Light, int)>(); RenderTexture val3 = null; Texture2D val4 = null; EnvBackup envBackup = null; RenderTexture active = RenderTexture.active; try { GameObject val5 = new GameObject("model"); val5.transform.SetParent(val.transform, false); val5.transform.localRotation = View; KeychainLook.Build(val5.transform, keys); Bounds val6 = default(Bounds); bool flag = false; Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>(true); for (int i = 0; i < componentsInChildren.Length; i++) { ((Component)componentsInChildren[i]).gameObject.layer = 31; } Renderer[] componentsInChildren2 = val.GetComponentsInChildren<Renderer>(); foreach (Renderer val7 in componentsInChildren2) { val7.reflectionProbeUsage = (ReflectionProbeUsage)0; val7.lightProbeUsage = (LightProbeUsage)0; if (!flag) { val6 = val7.bounds; flag = true; } else { ((Bounds)(ref val6)).Encapsulate(val7.bounds); } } if (!flag) { return null; } Light[] array = Object.FindObjectsByType<Light>((FindObjectsSortMode)0); foreach (Light val8 in array) { if ((val8.cullingMask & int.MinValue) != 0) { list.Add((val8, val8.cullingMask)); val8.cullingMask &= 0x7FFFFFFF; } } Camera val9 = val2.AddComponent<Camera>(); ((Behaviour)val9).enabled = false; val9.orthographic = true; val9.orthographicSize = Mathf.Max(((Bounds)(ref val6)).size.x, ((Bounds)(ref val6)).size.y) * 0.5f * 1.06f; val9.cullingMask = int.MinValue; val9.clearFlags = (CameraClearFlags)2; val9.backgroundColor = new Color(0f, 0f, 0f, 0f); val9.nearClipPlane = 0.01f; val9.farClipPlane = 50f; ((Component)val9).transform.position = ((Bounds)(ref val6)).center + Vector3.forward * 10f; ((Component)val9).transform.rotation = Quaternion.Euler(0f, 180f, 0f); Color color = Color.Lerp(Color.white, new Color(1f, 0.92f, 0.8f), Warmth); Color color2 = Color.Lerp(Color.white, new Color(0.85f, 0.9f, 1f), Warmth); AddLight(val2, new Vector3(1f, 1.2f, 1f), KeyLight, color); AddLight(val2, new Vector3(-1.2f, 0.2f, 0.8f), FillLight, color2); AddLight(val2, new Vector3(0f, 1f, -1f), RimLight, color2); envBackup = new EnvBackup(); RenderSettings.ambientMode = (AmbientMode)3; RenderSettings.ambientLight = new Color(Ambient, Ambient, Ambient * 1.02f); RenderSettings.ambientIntensity = 1f; RenderSettings.defaultReflectionMode = (DefaultReflectionMode)1; RenderSettings.customReflectionTexture = (Texture)(object)GreyWorld(); RenderSettings.reflectionIntensity = 1f; val3 = RenderTexture.GetTemporary(256, 256, 24, (RenderTextureFormat)0); val3.antiAliasing = 1; val9.targetTexture = val3; Texture2D val10 = new Texture2D(256, 256, (TextureFormat)4, false); val4 = new Texture2D(256, 256, (TextureFormat)4, false); Shoot(val9, val3, val10, val4); if (Covered(val10, out var x, out var y, out var x2, out var y2)) { float num = 2f * val9.orthographicSize / 256f; float num2 = (float)(x + x2 + 1) * 0.5f - 128f; float num3 = (float)(y + y2 + 1) * 0.5f - 128f; Transform transform = ((Component)val9).transform; transform.position += new Vector3((0f - num2) * num, num3 * num, 0f); val9.orthographicSize = (float)Mathf.Max(x2 - x + 1, y2 - y + 1) * num * 0.5f * 1.1f; Shoot(val9, val3, val10, val4); } val9.targetTexture = null; Texture2D obj = Finish(val10); Object.Destroy((Object)(object)val10); Sprite obj2 = Sprite.Create(obj, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f)); ((Object)obj2).name = "keychain_" + keys.Count; return obj2; } catch (Exception ex) { Logger.LogWarning((object)("Keychain: icon render failed (" + ex.Message + "); keeping the plain icon")); return null; } finally { envBackup?.Restore(); if (Object.op_Implicit((Object)(object)val4)) { Object.Destroy((Object)(object)val4); } RenderTexture.active = active; if (Object.op_Implicit((Object)(object)val3)) { RenderTexture.ReleaseTemporary(val3); } foreach (var (val11, cullingMask) in list) { if (Object.op_Implicit((Object)(object)val11)) { val11.cullingMask = cullingMask; } } Object.DestroyImmediate((Object)(object)val2); Object.DestroyImmediate((Object)(object)val); } } private static void Shoot(Camera cam, RenderTexture rt, Texture2D into, Texture2D scratch) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: 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_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) RenderTexture.active = rt; cam.backgroundColor = new Color(0f, 0f, 0f, 1f); cam.Render(); into.ReadPixels(new Rect(0f, 0f, 256f, 256f), 0, 0); cam.backgroundColor = new Color(1f, 1f, 1f, 1f); cam.Render(); scratch.ReadPixels(new Rect(0f, 0f, 256f, 256f), 0, 0); Color32[] pixels = into.GetPixels32(); Color32[] pixels2 = scratch.GetPixels32(); for (int i = 0; i < pixels.Length; i++) { float num = (float)(pixels2[i].r - pixels[i].r + (pixels2[i].g - pixels[i].g) + (pixels2[i].b - pixels[i].b)) / 765f; float num2 = Mathf.Clamp01(1f - num); if (num2 < 0.01f) { pixels[i] = new Color32((byte)0, (byte)0, (byte)0, (byte)0); } else { pixels[i] = new Color32((byte)Mathf.Min(255f, (float)(int)pixels[i].r / num2), (byte)Mathf.Min(255f, (float)(int)pixels[i].g / num2), (byte)Mathf.Min(255f, (float)(int)pixels[i].b / num2), (byte)(num2 * 255f)); } } into.SetPixels32(pixels); } private static bool Covered(Texture2D tex, out int x0, out int y0, out int x1, out int y1) { Color32[] pixels = tex.GetPixels32(); x0 = (y0 = int.MaxValue); x1 = (y1 = -1); for (int i = 0; i < 256; i++) { for (int j = 0; j < 256; j++) { if (pixels[i * 256 + j].a > 8) { if (j < x0) { x0 = j; } if (j > x1) { x1 = j; } if (i < y0) { y0 = i; } if (i > y1) { y1 = i; } } } } return x1 >= 0; } private static Texture2D Finish(Texture2D big) { //IL_03f9: Unknown result type (might be due to invalid IL or missing references) //IL_03fe: Unknown result type (might be due to invalid IL or missing references) //IL_0405: Unknown result type (might be due to invalid IL or missing references) //IL_040c: Unknown result type (might be due to invalid IL or missing references) //IL_0414: Unknown result type (might be due to invalid IL or missing references) //IL_041b: Expected O, but got Unknown //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) //IL_013c: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01dd: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_03ba: Unknown result type (might be due to invalid IL or missing references) //IL_038a: Unknown result type (might be due to invalid IL or missing references) //IL_0391: Unknown result type (might be due to invalid IL or missing references) //IL_0396: Unknown result type (might be due to invalid IL or missing references) //IL_039a: Unknown result type (might be due to invalid IL or missing references) //IL_03a7: Unknown result type (might be due to invalid IL or missing references) //IL_03ac: Unknown result type (might be due to invalid IL or missing references) //IL_03b3: Unknown result type (might be due to invalid IL or missing references) //IL_03bf: Unknown result type (might be due to invalid IL or missing references) //IL_03ce: Unknown result type (might be due to invalid IL or missing references) //IL_03d0: Unknown result type (might be due to invalid IL or missing references) Color32[] pixels = big.GetPixels32(); int num = 4; Color[] array = (Color[])(object)new Color[4096]; float[] array2 = new float[4096]; Color val2 = default(Color); for (int i = 0; i < 64; i++) { for (int j = 0; j < 64; j++) { float num2 = 0f; float num3 = 0f; float num4 = 0f; float num5 = 0f; for (int k = 0; k < num; k++) { for (int l = 0; l < num; l++) { Color32 val = pixels[(i * num + k) * 256 + j * num + l]; float num6 = (float)(int)val.a / 255f; num2 += (float)(int)val.r / 255f * num6; num3 += (float)(int)val.g / 255f * num6; num4 += (float)(int)val.b / 255f * num6; num5 += num6; } } int num7 = i * 64 + j; array2[num7] = num5 / (float)(num * num); if (!(num5 <= 0f)) { ((Color)(ref val2))..ctor(num2 / num5, num3 / num5, num4 / num5); float num8 = val2.r * 0.299f + val2.g * 0.587f + val2.b * 0.114f; val2 = Color.LerpUnclamped(new Color(num8, num8, num8), val2, 1.2f); ((Color)(ref val2))..ctor((val2.r - 0.35f) * 1.12f + 0.35f, (val2.g - 0.35f) * 1.12f + 0.35f, (val2.b - 0.35f) * 1.12f + 0.35f); array[num7] = new Color(Mathf.Clamp01(val2.r), Mathf.Clamp01(val2.g), Mathf.Clamp01(val2.b)); } } } float[] array3 = new float[4096]; for (int m = 0; m < 64; m++) { for (int n = 0; n < 64; n++) { float num9 = 0f; for (int num10 = -1; num10 <= 1; num10++) { for (int num11 = -1; num11 <= 1; num11++) { int num12 = n + num11; int num13 = m + num10; if (num12 >= 0 && num13 >= 0 && num12 < 64 && num13 < 64) { num9 = Mathf.Max(num9, array2[num13 * 64 + num12]); } } } array3[m * 64 + n] = num9; } } Color[] array4 = (Color[])(object)new Color[4096]; Color val3 = default(Color); ((Color)(ref val3))..ctor(6f / 85f, 4f / 85f, 0.03137255f); for (int num14 = 0; num14 < 64; num14++) { for (int num15 = 0; num15 < 64; num15++) { float num16 = 0f; float num17 = 0f; for (int num18 = -1; num18 <= 1; num18++) { for (int num19 = -1; num19 <= 1; num19++) { int num20 = num15 + num19; int num21 = num14 + num18; if (num20 >= 0 && num21 >= 0 && num20 < 64 && num21 < 64) { float num22 = ((num19 != 0) ? 1 : 2) * ((num18 != 0) ? 1 : 2); num16 += array3[num21 * 64 + num20] * num22; num17 += num22; } } } int num23 = num14 * 64 + num15; float num24 = num16 / num17 * 0.75f; float num25 = array2[num23]; float num26 = num25 + num24 * (1f - num25); Color val4 = ((num26 <= 0f) ? Color.clear : ((array[num23] * num25 + val3 * num24 * (1f - num25)) / num26)); val4.a = num26; array4[num23] = val4; } } Texture2D val5 = new Texture2D(64, 64, (TextureFormat)4, false) { filterMode = (FilterMode)1, wrapMode = (TextureWrapMode)1 }; val5.SetPixels(array4); val5.Apply(); return val5; } private static void AddLight(GameObject rig, Vector3 from, float intensity, Color color) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_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_004c: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject("light"); val.transform.SetParent(rig.transform, false); val.transform.rotation = Quaternion.LookRotation(-((Vector3)(ref from)).normalized); Light obj = val.AddComponent<Light>(); obj.type = (LightType)1; obj.intensity = intensity; obj.color = color; obj.cullingMask = int.MinValue; obj.shadows = (LightShadows)0; } } internal static class KeychainItem { internal const string Prefab = "KW_Keychain"; internal const string Token = "$item_kw_keychain"; private const string BasePrefab = "SilverNecklace"; private static HashSet<string> _keyNames; private static ObjectDB _builtFor; private static string _builtFrom; internal static HashSet<string> KeyNames { get { ObjectDB instance = ObjectDB.instance; string text = Plugin.Keys.Value + "|" + Plugin.AnyKey.Value + "|" + (Object.op_Implicit((Object)(object)ZNetScene.instance) ? ((Object)ZNetScene.instance).GetInstanceID() : 0); if (_keyNames != null && (Object)(object)_builtFor == (Object)(object)instance && _builtFrom == text) { return _keyNames; } HashSet<string> hashSet = new HashSet<string>(); if (Object.op_Implicit((Object)(object)instance)) { string[] array = Plugin.Keys.Value.Split(','); foreach (string text2 in array) { GameObject itemPrefab = instance.GetItemPrefab(text2.Trim()); ItemDrop val = (Object.op_Implicit((Object)(object)itemPrefab) ? itemPrefab.GetComponent<ItemDrop>() : null); if (Object.op_Implicit((Object)(object)val)) { hashSet.Add(val.m_itemData.m_shared.m_name); } } if (Plugin.AnyKey.Value && Object.op_Implicit((Object)(object)ZNetScene.instance)) { foreach (GameObject prefab in ZNetScene.instance.m_prefabs) { if (!Object.op_Implicit((Object)(object)prefab)) { continue; } Door[] componentsInChildren = prefab.GetComponentsInChildren<Door>(true); foreach (Door val2 in componentsInChildren) { if (Object.op_Implicit((Object)(object)val2.m_keyItem)) { hashSet.Add(val2.m_keyItem.m_itemData.m_shared.m_name); } } } } _builtFor = instance; _builtFrom = text; _keyNames = hashSet; } return hashSet; } } internal static bool IsKeychain(ItemData item) { if (item != null && item.m_shared != null) { return item.m_shared.m_name == "$item_kw_keychain"; } return false; } internal static void Register() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Expected O, but got Unknown //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown //IL_00ae: Unknown result type (might be due to invalid IL or missing references) PrefabManager.OnVanillaPrefabsAvailable -= Register; ItemConfig val = new ItemConfig { Name = "$item_kw_keychain", Description = "$item_kw_keychain_description", CraftingStation = Plugin.Station.Value, MinStationLevel = Plugin.StationLevel.Value, Requirements = ParseRecipe(Plugin.Recipe.Value) }; CustomItem val2 = new CustomItem("KW_Keychain", "SilverNecklace", val); if ((Object)(object)val2.ItemPrefab == (Object)null) { Logger.LogError((object)"Keychain: could not clone SilverNecklace"); return; } SharedData shared = val2.ItemDrop.m_itemData.m_shared; shared.m_itemType = (ItemType)16; shared.m_maxStackSize = 1; shared.m_maxQuality = 1; shared.m_weight = 0.5f; shared.m_value = 0; shared.m_teleportable = true; ItemManager.Instance.AddItem(val2); try { KeychainLook.SetUpPrefab(val2.ItemPrefab); } catch (Exception ex) { Logger.LogWarning((object)("Keychain: ring model not set up (" + ex.Message + ")")); } } private static RequirementConfig[] ParseRecipe(string text) { //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Expected O, but got Unknown //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown List<RequirementConfig> list = new List<RequirementConfig>(); string[] array = (text ?? "").Split(','); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(':'); if (array2.Length == 2 && int.TryParse(array2[1].Trim(), out var result) && result > 0) { list.Add(new RequirementConfig(array2[0].Trim(), result, 0, true)); } } if (list.Count == 0) { list.Add(new RequirementConfig("LeatherScraps", 4, 0, true)); } return list.ToArray(); } internal static bool IsKey(ItemData item) { if (item?.m_shared != null) { return KeyNames.Contains(item.m_shared.m_name); } return false; } internal static bool IsKeyName(string name) { if (name != null) { return KeyNames.Contains(name); } return false; } } internal static class KeychainLook { private struct Hang { public Vector3 Point; public Vector3 Up; public Vector3 Normal; public float Length; public Hang(Vector3 point, Vector3 up, Vector3 normal, float length) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) Point = point; Up = up; Normal = normal; Length = length; } } [HarmonyPatch(typeof(ItemDrop), "Start")] private static class DroppedPatch { private static void Postfix(ItemDrop __instance) { if (!KeychainItem.IsKeychain(__instance.m_itemData)) { return; } List<string> list = KeychainStore.ShownKeys(__instance.m_itemData); if (list == null || list.Count == 0) { return; } Transform[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Transform>(true); foreach (Transform val in componentsInChildren) { if (((Object)val).name == "keychain_model") { Rebuild(val, list); break; } } } } internal const int MaxShown = 5; private static readonly Dictionary<string, Hang> Known = new Dictionary<string, Hang> { { "CryptKey", new Hang(new Vector3(-0.0147f, 0.02f, 0.3763f), new Vector3(0.0231f, 0f, 0.9997f), new Vector3(0f, -1f, 0f), 0.836f) }, { "HildirKey_forestcrypt", new Hang(new Vector3(0.0027f, 0f, -0.2629f), new Vector3(0.0845f, 0f, -0.9964f), new Vector3(0f, 1f, 0f), 0.506f) }, { "HildirKey_mountaincave", new Hang(new Vector3(0.0027f, 0f, -0.2629f), new Vector3(0.0845f, 0f, -0.9964f), new Vector3(0f, 1f, 0f), 0.506f) }, { "HildirKey_plainsfortress", new Hang(new Vector3(0.0027f, 0f, -0.2629f), new Vector3(0.0845f, 0f, -0.9964f), new Vector3(0f, 1f, 0f), 0.506f) }, { "BloodGoldKey", new Hang(new Vector3(-0.0052f, -0.0004f, 0.2486f), new Vector3(0.0096f, -0.0006f, 1f), new Vector3(0.0004f, -1f, -0.0007f), 0.602f) }, { "BOM_EikthyrKey", new Hang(new Vector3(-0.0147f, 0.03f, 0.3763f), new Vector3(0.0231f, 0f, 0.9997f), new Vector3(0f, -1f, 0f), 0.836f) }, { "BOM_BonemassKey", new Hang(new Vector3(-0.0147f, 0.03f, 0.3763f), new Vector3(0.0231f, 0f, 0.9997f), new Vector3(0f, -1f, 0f), 0.836f) }, { "BOM_CrystalKey", new Hang(new Vector3(-0.0147f, 0.03f, 0.3763f), new Vector3(0.0231f, 0f, 0.9997f), new Vector3(0f, -1f, 0f), 0.836f) }, { "BOM_LavaKey", new Hang(new Vector3(-0.0147f, 0.03f, 0.3763f), new Vector3(0.0231f, 0f, 0.9997f), new Vector3(0f, -1f, 0f), 0.836f) } }; internal const string ModelNode = "keychain_model"; private static readonly Dictionary<long, Mesh> Tori = new Dictionary<long, Mesh>(); private static Material _ringMat; internal static void Build(Transform parent, IList<string> keyPrefabs) { //IL_0100: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Unknown result type (might be due to invalid IL or missing references) //IL_0222: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_0233: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_0248: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_0254: Unknown result type (might be due to invalid IL or missing references) //IL_0259: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_0269: Expected O, but got Unknown //IL_027e: 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_028e: Unknown result type (might be due to invalid IL or missing references) //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_0297: Unknown result type (might be due to invalid IL or missing references) //IL_029c: Unknown result type (might be due to invalid IL or missing references) List<(GameObject, Hang)> list = new List<(GameObject, Hang)>(); if (Object.op_Implicit((Object)(object)ObjectDB.instance) && keyPrefabs != null) { foreach (string keyPrefab in keyPrefabs) { if (list.Count >= 5) { break; } GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(keyPrefab); if (Object.op_Implicit((Object)(object)itemPrefab)) { list.Add((itemPrefab, Known.TryGetValue(keyPrefab, out var value) ? value : Guess(itemPrefab))); } } } float num = 0.6f; foreach (var item3 in list) { num = Mathf.Max(num, item3.Item2.Length); } float num2 = 0.3f * num; float r = 0.025f * num; float num3 = ((list.Count == 0) ? 25f : 58f); Quaternion val = Quaternion.Euler(0f, num3, 0f); Vector3 val2 = default(Vector3); ((Vector3)(ref val2))..ctor(0f, num2, 0f); GameObject val3 = new GameObject("ring"); val3.transform.SetParent(parent, false); val3.transform.localPosition = val2; val3.transform.localRotation = val; val3.AddComponent<MeshFilter>().sharedMesh = Torus(num2, r); ((Renderer)val3.AddComponent<MeshRenderer>()).sharedMaterial = RingMaterial(); int count = list.Count; float num4 = ((count <= 1) ? 0f : (count switch { 4 => 42f, 3 => 28f, 2 => 18f, _ => 54f, })) * ((float)Math.PI / 180f); for (int i = 0; i < count; i++) { (GameObject, Hang) tuple = list[i]; GameObject item = tuple.Item1; Hang item2 = tuple.Item2; float num5 = ((count == 1) ? 0f : (0f - num4 + 2f * num4 * (float)i / (float)(count - 1))); Vector3 val4 = val * new Vector3(num2 * Mathf.Sin(num5), (0f - num2) * Mathf.Cos(num5), 0f) + val2; Quaternion val5 = Quaternion.Inverse(Quaternion.LookRotation(item2.Normal, item2.Up)); Quaternion val6 = Quaternion.AngleAxis(num5 * 0.6f * 57.29578f, Vector3.forward) * val5; GameObject val7 = new GameObject(((Object)item).name); val7.transform.SetParent(parent, false); val7.transform.localRotation = val6; val7.transform.localPosition = val4 - val6 * item2.Point; CopyMeshes(item, val7.transform); } } private static void CopyMeshes(GameObject prefab, Transform target) { //IL_005c: 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) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0094: 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_00a3: 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) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) Transform transform = prefab.transform; MeshRenderer[] componentsInChildren = prefab.GetComponentsInChildren<MeshRenderer>(true); foreach (MeshRenderer val in componentsInChildren) { if (ActiveInPrefab(((Component)val).transform, transform) && ((Renderer)val).enabled) { MeshFilter component = ((Component)val).GetComponent<MeshFilter>(); if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.sharedMesh)) { Matrix4x4 val2 = transform.worldToLocalMatrix * ((Component)val).transform.localToWorldMatrix; GameObject val3 = new GameObject(((Object)val).name); val3.transform.SetParent(target, false); val3.transform.localPosition = Vector4.op_Implicit(((Matrix4x4)(ref val2)).GetColumn(3)); val3.transform.localRotation = ((Matrix4x4)(ref val2)).rotation; val3.transform.localScale = ((Matrix4x4)(ref val2)).lossyScale; val3.AddComponent<MeshFilter>().sharedMesh = component.sharedMesh; ((Renderer)val3.AddComponent<MeshRenderer>()).sharedMaterials = ((Renderer)val).sharedMaterials; } } } } private static bool ActiveInPrefab(Transform t, Transform root) { while (Object.op_Implicit((Object)(object)t) && (Object)(object)t != (Object)(object)root) { if (!((Component)t).gameObject.activeSelf) { return false; } t = t.parent; } return true; } private static Hang Guess(GameObject prefab) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_0186: Unknown result type (might be due to invalid IL or missing references) //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_017e: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) //IL_01d7: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_01ff: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: 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_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00df: Unknown result type (might be due to invalid IL or missing references) Transform transform = prefab.transform; bool flag = false; Bounds val = default(Bounds); MeshRenderer[] componentsInChildren = prefab.GetComponentsInChildren<MeshRenderer>(true); foreach (MeshRenderer val2 in componentsInChildren) { MeshFilter component = ((Component)val2).GetComponent<MeshFilter>(); if (!Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component.sharedMesh) || !ActiveInPrefab(((Component)val2).transform, transform)) { continue; } Matrix4x4 val3 = transform.worldToLocalMatrix * ((Component)val2).transform.localToWorldMatrix; Bounds bounds = component.sharedMesh.bounds; for (int j = 0; j < 8; j++) { Vector3 val4 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1)))); Vector3 val5 = ((Matrix4x4)(ref val3)).MultiplyPoint3x4(val4); if (!flag) { ((Bounds)(ref val))..ctor(val5, Vector3.zero); flag = true; } else { ((Bounds)(ref val)).Encapsulate(val5); } } } if (!flag) { return new Hang(Vector3.zero, Vector3.up, Vector3.forward, 0.6f); } Vector3 size = ((Bounds)(ref val)).size; int num = ((!(size.x >= size.y) || !(size.x >= size.z)) ? ((size.y >= size.z) ? 1 : 2) : 0); int num2 = ((!(size.x <= size.y) || !(size.x <= size.z)) ? ((size.y <= size.z) ? 1 : 2) : 0); if (num2 == num) { num2 = (num + 1) % 3; } Vector3 zero = Vector3.zero; ((Vector3)(ref zero))[num] = 1f; Vector3 zero2 = Vector3.zero; ((Vector3)(ref zero2))[num2] = 1f; return new Hang(((Bounds)(ref val)).center + zero * (((Vector3)(ref size))[num] * 0.5f * 0.85f), zero, zero2, ((Vector3)(ref size))[num]); } internal static void SetUpPrefab(GameObject prefab) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { if (val is MeshRenderer || val is SkinnedMeshRenderer) { Object.DestroyImmediate((Object)(object)val); } } Transform val2 = prefab.transform.Find("attach") ?? prefab.transform; GameObject val3 = new GameObject("keychain_model"); val3.transform.SetParent(val2, false); val3.transform.localRotation = Quaternion.Euler(90f, 0f, 0f); val3.transform.localPosition = new Vector3(0f, 0.03f, 0.12f); Build(val3.transform, null); } private static void Rebuild(Transform model, IList<string> keys) { for (int num = model.childCount - 1; num >= 0; num--) { Object.Destroy((Object)(object)((Component)model.GetChild(num)).gameObject); } Build(model, keys); } private static Material RingMaterial() { //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Expected O, but got Unknown if (Object.op_Implicit((Object)(object)_ringMat)) { return _ringMat; } string[] array = new string[2] { "Tin", "SilverNecklace" }; foreach (string text in array) { GameObject val = (Object.op_Implicit((Object)(object)ObjectDB.instance) ? ObjectDB.instance.GetItemPrefab(text) : null) ?? Cache.GetPrefab<GameObject>(text); MeshRenderer val2 = (Object.op_Implicit((Object)(object)val) ? val.GetComponentInChildren<MeshRenderer>(true) : null); if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)((Renderer)val2).sharedMaterial)) { return _ringMat = ((Renderer)val2).sharedMaterial; } } return new Material(Shader.Find("Standard")) { color = new Color(0.765f, 0.765f, 0.765f) }; } private static Mesh Torus(float R, float r) { //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //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_01d1: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01df: Unknown result type (might be due to invalid IL or missing references) //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Expected O, but got Unknown long key = (long)Math.Round(R * 10000f) * 100000 + (long)Math.Round(r * 10000f); if (Tori.TryGetValue(key, out var value) && Object.op_Implicit((Object)(object)value)) { return value; } Vector3[] array = (Vector3[])(object)new Vector3[637]; Vector3[] array2 = (Vector3[])(object)new Vector3[array.Length]; Vector2[] array3 = (Vector2[])(object)new Vector2[array.Length]; Vector3 val = default(Vector3); for (int i = 0; i <= 48; i++) { float num = (float)i / 48f * (float)Math.PI * 2f; ((Vector3)(ref val))..ctor(Mathf.Cos(num), Mathf.Sin(num), 0f); for (int j = 0; j <= 12; j++) { float num2 = (float)j / 12f * (float)Math.PI * 2f; Vector3 val2 = val * Mathf.Cos(num2) + Vector3.forward * Mathf.Sin(num2); int num3 = i * 13 + j; array[num3] = val * R + val2 * r; array2[num3] = val2; array3[num3] = new Vector2((float)i / 48f * 4f, (float)j / 12f); } } List<int> list = new List<int>(3456); for (int k = 0; k < 48; k++) { for (int l = 0; l < 12; l++) { int num4 = k * 13 + l; int num5 = num4 + 12 + 1; list.AddRange(new int[6] { num4, num5, num4 + 1, num5, num5 + 1, num4 + 1 }); } } Mesh val3 = new Mesh { name = "keychain_ring", vertices = array, normals = array2, uv = array3, triangles = list.ToArray() }; val3.RecalculateBounds(); val3.RecalculateTangents(); return Tori[key] = val3; } } internal static class KeychainPickup { [HarmonyPatch(typeof(Humanoid), "Pickup")] private static class PickupPatch { private static void Postfix(Humanoid __instance, bool __result, GameObject go) { if (!__result || !Plugin.KeysToChain.Value) { return; } Player val = (Player)(object)((__instance is Player) ? __instance : null); if (Object.op_Implicit((Object)(object)val) && !((Object)(object)val != (Object)(object)Player.m_localPlayer) && Object.op_Implicit((Object)(object)go)) { ItemDrop component = go.GetComponent<ItemDrop>(); if (Object.op_Implicit((Object)(object)component) && KeychainItem.IsKey(component.m_itemData)) { MoveOntoChain(val, component.m_itemData.m_shared.m_name); } } } } internal static void MoveOntoChain(Player me, string keyName) { Inventory inventory = ((Humanoid)me).GetInventory(); List<ItemData> list = (from c in inventory.GetAllItems().Where(KeychainItem.IsKeychain) where !KeychainStore.IsBroken(c) orderby c.m_equipped descending select c).ToList(); if (list.Count == 0) { return; } Inventory val = KeychainStore.Get(list[0]); if (val != null) { ItemData[] array = (from i in inventory.GetAllItems() where i.m_shared.m_name == keyName && !KeychainItem.IsKeychain(i) select i).ToArray(); foreach (ItemData val2 in array) { val.MoveItemToThis(inventory, val2); } } } } internal static class KeychainSplit { internal struct Span { public int Version; public int Hash; public byte[] Bytes; } internal static readonly int CurrentVersion = 110; internal static List<Span> ReadItems(ZPackage pkg, out int version) { version = pkg.ReadInt(); if (version < 108) { throw new InvalidDataException("old keychain format " + version); } int num = pkg.ReadUShort(); byte[] array = pkg.GetArray(); List<Span> list = new List<Span>(num); for (int i = 0; i < num; i++) { int pos = pkg.GetPos(); int item = ItemData.Load(pkg, (Item)version).Item1; int pos2 = pkg.GetPos(); if (item != 0) { byte[] array2 = new byte[pos2 - pos]; Array.Copy(array, pos, array2, 0, array2.Length); list.Add(new Span { Version = version, Hash = item, Bytes = array2 }); } } return list; } internal static ZPackage Build(int version, List<Span> items) { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Expected O, but got Unknown using MemoryStream memoryStream = new MemoryStream(); using BinaryWriter binaryWriter = new BinaryWriter(memoryStream); binaryWriter.Write(version); binaryWriter.Write((ushort)items.Count); foreach (Span item in items) { binaryWriter.Write(item.Bytes); } binaryWriter.Flush(); return new ZPackage(memoryStream.ToArray()); } internal static ZPackage WriteHidden(List<Span> items) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown ZPackage val = new ZPackage(); val.Write(items.Count); foreach (Span item in items) { val.Write(item.Version); val.Write(item.Hash); val.Write(item.Bytes); } return val; } internal static List<Span> ReadHidden(ZPackage pkg) { int num = pkg.ReadInt(); List<Span> list = new List<Span>(num); for (int i = 0; i < num; i++) { int version = pkg.ReadInt(); int hash = pkg.ReadInt(); list.Add(new Span { Version = version, Hash = hash, Bytes = pkg.ReadByteArray() }); } return list; } } internal static class KeychainStore { private sealed class Box { public Inventory Inv; public bool Broken; public List<KeychainSplit.Span> Hidden = new List<KeychainSplit.Span>(); public List<string> Shown; } internal const string DataKey = "KeyWarden.keys"; internal const string HiddenKey = "KeyWarden.hidden"; private static readonly ConditionalWeakTable<ItemData, Box> ByItem = new ConditionalWeakTable<ItemData, Box>(); private static readonly ConditionalWeakTable<Inventory, ItemData> Owner = new ConditionalWeakTable<Inventory, ItemData>(); private static readonly Action<Inventory> UpdateTotalWeight = AccessTools.MethodDelegate<Action<Inventory>>(AccessTools.Method(typeof(Inventory), "UpdateTotalWeight", (Type[])null, (Type[])null), (object)null, true); private const int Cols = 8; private static readonly FieldRef<Inventory, int> Width = AccessTools.FieldRefAccess<Inventory, int>("m_width"); private static readonly FieldRef<Inventory, int> Height = AccessTools.FieldRefAccess<Inventory, int>("m_height"); internal static List<string> ShownKeys(ItemData chain) { if (Get(chain) == null || !ByItem.TryGetValue(chain, out var value)) { return null; } if (value.Shown != null) { return value.Shown; } List<ItemData> list = new List<ItemData>(value.Inv.GetAllItems()); list.Sort((ItemData a, ItemData b) => (a.m_gridPos.y * 100 + a.m_gridPos.x).CompareTo(b.m_gridPos.y * 100 + b.m_gridPos.x)); List<string> list2 = new List<string>(); Dictionary<string, int> dictionary = new Dictionary<string, int>(); foreach (ItemData item in list) { if (Object.op_Implicit((Object)(object)item.m_dropPrefab)) { string name = ((Object)item.m_dropPrefab).name; if (!dictionary.ContainsKey(name)) { list2.Add(name); dictionary[name] = 0; } dictionary[name] += Math.Max(1, item.m_stack); } } Dictionary<string, int> dictionary2 = new Dictionary<string, int>(); int num = 5; foreach (string item2 in list2) { if (num == 0) { break; } dictionary2[item2] = 1; num--; } bool flag = true; while (num > 0 && flag) { flag = false; foreach (string item3 in list2) { if (num == 0) { break; } if (dictionary2.TryGetValue(item3, out var value2) && value2 < dictionary[item3]) { dictionary2[item3] = value2 + 1; num--; flag = true; } } } List<string> list3 = new List<string>(); foreach (string item4 in list2) { if (dictionary2.TryGetValue(item4, out var value3)) { for (int num2 = 0; num2 < value3; num2++) { list3.Add(item4); } } } return value.Shown = list3; } internal static bool IsChainInventory(Inventory inv) { ItemData value; if (inv != null) { return Owner.TryGetValue(inv, out value); } return false; } internal static bool IsBroken(ItemData chain) { if (ByItem.TryGetValue(chain, out var value)) { return value.Broken; } return false; } internal static bool HasHidden(ItemData chain) { if (!ByItem.TryGetValue(chain, out var value)) { return chain.m_customData.ContainsKey("KeyWarden.hidden"); } return value.Hidden.Count > 0; } internal static Inventory Get(ItemData chain) { //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Expected O, but got Unknown //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Expected O, but got Unknown //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Expected O, but got Unknown if (chain == null) { return null; } if (ByItem.TryGetValue(chain, out var box)) { return box.Inv; } if (!Object.op_Implicit((Object)(object)ObjectDB.instance) || ObjectDB.instance.m_items.Count == 0) { return null; } chain.m_customData.TryGetValue("KeyWarden.keys", out var value); chain.m_customData.TryGetValue("KeyWarden.hidden", out var value2); Inventory inv = new Inventory("$item_kw_keychain", (Sprite)null, 8, 64); box = new Box { Inv = inv }; if (!string.IsNullOrEmpty(value) || !string.IsNullOrEmpty(value2)) { try { int version = KeychainSplit.CurrentVersion; List<KeychainSplit.Span> list = new List<KeychainSplit.Span>(); if (!string.IsNullOrEmpty(value)) { list.AddRange(KeychainSplit.ReadItems(new ZPackage(value), out version)); } List<KeychainSplit.Span> source = (string.IsNullOrEmpty(value2) ? new List<KeychainSplit.Span>() : KeychainSplit.ReadHidden(new ZPackage(value2))); List<KeychainSplit.Span> list2 = new List<KeychainSplit.Span>(); GameObject val = default(GameObject); foreach (KeychainSplit.Span item in list.Concat(source.Where((KeychainSplit.Span a) => a.Version == version))) { if (ObjectDB.instance.TryGetItemPrefab(item.Hash, ref val)) { list2.Add(item); } else { box.Hidden.Add(item); } } box.Hidden.AddRange(source.Where((KeychainSplit.Span a) => a.Version != version)); inv.Load(KeychainSplit.Build(version, list2)); if (inv.NrOfItems() < list2.Count) { box.Broken = true; } } catch (Exception ex) { box.Broken = true; Logger.LogWarning((object)("Keychain: could not read a keychain's keys (" + ex.Message + "); left untouched")); } } Fit(inv); Inventory obj = inv; obj.m_onChanged = (Action)Delegate.Combine(obj.m_onChanged, (Action)delegate { Grow(inv); Save(chain, box); }); ByItem.Add(chain, box); Owner.Add(inv, chain); return inv; } internal static bool Fit(Inventory inv) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) List<ItemData> allItems = inv.GetAllItems(); int num = allItems.Count + 1; int num2 = Math.Min(num, 8); int num3 = (num + num2 - 1) / num2; bool flag = true; for (int i = 0; i < allItems.Count && flag; i++) { Vector2i gridPos = allItems[i].m_gridPos; flag = gridPos.x < num2 && gridPos.y * num2 + gridPos.x < allItems.Count; } if (flag && Width.Invoke(inv) == num2 && Height.Invoke(inv) == num3) { return false; } Width.Invoke(inv) = num2; Height.Invoke(inv) = num3; allItems.Sort((ItemData a, ItemData b) => (a.m_gridPos.y == b.m_gridPos.y) ? a.m_gridPos.x.CompareTo(b.m_gridPos.x) : a.m_gridPos.y.CompareTo(b.m_gridPos.y)); for (int num4 = 0; num4 < allItems.Count; num4++) { allItems[num4].m_gridPos = new Vector2i(num4 % num2, num4 / num2); } return true; } private static void Grow(Inventory inv) { int num = inv.GetAllItems().Count + 1; if (num > Width.Invoke(inv) * Height.Invoke(inv)) { int num2 = Math.Max(Width.Invoke(inv), Math.Min(num, 8)); int num3 = Math.Max(Height.Invoke(inv), (num + num2 - 1) / num2); Width.Invoke(inv) = num2; Height.Invoke(inv) = num3; } } internal static void FitAndSave(ItemData chain) { if (ByItem.TryGetValue(chain, out var value) && !value.Broken && Fit(value.Inv)) { value.Shown = null; Save(chain, value); } } private static void Save(ItemData chain, Box box) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown box.Shown = null; if (!box.Broken) { ZPackage val = new ZPackage(); box.Inv.Save(val); chain.m_customData["KeyWarden.keys"] = val.GetBase64(); if (box.Hidden.Count > 0) { chain.m_customData["KeyWarden.hidden"] = KeychainSplit.WriteHidden(box.Hidden).GetBase64(); } else { chain.m_customData.Remove("KeyWarden.hidden"); } Player localPlayer = Player.m_localPlayer; if (Object.op_Implicit((Object)(object)localPlayer) && ((Humanoid)localPlayer).GetInventory().ContainsItem(chain)) { UpdateTotalWeight(((Humanoid)localPlayer).GetInventory()); } } } } internal static class KeychainWindow { [HarmonyPatch(typeof(Container), "IsOwner")] private static class IsOwnerPatch { private static bool Prefix(Container __instance, ref bool __result) { if (!IsOurs(__instance)) { return true; } __result = true; return false; } } [HarmonyPatch(typeof(Container), "SetInUse")] private static class SetInUsePatch { private static bool Prefix(Container __instance) { return !IsOurs(__instance); } } [HarmonyPatch(typeof(Container), "StackAll")] private static class StackAllPatch { private static bool Prefix(Container __instance) { return !IsOurs(__instance); } } [HarmonyPatch(typeof(Humanoid), "UseItem")] private static class UseItemPatch { private static bool Prefix(Humanoid __instance, Inventory inventory, ItemData item) { if (!KeychainItem.IsKeychain(item)) { return true; } Player val = (Player)(object)((__instance is Player) ? __instance : null); if (!Object.op_Implicit((Object)(object)val) || (Object)(object)val != (Object)(object)Player.m_localPlayer) { return true; } Inventory inventory2 = ((Humanoid)val).GetInventory(); if ((inventory ?? inventory2) != inventory2 || !inventory2.ContainsItem(item)) { return true; } InventoryGui instance = InventoryGui.instance; if (Object.op_Implicit((Object)(object)instance) && _open == item && Object.op_Implicit((Object)(object)_box) && (Object)(object)CurrentContainer.Invoke(instance) == (Object)(object)_box) { AccessTools.Method(typeof(InventoryGui), "CloseContainer", (Type[])null, (Type[])null).Invoke(instance, null); _open = null; return false; } Open(val, item); return false; } } private static Container _box; private static ItemData _open; private static readonly FieldRef<Container, Inventory> BoxInventory = AccessTools.FieldRefAccess<Container, Inventory>("m_inventory"); private static readonly FieldRef<InventoryGui, Container> CurrentContainer = AccessTools.FieldRefAccess<InventoryGui, Container>("m_currentContainer"); private static readonly FieldRef<InventoryGui, ItemData> DragItem = AccessTools.FieldRefAccess<InventoryGui, ItemData>("m_dragItem"); internal static bool IsOurs(Container c) { if ((Object)(object)c != (Object)null) { return (Object)(object)c == (Object)(object)_box; } return false; } internal static void Open(Player me, ItemData chain) { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) InventoryGui instance = InventoryGui.instance; if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)me)) { return; } Inventory val = KeychainStore.Get(chain); if (val == null) { return; } if (KeychainStore.IsBroken(chain)) { ((Character)me).Message((MessageType)2, "$keychain_unreadable", 0, (Sprite)null, false); return; } if (!Object.op_Implicit((Object)(object)_box)) { GameObject val2 = new GameObject("Keychain_Panel"); val2.SetActive(false); _box = val2.AddComponent<Container>(); } ((Component)_box).transform.SetParent(((Component)me).transform, false); _box.m_name = "$item_kw_keychain"; KeychainStore.FitAndSave(chain); BoxInventory.Invoke(_box) = val; _open = chain; instance.Show(_box, 1); } internal static void Tick() { if (_open == null) { return; } InventoryGui instance = InventoryGui.instance; Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)localPlayer) || (Object)(object)CurrentContainer.Invoke(instance) != (Object)(object)_box || !Object.op_Implicit((Object)(object)_box)) { _open = null; return; } if (!((Humanoid)localPlayer).GetInventory().ContainsItem(_open)) { ItemData val = SameChain(((Humanoid)localPlayer).GetInventory(), _open); if (val == null) { AccessTools.Method(typeof(InventoryGui), "CloseContainer", (Type[])null, (Type[])null).Invoke(instance, null); _open = null; return; } Inventory val2 = KeychainStore.Get(val); if (val2 == null || KeychainStore.IsBroken(val)) { AccessTools.Method(typeof(InventoryGui), "CloseContainer", (Type[])null, (Type[])null).Invoke(instance, null); _open = null; return; } BoxInventory.Invoke(_box) = val2; _open = val; } if (DragItem.Invoke(instance) == null) { KeychainStore.FitAndSave(_open); } } private static ItemData SameChain(Inventory bag, ItemData gone) { gone.m_customData.TryGetValue("KeyWarden.keys", out var value); ItemData val = null; foreach (ItemData allItem in bag.GetAllItems()) { if (allItem == gone || !KeychainItem.IsKeychain(allItem)) { continue; } allItem.m_customData.TryGetValue("KeyWarden.keys", out var value2); if (!(value2 != value)) { if (val != null) { return null; } val = allItem; } } return val; } } internal static class KeyPatches { [HarmonyPatch(typeof(Inventory), "HaveItem", new Type[] { typeof(string), typeof(bool) })] private static class HaveItemPatch { private static void Postfix(Inventory __instance, string name, bool matchWorldLevel, ref bool __result) { if (__result || !KeychainItem.IsKeyName(name) || __instance != LocalBag()) { return; } foreach (ItemData allItem in __instance.GetAllItems()) { if (KeychainItem.IsKeychain(allItem)) { Inventory val = KeychainStore.Get(allItem); if (val != null && val.HaveItem(name, matchWorldLevel)) { __result = true; break; } } } } } [HarmonyPatch(typeof(Inventory), "RemoveItem", new Type[] { typeof(string), typeof(int), typeof(int), typeof(bool) })] private static class RemoveByNamePatch { private static void Prefix(Inventory __instance, string name, int amount, int itemQuality, bool worldLevelBased, out int __state) { __state = 0; if (KeychainItem.IsKeyName(name) && __instance == LocalBag()) { __state = Mathf.Max(0, amount - __instance.CountItems(name, itemQuality, worldLevelBased)); } } private static void Postfix(Inventory __instance, string name, int itemQuality, bool worldLevelBased, int __state) { int num = __state; if (num <= 0) { return; } ItemData[] array = __instance.GetAllItems().ToArray(); foreach (ItemData val in array) { if (num <= 0) { break; } if (!KeychainItem.IsKeychain(val) || KeychainStore.IsBroken(val)) { continue; } Inventory val2 = KeychainStore.Get(val); if (val2 != null) { int num2 = val2.CountItems(name, itemQuality, worldLevelBased); if (num2 > 0) { int num3 = Mathf.Min(num2, num); val2.RemoveItem(name, num3, itemQuality, worldLevelBased); num -= num3; } } } } } [HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(ItemData) })] private static class AddItemPatch { private static bool Prefix(Inventory __instance, ItemData item, ref bool __result) { if (!Refuse(__instance, item)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(ItemData), typeof(Vector2i) })] private static class AddItemAtPatch { private static bool Prefix(Inventory __instance, ItemData item, ref bool __result) { if (!Refuse(__instance, item)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(ItemData), typeof(int), typeof(int), typeof(int), typeof(bool) })] private static class AddItemGridPatch { private static bool Prefix(Inventory __instance, ItemData item, ref bool __result) { if (!Refuse(__instance, item)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(InventoryGrid), "DropItem")] private static class DropItemPatch { private static bool Prefix(InventoryGrid __instance, Inventory fromInventory, ItemData item, Vector2i pos, ref bool __result) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) Inventory inventory = __instance.GetInventory(); if (inventory == fromInventory) { return true; } ItemData item2 = ((inventory != null) ? inventory.GetItemAt(pos.x, pos.y) : null); if (!Refuse(inventory, item) && !Refuse(fromInventory, item2)) { return true; } SayOnlyKeys(); __result = false; return false; } } [HarmonyPatch(typeof(ItemData), "GetWeight")] private static class WeightPatch { private static void Postfix(ItemData __instance, ref float __result) { if (KeychainItem.IsKeychain(__instance)) { Inventory val = KeychainStore.Get(__instance); if (val != null) { __result += val.GetTotalWeight(); } } } } [HarmonyPatch(typeof(ItemData), "GetTooltip", new Type[] { typeof(ItemData), typeof(int), typeof(bool), typeof(float), typeof(int), typeof(bool) })] private static class TooltipPatch { private static void Postfix(ItemData item, bool crafting, ref string __result) { if (crafting || !KeychainItem.IsKeychain(item)) { return; } Inventory val = KeychainStore.Get(item); if (val != null) { string[] array = (from k in val.GetAllItems() select Localization.instance.Localize(k.m_shared.m_name)).ToArray(); __result = __result + "\n\n" + Localization.instance.Localize("$keychain_keys") + ": " + ((array.Length == 0) ? Localization.instance.Localize("$keychain_none") : string.Join(", ", array)); } } } [HarmonyPatch(typeof(Inventory), "IsTeleportable")] private static class TeleportPatch { private static void Postfix(Inventory __instance, bool allowAllItems, ref bool __result) { if (!__result || KeychainStore.IsChainInventory(__instance)) { return; } foreach (ItemData allItem in __instance.GetAllItems()) { if (KeychainItem.IsKeychain(allItem)) { Inventory val = KeychainStore.Get(allItem); if (val != null && !val.IsTeleportable(allowAllItems)) { __result = false; break; } } } } } private static Inventory LocalBag() { Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)localPlayer)) { return null; } return ((Humanoid)localPlayer).GetInventory(); } private static bool Refuse(Inventory inv, ItemData item) { if (item != null && KeychainStore.IsChainInventory(inv)) { return !KeychainItem.IsKey(item); } return false; } private static void SayOnlyKeys() { Player localPlayer = Player.m_localPlayer; if (Object.op_Implicit((Object)(object)localPlayer)) { ((Character)localPlayer).Message((MessageType)2, "$keychain_onlykeys", 0, (Sprite)null, false); } } } [BepInPlugin("daddybjorn.KeyWarden", "KeyWarden", "1.0.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { internal static ConfigEntry<string> Recipe; internal static ConfigEntry<string> Station; internal static ConfigEntry<string> Keys; internal static ConfigEntry<int> StationLevel; internal static ConfigEntry<bool> AnyKey; internal static ConfigEntry<bool> KeysToChain; internal static ConfigEntry<bool> AzuSlot; private Harmony _harmony; internal static readonly Dictionary<string, string> English = new Dictionary<string, string> { { "item_kw_keychain", "Keychain" }, { "item_kw_keychain_description", "A sturdy tin ring for your keys. Right-click it to open it. Keys on the chain still open their doors while you carry it." }, { "keychain_onlykeys", "Only keys fit on the keychain" }, { "keychain_emptyfirst", "Empty the keychain first (it still holds keys)" }, { "keychain_keys", "Keys" }, { "keychain_none", "none" }, { "keychain_unreadable", "This keychain's keys could not be read (is the mod that adds them missing?). It was left untouched." } }; private void Awake() { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Expected O, but got Unknown //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Expected O, but got Unknown //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Expected O, but got Unknown //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Expected O, but got Unknown //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0117: Expected O, but got Unknown //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Expected O, but got Unknown //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Expected O, but got Unknown //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Expected O, but got Unknown Recipe = ((BaseUnityPlugin)this).Config.Bind<string>("1 - Crafting", "Recipe", "LeatherScraps:4,HardAntler:1,Tin:1", new ConfigDescription("Crafting cost, as Prefab:Amount separated by commas. Needs a restart.", (AcceptableValueBase)null, new object[1] { Admin(3) })); Station = ((BaseUnityPlugin)this).Config.Bind<string>("1 - Crafting", "Crafting station", "piece_workbench", new ConfigDescription("Prefab name of the station that crafts it. Needs a restart.", (AcceptableValueBase)null, new object[1] { Admin(2) })); StationLevel = ((BaseUnityPlugin)this).Config.Bind<int>("1 - Crafting", "Station level", 1, new ConfigDescription("Station level needed. Needs a restart.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), new object[1] { Admin(1) })); Keys = ((BaseUnityPlugin)this).Config.Bind<string>("2 - Keys", "Keys", "CryptKey,DvergrKey,HildirKey_forestcrypt,HildirKey_mountaincave,HildirKey_plainsfortress,BloodGoldKey,BOM_EikthyrKey,BOM_BonemassKey,BOM_CrystalKey,BOM_LavaKey", new ConfigDescription("Prefab names of the items that fit on the keychain, separated by commas; names the game doesn't have are skipped. Default: the vanilla keys (Swamp key, Sealbreaker, Hildir's keys, Bloodgold key) + Blackbear's Ore Mines keys (its coal and iron mines use the Swamp key). Not the Sealbreaker fragments: crafting can't use items on the chain.", (AcceptableValueBase)null, new object[1] { Admin(3) })); AnyKey = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Keys", "Accept any key", true, new ConfigDescription("Also accept every item that any door in the game uses as its key (keys from other dungeon mods). Tools or crafting items with key in the name are not taken.", (AcceptableValueBase)null, new object[1] { Admin(2) })); KeysToChain = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Keys", "Keys go onto the keychain", true, new ConfigDescription("Keys you pick up go straight onto your keychain (the worn one first) when you carry one.", (AcceptableValueBase)null, new object[1] { Local(1) })); AzuSlot = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Compatibility", "AzuEPI slot", true, new ConfigDescription("With AzuExtendedPlayerInventory installed: give the keychain its own \"Keychain\" equipment slot. Needs a restart. Off: the keychain works from the bag only (AzuEPI moves one out of the removed slot into the bag).", (AcceptableValueBase)null, new object[1] { Local(1) })); CustomLocalization localization = LocalizationManager.Instance.GetLocalization(); string text = "English"; localization.AddTranslation(ref text, English); PrefabManager.OnVanillaPrefabsAvailable += KeychainItem.Register; _harmony = new Harmony("daddybjorn.KeyWarden"); _harmony.PatchAll(typeof(Plugin).Assembly); static ConfigurationManagerAttributes Admin(int order) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown return new ConfigurationManagerAttributes { IsAdminOnly = true, Order = order }; } static ConfigurationManagerAttributes Local(int order) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown return new ConfigurationManagerAttributes { Order = order }; } } private void Start() { AzuEpiSlot.TryAdd(); KeychainCompat.Install(_harmony); } private void Update() { KeychainWindow.Tick(); AzuEpiSlot.Tick(); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } internal static class PluginInfo { public const string Guid = "daddybjorn.KeyWarden"; public const string Name = "KeyWarden"; public const string Version = "1.0.1"; } }