using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyCompany("com.github.DarknessEoL.VisualBackpack")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("com.github.DarknessEoL.VisualBackpack")]
[assembly: AssemblyTitle("VisualBackpack")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[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;
}
}
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}
namespace PeakBackpackMods
{
[HarmonyPatch(typeof(BackpackData), "AddItem")]
public static class BackpackData_Patch
{
[HarmonyPostfix]
public static void Postfix(BackpackData __instance)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
if ((Object)BackpackHotbarMod.hotbarUI != (Object)null)
{
BackpackHotbarMod.hotbarUI.UpdateHotbar(__instance.itemSlots);
}
}
}
public class BackpackHotbarHotbarUI : MonoBehaviour
{
private CustomInventorySlotUI[]? slots;
private Canvas? canvas;
private GameObject? slotContainer;
private GameObject? slotTemplateClone;
private bool isInitialized = false;
private void Awake()
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
canvas = ((Component)this).gameObject.AddComponent<Canvas>();
canvas.renderMode = (RenderMode)0;
((Component)this).gameObject.AddComponent<CanvasScaler>();
((Component)this).gameObject.AddComponent<GraphicRaycaster>();
slotContainer = new GameObject("BackpackHotbarContainer");
slotContainer.transform.SetParent(((Component)canvas).transform);
RectTransform val = slotContainer.AddComponent<RectTransform>();
val.anchorMin = new Vector2(0.5f, 0f);
val.anchorMax = new Vector2(0.5f, 0f);
val.pivot = new Vector2(0.5f, 0f);
val.anchoredPosition = new Vector2(0f, 20f);
val.sizeDelta = new Vector2(400f, 100f);
HorizontalLayoutGroup val2 = slotContainer.AddComponent<HorizontalLayoutGroup>();
((HorizontalOrVerticalLayoutGroup)val2).spacing = 10f;
((LayoutGroup)val2).childAlignment = (TextAnchor)4;
((HorizontalOrVerticalLayoutGroup)val2).childControlWidth = true;
((HorizontalOrVerticalLayoutGroup)val2).childControlHeight = true;
SetHotbarVisibility(isVisible: false);
}
private void InitializeHotbar()
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Expected O, but got Unknown
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Expected O, but got Unknown
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Expected O, but got Unknown
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Expected O, but got Unknown
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_011d: Expected O, but got Unknown
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Expected O, but got Unknown
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Expected O, but got Unknown
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Expected O, but got Unknown
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Expected O, but got Unknown
//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
//IL_01d3: Expected O, but got Unknown
//IL_0228: Unknown result type (might be due to invalid IL or missing references)
//IL_0232: Expected O, but got Unknown
if (isInitialized)
{
return;
}
GameObject val = GameObject.Find("GAME/GUIManager/Canvas_HUD/Inventory/Layout/UI_InventoryItem");
Transform val2 = (((Object)(object)val != (Object)null) ? val.transform : null);
if ((Object)val2 == (Object)null)
{
return;
}
try
{
slotTemplateClone = Object.Instantiate<GameObject>(((Component)val2).gameObject);
Type type = Type.GetType("Zorro.UI.InventoryItemUI, Assembly-CSharp");
if (type != null)
{
Component component = slotTemplateClone.GetComponent(type);
if ((Object)component != (Object)null)
{
Object.DestroyImmediate((Object)component);
}
}
LayoutElement component2 = slotTemplateClone.GetComponent<LayoutElement>();
if ((Object)(object)component2 != (Object)null)
{
Object.DestroyImmediate((Object)component2);
}
CanvasGroup component3 = slotTemplateClone.GetComponent<CanvasGroup>();
if ((Object)(object)component3 != (Object)null)
{
Object.DestroyImmediate((Object)component3);
}
Transform val3 = slotTemplateClone.transform.FindDeepChild("UI_InputIcon");
if ((Object)val3 != (Object)null)
{
Object.DestroyImmediate((Object)((Component)val3).gameObject);
}
Canvas component4 = slotTemplateClone.GetComponent<Canvas>();
if ((Object)(object)component4 != (Object)null)
{
Object.DestroyImmediate((Object)component4);
}
CanvasScaler component5 = slotTemplateClone.GetComponent<CanvasScaler>();
if ((Object)(object)component5 != (Object)null)
{
Object.DestroyImmediate((Object)component5);
}
((Object)slotTemplateClone).name = "BackpackSlotTemplate";
slotTemplateClone.SetActive(false);
slots = new CustomInventorySlotUI[4];
for (int i = 0; i < 4; i++)
{
GameObject val4 = new GameObject($"BackpackSlot_{i}");
val4.transform.SetParent(slotContainer.transform);
slots[i] = val4.AddComponent<CustomInventorySlotUI>();
slots[i].Setup(slotTemplateClone);
}
Object.DestroyImmediate((Object)slotTemplateClone);
slotTemplateClone = null;
isInitialized = true;
}
catch (Exception ex)
{
Debug.LogError((object)("BackpackHotbarMod: Error cloning/stripping UI template: " + ex.Message));
isInitialized = false;
}
}
public void SetHotbarVisibility(bool isVisible)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
if ((Object)canvas != (Object)null)
{
((Behaviour)canvas).enabled = isVisible;
}
}
public void UpdateHotbar(ItemSlot[] itemSlots)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Expected O, but got Unknown
InitializeHotbar();
if (!isInitialized || (Object)canvas == (Object)null || !((Behaviour)canvas).enabled || slots == null)
{
return;
}
for (int i = 0; i < 4; i++)
{
if (i < itemSlots.Length)
{
slots[i].SetItem(itemSlots[i]);
}
}
}
}
[BepInPlugin("com.yourname.backpackhotbar", "Peak Backpack Hotbar", "1.0.0")]
public class BackpackHotbarMod : BaseUnityPlugin
{
public const int NUM_SLOTS = 4;
public static BackpackHotbarHotbarUI? hotbarUI;
private static Harmony harmony;
private void Awake()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Expected O, but got Unknown
harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
harmony.PatchAll(typeof(BackpackHotbarMod));
harmony.PatchAll(typeof(BackpackData_Patch));
GameObject val = new GameObject("BackpackHotbarUI");
hotbarUI = val.AddComponent<BackpackHotbarHotbarUI>();
Object.DontDestroyOnLoad((Object)val);
}
private void OnDestroy()
{
harmony.UnpatchSelf();
}
private void Update()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
if ((Object)hotbarUI == (Object)null || (Object)Player.localPlayer == (Object)null)
{
hotbarUI?.SetHotbarVisibility(isVisible: false);
return;
}
try
{
Player localPlayer = Player.localPlayer;
BackpackSlot backpackSlot = localPlayer.backpackSlot;
if (((ItemSlot)backpackSlot).IsEmpty())
{
hotbarUI.SetHotbarVisibility(isVisible: false);
return;
}
ItemInstanceData data = ((ItemSlot)backpackSlot).data;
BackpackData val = null;
if (data != null && data.TryGetDataEntry<BackpackData>((DataEntryKey)7, ref val))
{
hotbarUI.SetHotbarVisibility(isVisible: true);
hotbarUI.UpdateHotbar(val.itemSlots);
}
else
{
hotbarUI.SetHotbarVisibility(isVisible: false);
}
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Backpack Hotbar Runtime Error: " + ex.Message));
hotbarUI.SetHotbarVisibility(isVisible: false);
}
}
}
public class CustomInventorySlotUI : MonoBehaviour
{
private RawImage? icon;
private TextMeshProUGUI? nameText;
private Image? background;
private Item? itemPrefab;
public void Setup(GameObject? templateObject)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Expected O, but got Unknown
//IL_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: 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_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_0184: Expected O, but got Unknown
//IL_01be: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: Expected O, but got Unknown
//IL_022f: Unknown result type (might be due to invalid IL or missing references)
//IL_023a: Expected O, but got Unknown
if ((Object)templateObject != (Object)null)
{
LayoutElement val = ((Component)this).gameObject.AddComponent<LayoutElement>();
RectTransform component = templateObject.GetComponent<RectTransform>();
if ((Object)(object)component != (Object)null)
{
val.preferredWidth = component.sizeDelta.x;
val.preferredHeight = component.sizeDelta.y;
Transform transform = ((Component)this).transform;
((RectTransform)((transform is RectTransform) ? transform : null)).sizeDelta = component.sizeDelta;
}
GameObject val2 = Object.Instantiate<GameObject>(templateObject, ((Component)this).transform);
((Object)val2).name = "HotbarSlotInstance";
val2.SetActive(true);
Transform transform2 = val2.transform;
RectTransform val3 = (RectTransform)((transform2 is RectTransform) ? transform2 : null);
if ((Object)(object)val3 != (Object)null)
{
val3.anchorMin = Vector2.zero;
val3.anchorMax = Vector2.one;
val3.pivot = new Vector2(0.5f, 0.5f);
val3.anchoredPosition = Vector2.zero;
val3.sizeDelta = Vector2.zero;
}
Transform val4 = val2.transform.FindDeepChild("Outline");
background = (((Object)(object)val4 != (Object)null) ? ((Component)val4).GetComponent<Image>() : null);
Transform val5 = val2.transform.FindDeepChild("ItemIcon");
icon = (((Object)(object)val5 != (Object)null) ? ((Component)val5).GetComponent<RawImage>() : null);
if ((Object)icon == (Object)null)
{
Transform val6 = val2.transform.FindDeepChild("Icon");
icon = (((Object)(object)val6 != (Object)null) ? ((Component)val6).GetComponent<RawImage>() : null);
}
if ((Object)icon == (Object)null)
{
Transform val7 = val2.transform.FindDeepChild("RawImage");
icon = (((Object)(object)val7 != (Object)null) ? ((Component)val7).GetComponent<RawImage>() : null);
}
Transform val8 = val2.transform.FindDeepChild("ItemName");
nameText = (((Object)(object)val8 != (Object)null) ? ((Component)val8).GetComponent<TextMeshProUGUI>() : null);
if ((Object)nameText == (Object)null)
{
Transform val9 = val2.transform.FindDeepChild("Name");
nameText = (((Object)(object)val9 != (Object)null) ? ((Component)val9).GetComponent<TextMeshProUGUI>() : null);
}
}
}
public void SetItem(ItemSlot slot)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Expected O, but got Unknown
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Expected O, but got Unknown
//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Expected O, but got Unknown
if ((Object)icon == (Object)null || (Object)nameText == (Object)null || (Object)background == (Object)null)
{
return;
}
if (slot.IsEmpty())
{
((Behaviour)icon).enabled = false;
itemPrefab = null;
((TMP_Text)nameText).text = "";
return;
}
itemPrefab = slot.prefab;
if ((Object)itemPrefab != (Object)null)
{
Texture val = null;
try
{
object value = Traverse.Create((object)itemPrefab).Field("UIData").GetValue();
if (value != null)
{
val = (Texture)Traverse.Create(value).Method("GetIcon", Array.Empty<object>()).GetValue<Texture2D>();
}
}
catch (Exception)
{
}
if ((Object)val != (Object)null)
{
icon.texture = val;
((Behaviour)icon).enabled = true;
}
else
{
((Behaviour)icon).enabled = false;
}
((TMP_Text)nameText).text = itemPrefab.GetItemName(slot.data);
}
else
{
((Behaviour)icon).enabled = false;
((TMP_Text)nameText).text = "???";
}
}
}
public static class TransformExtensions
{
public static Transform? FindDeepChild(this Transform aParent, string aName)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Expected O, but got Unknown
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Expected O, but got Unknown
if ((Object)aParent == (Object)null)
{
return null;
}
Transform val = aParent.Find(aName);
if ((Object)val != (Object)null)
{
return val;
}
foreach (Transform item in aParent)
{
Transform val2 = item;
Transform aParent2 = val2;
val = aParent2.FindDeepChild(aName);
if ((Object)val != (Object)null)
{
return val;
}
}
return null;
}
}
}
namespace BepInEx
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class BepInAutoPluginAttribute : Attribute
{
public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace BepInEx.Preloader.Core.Patching
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class PatcherAutoPluginAttribute : Attribute
{
public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}