using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace InventorySlotsVisualToggle { [BepInPlugin("dragonmotion.InventorySlotsVisualToggle", "InventorySlots Visual Toggle", "0.1.4")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class InventorySlotsVisualTogglePlugin : BaseUnityPlugin { private sealed class HiddenVisualState { public ItemData? Helmet; public ItemData? Shoulder; public bool HideHelmet; public bool HideCape; } private static class InventorySlotsUiPatch { public static void Postfix(object[] __args, bool __result) { object element = ((__args.Length != 0) ? __args[0] : null); string slotId = GetSlotId((__args.Length > 3) ? __args[3] : null); if (!IsTargetSlot(slotId)) { SetToggleActive(element, active: false); } else { EnsureToggle(element, slotId, __result); } } } private static class InventorySlotsBindingLabelPatch { public static void Postfix(object[] __args) { object element = ((__args.Length != 0) ? __args[0] : null); if (IsTargetSlot(GetSlotId((__args.Length > 1) ? __args[1] : null))) { BringToggleToFront(element); } } } [HarmonyPatch(typeof(Humanoid), "SetupVisEquipment")] private static class HumanoidSetupVisEquipmentPatch { private static void Prefix(Humanoid __instance, bool isRagdoll, ref HiddenVisualState? __state) { if (isRagdoll) { return; } Player val = (Player)(object)((__instance is Player) ? __instance : null); if (val == null) { return; } bool flag = IsHidden(val, "helmet"); bool flag2 = IsHidden(val, "cape"); if (flag || flag2) { __state = new HiddenVisualState { Helmet = HelmetItemRef.Invoke(__instance), Shoulder = ShoulderItemRef.Invoke(__instance), HideHelmet = flag, HideCape = flag2 }; if (flag) { HelmetItemRef.Invoke(__instance) = null; } if (flag2) { ShoulderItemRef.Invoke(__instance) = null; } } } private static void Postfix(Humanoid __instance, HiddenVisualState? __state) { if (__state != null) { if (__state.HideHelmet) { HelmetItemRef.Invoke(__instance) = __state.Helmet; } if (__state.HideCape) { ShoulderItemRef.Invoke(__instance) = __state.Shoulder; } } } } [HarmonyPatch(typeof(Player), "Load")] private static class PlayerLoadPatch { private static void Postfix(Player __instance) { RestoreHiddenState(__instance); RefreshVisuals(__instance); } } [HarmonyPatch(typeof(Player), "Save")] private static class PlayerSavePatch { private static void Prefix(Player __instance) { RestoreHiddenState(__instance); } } [HarmonyPatch(typeof(Player), "OnSpawned")] private static class PlayerOnSpawnedPatch { private static void Postfix(Player __instance) { RestoreHiddenState(__instance); RefreshVisuals(__instance); } } private sealed class EyeToggleMarker : MonoBehaviour { public const string ChildName = "ObeliskVisualEyeToggle"; private string _slotId = ""; public void Configure(string slotId) { _slotId = slotId; } public void OnClick() { ToggleHidden(_slotId); } } public const string ModGuid = "dragonmotion.InventorySlotsVisualToggle"; public const string ModName = "InventorySlots Visual Toggle"; public const string ModVersion = "0.1.4"; private static readonly string HelmetHiddenKey = "dragonmotion.InventorySlotsVisualToggle.HideHelmet"; private static readonly string CapeHiddenKey = "dragonmotion.InventorySlotsVisualToggle.HideCape"; private static readonly string ItemHiddenSlotKey = "dragonmotion.InventorySlotsVisualToggle.HiddenSlot"; private static readonly Dictionary ElementGoFields = new Dictionary(); private static readonly Dictionary SlotIdProperties = new Dictionary(); private static readonly FieldRef HelmetItemRef = AccessTools.FieldRefAccess("m_helmetItem"); private static readonly FieldRef ShoulderItemRef = AccessTools.FieldRefAccess("m_shoulderItem"); private static Harmony? _harmony; private static ManualLogSource? _log; private static MethodInfo? _setupEquipmentMethod; private static MethodInfo? _inventoryGuiUpdateInventoryMethod; private static Sprite? _eyeSprite; private static Sprite? _hiddenEyeSprite; private static bool _loggedHelmetSlotSeen; private static bool _loggedCapeSlotSeen; private void Awake() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Expected O, but got Unknown _log = ((BaseUnityPlugin)this).Logger; _harmony = new Harmony("dragonmotion.InventorySlotsVisualToggle"); _setupEquipmentMethod = AccessTools.Method(typeof(Humanoid), "SetupEquipment", (Type[])null, (Type[])null); _inventoryGuiUpdateInventoryMethod = AccessTools.Method(typeof(InventoryGui), "UpdateInventory", new Type[1] { typeof(Player) }, (Type[])null); PatchInventorySlotsUi(); _harmony.PatchAll(typeof(InventorySlotsVisualTogglePlugin).Assembly); ((BaseUnityPlugin)this).Logger.LogInfo((object)"InventorySlots Visual Toggle 0.1.4 loaded."); } private void OnDestroy() { Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } private static void PatchInventorySlotsUi() { //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Expected O, but got Unknown //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown Type type = AccessTools.TypeByName("InventorySlots.InventorySlotsPlugin"); MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "UpdateEquipmentSlotElementState", (Type[])null, (Type[])null)); MethodInfo methodInfo2 = AccessTools.Method(typeof(InventorySlotsUiPatch), "Postfix", (Type[])null, (Type[])null); if (methodInfo == null || methodInfo2 == null) { ManualLogSource? log = _log; if (log != null) { log.LogWarning((object)"InventorySlots equipment slot UI method was not found. Eye buttons are disabled."); } return; } Harmony? harmony = _harmony; if (harmony != null) { harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } ManualLogSource? log2 = _log; if (log2 != null) { log2.LogInfo((object)"InventorySlots equipment slot UI method patched."); } MethodInfo methodInfo3 = ((type == null) ? null : AccessTools.Method(type, "UpdateSlotBindingLabel", (Type[])null, (Type[])null)); MethodInfo methodInfo4 = AccessTools.Method(typeof(InventorySlotsBindingLabelPatch), "Postfix", (Type[])null, (Type[])null); if (methodInfo3 != null && methodInfo4 != null) { Harmony? harmony2 = _harmony; if (harmony2 != null) { harmony2.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, new HarmonyMethod(methodInfo4), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } ManualLogSource? log3 = _log; if (log3 != null) { log3.LogInfo((object)"InventorySlots slot binding label method patched."); } } } private static bool IsTargetSlot(string? slotId) { if (!string.Equals(slotId, "helmet", StringComparison.OrdinalIgnoreCase)) { return string.Equals(slotId, "cape", StringComparison.OrdinalIgnoreCase); } return true; } private static string GetHiddenKey(string slotId) { if (!string.Equals(slotId, "helmet", StringComparison.OrdinalIgnoreCase)) { return CapeHiddenKey; } return HelmetHiddenKey; } internal static bool IsHidden(Player? player, string slotId) { if (player?.m_customData == null) { return false; } if (player.m_customData.TryGetValue(GetHiddenKey(slotId), out var value) && string.Equals(value, "1", StringComparison.Ordinal)) { return true; } return IsItemMarkedHidden(GetSlotItem(player, slotId), slotId); } private static void SetHidden(Player player, string slotId, bool hidden) { string hiddenKey = GetHiddenKey(slotId); if (hidden) { player.m_customData[hiddenKey] = "1"; } else { player.m_customData.Remove(hiddenKey); } SetItemHidden(GetSlotItem(player, slotId), slotId, hidden); } internal static void ToggleHidden(string slotId) { Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && IsTargetSlot(slotId)) { bool hidden = !IsHidden(localPlayer, slotId); SetHidden(localPlayer, slotId, hidden); RefreshVisuals(localPlayer); RefreshInventoryGui(localPlayer); } } private static ItemData? GetSlotItem(Player? player, string slotId) { if ((Object)(object)player == (Object)null) { return null; } if (!string.Equals(slotId, "helmet", StringComparison.OrdinalIgnoreCase)) { return ShoulderItemRef.Invoke((Humanoid)(object)player); } return HelmetItemRef.Invoke((Humanoid)(object)player); } private static bool IsItemMarkedHidden(ItemData? item, string slotId) { if (item?.m_customData != null && item.m_customData.TryGetValue(ItemHiddenSlotKey, out var value)) { return string.Equals(value, slotId, StringComparison.OrdinalIgnoreCase); } return false; } private static void SetItemHidden(ItemData? item, string slotId, bool hidden) { if (item != null) { if (item.m_customData == null) { item.m_customData = new Dictionary(); } if (hidden) { item.m_customData[ItemHiddenSlotKey] = slotId.ToLowerInvariant(); } else if (IsItemMarkedHidden(item, slotId)) { item.m_customData.Remove(ItemHiddenSlotKey); } } } private static void RestoreHiddenState(Player player) { RestoreSlotHiddenState(player, "helmet"); RestoreSlotHiddenState(player, "cape"); } private static void RestoreSlotHiddenState(Player player, string slotId) { bool flag = IsHidden(player, slotId); string hiddenKey = GetHiddenKey(slotId); if (flag) { player.m_customData[hiddenKey] = "1"; } else { player.m_customData.Remove(hiddenKey); } SetItemHidden(GetSlotItem(player, slotId), slotId, flag); } private static void RefreshVisuals(Player player) { try { _setupEquipmentMethod?.Invoke(player, Array.Empty()); } catch (Exception ex) { ManualLogSource? log = _log; if (log != null) { log.LogWarning((object)("Failed to refresh player equipment visuals: " + ex.Message)); } } } private static void RefreshInventoryGui(Player player) { try { InventoryGui instance = InventoryGui.instance; if ((Object)(object)instance != (Object)null) { _inventoryGuiUpdateInventoryMethod?.Invoke(instance, new object[1] { player }); } } catch (Exception ex) { ManualLogSource? log = _log; if (log != null) { log.LogWarning((object)("Failed to refresh InventoryGui after visual toggle: " + ex.Message)); } } } private static string? GetSlotId(object? slot) { if (slot == null) { return null; } Type type = slot.GetType(); if (!SlotIdProperties.TryGetValue(type, out PropertyInfo value)) { value = AccessTools.Property(type, "Id"); SlotIdProperties[type] = value; } return value?.GetValue(slot) as string; } private static GameObject? GetElementGameObject(object? element) { if (element == null) { return null; } Type type = element.GetType(); if (!ElementGoFields.TryGetValue(type, out FieldInfo value)) { value = AccessTools.Field(type, "m_go"); ElementGoFields[type] = value; } object? obj = value?.GetValue(element); return (GameObject?)((obj is GameObject) ? obj : null); } private static void SetToggleActive(object? element, bool active) { GameObject? elementGameObject = GetElementGameObject(element); Transform val = ((elementGameObject != null) ? elementGameObject.transform.Find("ObeliskVisualEyeToggle") : null); if ((Object)(object)val != (Object)null) { ((Component)val).gameObject.SetActive(active); } } private static void EnsureToggle(object? element, string slotId, bool hasItem) { //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: Unknown result type (might be due to invalid IL or missing references) //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: 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_010f: 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_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0124: 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_0143: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01b3: 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_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_021b: Expected O, but got Unknown //IL_02bf: Unknown result type (might be due to invalid IL or missing references) //IL_02a4: Unknown result type (might be due to invalid IL or missing references) GameObject elementGameObject = GetElementGameObject(element); if ((Object)(object)elementGameObject == (Object)null) { return; } Transform val = elementGameObject.transform.Find("ObeliskVisualEyeToggle"); if (!hasItem) { if ((Object)(object)val != (Object)null) { ((Component)val).gameObject.SetActive(false); } return; } Image val4; EyeToggleMarker eyeToggleMarker; if ((Object)(object)val == (Object)null) { GameObject val2 = new GameObject("ObeliskVisualEyeToggle", new Type[5] { typeof(RectTransform), typeof(CanvasRenderer), typeof(Image), typeof(Button), typeof(EyeToggleMarker) }); RectTransform val3 = (RectTransform)val2.transform; ((Transform)val3).SetParent(elementGameObject.transform, false); val3.anchorMin = new Vector2(0f, 1f); val3.anchorMax = new Vector2(0f, 1f); val3.pivot = new Vector2(0f, 1f); val3.sizeDelta = new Vector2(22f, 22f); val3.anchoredPosition = new Vector2(3f, -3f); ((Transform)val3).localScale = Vector3.one; ((Transform)val3).localRotation = Quaternion.identity; val4 = val2.GetComponent(); ((Graphic)val4).raycastTarget = true; val4.preserveAspect = true; Button component = val2.GetComponent