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 EquipmentSlots v0.2.4
NathansQol.EquipmentSlots.dll
Decompiled 5 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using NathansQol.EquipmentSlots.Equipment; using NathansQol.EquipmentSlots.Foodbag; using NathansQol.EquipmentSlots.Quiver; using NathansQol.EquipmentSlots.Slots; using TMPro; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("assembly_guiutils")] [assembly: IgnoresAccessChecksTo("assembly_utils")] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("NathansQol.EquipmentSlots")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.2.4.0")] [assembly: AssemblyInformationalVersion("0.2.4+b5cd180fda1a81174875e480d8ae3714ee1b1c4f")] [assembly: AssemblyProduct("NathansQol.EquipmentSlots")] [assembly: AssemblyTitle("NathansQol.EquipmentSlots")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.2.4.0")] [module: UnverifiableCode] [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 NathansQol.EquipmentSlots { [BepInPlugin("nathan.qol.equipmentslots", "Nathans Equipment Slots", "0.2.4")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class EquipmentSlotsPlugin : BaseUnityPlugin { public const string PluginGuid = "nathan.qol.equipmentslots"; public const string PluginName = "Nathans Equipment Slots"; public const string PluginVersion = "0.2.4"; internal static ManualLogSource Log; internal static ConfigEntry<KeyboardShortcut>[] EatKeys; internal static ConfigEntry<float> PanelOffsetX; internal static ConfigEntry<float> PanelOffsetY; internal static ConfigEntry<float> ArrowHudOffsetX; internal static ConfigEntry<float> FoodKeyHudOffsetX; private void Awake() { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; EatKeys = new ConfigEntry<KeyboardShortcut>[3] { ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "EatFoodSlot1", new KeyboardShortcut((KeyCode)122, Array.Empty<KeyCode>()), "Eat the food in food bag slot 1."), ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "EatFoodSlot2", new KeyboardShortcut((KeyCode)118, Array.Empty<KeyCode>()), "Eat the food in food bag slot 2."), ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Hotkeys", "EatFoodSlot3", new KeyboardShortcut((KeyCode)98, Array.Empty<KeyCode>()), "Eat the food in food bag slot 3.") }; PanelOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "EquipmentPanelOffsetX", 150f, "Distance of the equipment panel from the right edge of the inventory (UI pixels)."); PanelOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "EquipmentPanelOffsetY", 0f, "Distance of the equipment panel below the top edge of the inventory (UI pixels)."); ArrowHudOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "ArrowHudOffsetX", 12f, "Gap between the guardian power display (Eikthyr etc.) and the arrow display (UI pixels)."); FoodKeyHudOffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("Layout", "FoodKeyHudOffsetX", 40f, "Distance of the food hotkey labels to the left of the food display (UI pixels)."); QuiverFeature.Init(); new Harmony("nathan.qol.equipmentslots").PatchAll(); } } } namespace NathansQol.EquipmentSlots.Slots { internal sealed class BagType : ISlotRule { public readonly string PrefabName; public readonly string Title; public readonly int Slots; private readonly string _dataKey; private readonly Func<ItemData, bool> _accepts; private readonly ConditionalWeakTable<ItemData, Inventory> _cache = new ConditionalWeakTable<ItemData, Inventory>(); public BagType(string prefabName, string dataKey, string title, int slots, Func<ItemData, bool> accepts) { PrefabName = prefabName; _dataKey = dataKey; Title = title; Slots = slots; _accepts = accepts; } public bool IsBag(ItemData item) { if (item != null && (Object)(object)item.m_dropPrefab != (Object)null) { return ((Object)item.m_dropPrefab).name == PrefabName; } return false; } public bool Accepts(ItemData item, int x, int y) { return _accepts(item); } public bool CanAcceptAnywhere(Inventory inventory, ItemData item) { return _accepts(item); } public Inventory GetInventory(ItemData bag) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Expected O, but got Unknown if (_cache.TryGetValue(bag, out var inv)) { return inv; } inv = new Inventory(Title, (Sprite)null, Slots, 1); SlotRules.Register(inv, this); if (bag.m_customData.TryGetValue(_dataKey, out var value) && !string.IsNullOrEmpty(value)) { try { inv.Load(new ZPackage(value)); } catch (Exception arg) { EquipmentSlotsPlugin.Log.LogError((object)$"Could not load {Title} contents, starting empty: {arg}"); } } EquipmentSlotsPlugin.Log.LogInfo((object)$"{Title} contents loaded: {inv.NrOfItems()} stack(s)"); Inventory obj = inv; obj.m_onChanged = (Action)Delegate.Combine(obj.m_onChanged, (Action)delegate { //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(); inv.Save(val); bag.m_customData[_dataKey] = val.GetBase64(); EquipmentStorage.SaveSnapshot(); }); _cache.Add(bag, inv); return inv; } public ItemData FindEquipped() { return EquipmentStorage.FindItem(IsBag); } public Inventory EquippedInventory() { ItemData val = FindEquipped(); if (val != null) { return GetInventory(val); } return null; } } internal static class Bags { public static readonly BagType Quiver = new BagType("NathansQuiver", "nathan.quiver.inv", "Quiver", 3, IsArrow); public static readonly BagType Foodbag = new BagType("NathansFoodbag", "nathan.foodbag.inv", "Food bag", 3, IsFood); public static IEnumerable<BagType> All => new BagType[2] { Quiver, Foodbag }; public static bool IsArrow(ItemData item) { //IL_000b: 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) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Invalid comparison between Unknown and I4 //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Invalid comparison between Unknown and I4 if (item == null) { return false; } ItemType itemType = item.m_shared.m_itemType; if ((int)itemType != 9 && (int)itemType != 23) { return false; } string ammoType = item.m_shared.m_ammoType; if (ammoType != null) { return ammoType.IndexOf("arrow", StringComparison.OrdinalIgnoreCase) >= 0; } return false; } public static bool IsFood(ItemData item) { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Invalid comparison between Unknown and I4 if (item == null || (int)item.m_shared.m_itemType != 2) { return false; } SharedData shared = item.m_shared; if (!(shared.m_food > 0f) && !(shared.m_foodStamina > 0f)) { return shared.m_foodEitr > 0f; } return true; } public static ItemData GetFirstArrow(string ammoType) { Inventory val = Quiver.EquippedInventory(); if (val == null) { return null; } return ((IEnumerable<ItemData>)(from i in val.GetAllItems() orderby i.m_gridPos.x select i)).FirstOrDefault((Func<ItemData, bool>)((ItemData i) => i.m_shared.m_ammoType == ammoType)); } public static Inventory FindOwningInventory(ItemData item) { Inventory val = EquipmentStorage.Get(); if (val != null && val.GetAllItems().Contains(item)) { return val; } foreach (BagType item2 in All) { Inventory val2 = item2.EquippedInventory(); if (val2 != null && val2.GetAllItems().Contains(item)) { return val2; } } return null; } public static float CarriedWeight() { Inventory obj = EquipmentStorage.Get(); float num = ((obj != null) ? obj.GetTotalWeight() : 0f); foreach (BagType item in All) { float num2 = num; Inventory obj2 = item.EquippedInventory(); num = num2 + ((obj2 != null) ? obj2.GetTotalWeight() : 0f); } return num; } } [HarmonyPatch(typeof(Inventory), "GetAmmoItem")] internal static class GetAmmoItemPatch { private static void Postfix(Inventory __instance, string ammoName, ref ItemData __result) { if (SlotRules.IsPlayerInventory(__instance)) { ItemData firstArrow = Bags.GetFirstArrow(ammoName); if (firstArrow != null) { __result = firstArrow; } } } } [HarmonyPatch(typeof(Inventory), "ContainsItem", new Type[] { typeof(ItemData) })] internal static class ContainsItemPatch { private static void Postfix(Inventory __instance, ItemData item, ref bool __result) { if (!__result && SlotRules.IsPlayerInventory(__instance)) { __result = Bags.FindOwningInventory(item) != null; } } } [HarmonyPatch(typeof(Inventory), "RemoveItem", new Type[] { typeof(ItemData), typeof(int) })] internal static class RemoveItemPatch { private static bool Prefix(Inventory __instance, ItemData item, int amount, ref bool __result) { if (!SlotRules.IsPlayerInventory(__instance)) { return true; } Inventory val = Bags.FindOwningInventory(item); if (val == null) { return true; } __result = val.RemoveItem(item, amount); return false; } } [HarmonyPatch(typeof(Inventory), "GetTotalWeight")] internal static class TotalWeightPatch { private static void Postfix(Inventory __instance, ref float __result) { if (SlotRules.IsPlayerInventory(__instance)) { __result += Bags.CarriedWeight(); } } } [HarmonyPatch(typeof(Inventory), "GetWornItems")] internal static class WornItemsPatch { private static void Postfix(Inventory __instance, List<ItemData> worn) { if (SlotRules.IsPlayerInventory(__instance)) { EquipmentStorage.AddWornItems(worn); } } } [HarmonyPatch(typeof(Inventory), "CanAddItem", new Type[] { typeof(ItemData), typeof(int) })] internal static class CanAddItemRulePatch { private static bool Prefix(Inventory __instance, ItemData item, ref bool __result) { ISlotRule slotRule = SlotRules.Get(__instance); if (slotRule == null || slotRule.CanAcceptAnywhere(__instance, item)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(ItemData) })] internal static class AddItemRulePatch { private static bool Prefix(Inventory __instance, ItemData item, ref bool __result) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) ISlotRule slotRule = SlotRules.Get(__instance); if (slotRule == null) { return true; } if (!slotRule.CanAcceptAnywhere(__instance, item)) { __result = false; return false; } if (__instance != EquipmentStorage.Get()) { return true; } Vector2i? val = EquipmentStorage.FindFreeSlot(__instance, item); __result = val.HasValue && __instance.AddItem(item, item.m_stack, val.Value.x, val.Value.y, false); return false; } } [HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(ItemData), typeof(Vector2i) })] internal static class AddItemAtRulePatch { private static bool Prefix(Inventory __instance, ItemData item, Vector2i pos, ref bool __result) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) ISlotRule slotRule = SlotRules.Get(__instance); if (slotRule == null || slotRule.Accepts(item, pos.x, pos.y)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(Inventory), "AddItem", new Type[] { typeof(ItemData), typeof(int), typeof(int), typeof(int), typeof(bool) })] internal static class AddItemSlotRulePatch { private static bool Prefix(Inventory __instance, ItemData item, int x, int y, ref bool __result) { ISlotRule slotRule = SlotRules.Get(__instance); if (slotRule == null || slotRule.Accepts(item, x, y)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(InventoryGui), "UpdateContainer")] internal static class KeepDragPatch { private static bool Prefix(InventoryGui __instance) { if ((Object)(object)__instance.m_currentContainer != (Object)null) { return true; } if (!SlotRules.IsManaged(__instance.m_dragInventory)) { return true; } ((Component)__instance.m_container).gameObject.SetActive(false); return false; } } [HarmonyPatch(typeof(InventoryGrid), "DropItem")] internal static class DropGuardPatch { private static bool Prefix(InventoryGrid __instance, Inventory fromInventory, ItemData item, Vector2i pos, ref bool __result) { //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0046: 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) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; Inventory inventory = __instance.GetInventory(); Inventory val = EquipmentStorage.Get(); if ((Object)(object)localPlayer != (Object)null && val != null && (inventory == val || fromInventory == val)) { Inventory inventory2 = ((Humanoid)localPlayer).GetInventory(); bool flag = ((inventory != val) ? (inventory == inventory2) : (fromInventory == inventory2 && SlotRules.Get(val).Accepts(item, pos.x, pos.y))); if (flag) { ((Humanoid)localPlayer).ToggleEquipped(item); } __result = flag; return false; } ISlotRule slotRule = SlotRules.Get(inventory); ISlotRule slotRule2 = SlotRules.Get(fromInventory); if (slotRule == null && slotRule2 == null) { return true; } bool flag2 = slotRule != null && !slotRule.Accepts(item, pos.x, pos.y); if (!flag2 && slotRule2 != null) { ItemData itemAt = inventory.GetItemAt(pos.x, pos.y); flag2 = itemAt != null && itemAt != item && !slotRule2.Accepts(itemAt, item.m_gridPos.x, item.m_gridPos.y); } if (!flag2) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")] internal static class ShiftClickPatch { private static bool Prefix(InventoryGui __instance, InventoryGrid grid, ItemData item, Modifier mod) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Invalid comparison between Unknown and I4 if (item == null || (int)mod != 2) { return true; } if ((Object)(object)__instance.m_dragGo != (Object)null || (Object)(object)__instance.m_currentContainer != (Object)null) { return true; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return true; } Inventory inventory = grid.GetInventory(); if (inventory == EquipmentStorage.Get()) { ((Humanoid)localPlayer).ToggleEquipped(item); return false; } if (SlotRules.IsManaged(inventory)) { ((Humanoid)localPlayer).GetInventory().MoveItemToThis(inventory, item); return false; } if ((Object)(object)grid != (Object)(object)__instance.m_playerGrid) { return true; } if (EquipmentStorage.IsSlotItem(item)) { ((Humanoid)localPlayer).ToggleEquipped(item); return false; } foreach (BagType item2 in Bags.All) { Inventory val = item2.EquippedInventory(); if (val != null && val.CanAddItem(item, -1)) { val.MoveItemToThis(((Humanoid)localPlayer).GetInventory(), item); return false; } } return true; } } [HarmonyPatch(typeof(InventoryGui), "OnSelectedItem")] internal static class DragFlagPatch { public static bool Active; [HarmonyPriority(800)] private static void Prefix() { Active = true; } private static void Finalizer() { Active = false; } } [HarmonyPatch(typeof(Humanoid), "UseItem")] internal static class UseItemPatch { private static bool Prefix(Humanoid __instance, Inventory inventory, ItemData item) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance != (Object)(object)Player.m_localPlayer || item == null || !SlotRules.IsManaged(inventory)) { return true; } if (!inventory.ContainsItem(item)) { return true; } if (inventory == EquipmentStorage.Get()) { ((Humanoid)(Player)__instance).ToggleEquipped(item); return false; } if (!Bags.IsArrow(item)) { return true; } __instance.ToggleEquipped(item); return false; } } [HarmonyPatch(typeof(InventoryGui), "Update")] internal static class InventoryGuiUpdatePatch { private static void Postfix(InventoryGui __instance) { foreach (SlotPanel item in Panels.All) { item.Update(__instance); } } } [HarmonyPatch(typeof(Player), "Update")] internal static class PlayerUpdatePatch { private static void Postfix(Player __instance) { if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer)) { EquipmentStorage.Reconcile(__instance); Hotkeys.EatFood(__instance); } } } [HarmonyPatch(typeof(Player), "UseHotbarItem")] internal static class ArrowHotkeyPatch { private static bool Prefix(Player __instance, int index) { if (!Input.GetKey((KeyCode)308) || index < 1 || index > Bags.Quiver.Slots) { return true; } Hotkeys.SelectArrow(__instance, index - 1); return false; } } [HarmonyPatch(typeof(ItemData), "IsEquipable")] internal static class IsEquipablePatch { private static void Postfix(ItemData __instance, ref bool __result) { if (!__result && EquipmentStorage.IsBag(__instance)) { __result = true; } } } [HarmonyPatch(typeof(Humanoid), "IsItemEquiped")] internal static class IsItemEquipedPatch { private static void Postfix(Humanoid __instance, ItemData item, ref bool __result) { if (!__result && !((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && EquipmentStorage.IsBag(item)) { __result = EquipmentStorage.IsInSlots(item); } } } [HarmonyPatch(typeof(Humanoid), "EquipItem")] internal static class EquipFlowPatch { private static bool Prefix(Humanoid __instance, ItemData item, ref bool __result) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)__instance != (Object)(object)localPlayer || item == null || !EquipmentStorage.IsSlotItem(item)) { return true; } if (EquipmentStorage.IsInSlots(item)) { if (!EquipmentStorage.IsBag(item)) { return true; } __result = false; return false; } if (!((Humanoid)localPlayer).GetInventory().m_inventory.Contains(item) || ((Character)localPlayer).InAttack() || ((Character)localPlayer).InDodge()) { __result = false; return false; } if (!EquipmentStorage.MoveIntoSlot(localPlayer, item)) { __result = false; return false; } if (!EquipmentStorage.IsBag(item)) { return true; } item.m_equipped = true; __result = true; return false; } } [HarmonyPatch(typeof(Humanoid), "UnequipItem")] internal static class UnequipFlowPatch { private static bool Prefix(Humanoid __instance, ItemData item) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)__instance != (Object)(object)localPlayer || item == null || !EquipmentStorage.IsInSlots(item)) { return true; } if (DragFlagPatch.Active) { return false; } if (!EquipmentStorage.MoveOutOfSlot(localPlayer, item)) { return false; } return !EquipmentStorage.IsBag(item); } } [HarmonyPatch(typeof(Player), "CreateTombStone")] internal static class TombstonePatch { private static void Prefix(Player __instance) { ZoneSystem instance = ZoneSystem.instance; bool globalKey = instance.GetGlobalKey((GlobalKeys)23); bool globalKey2 = instance.GetGlobalKey((GlobalKeys)19); EquipmentSlotsPlugin.Log.LogInfo((object)$"Death: world keeps inventory = {globalKey}, keeps equipped items = {globalKey2}"); if (!(globalKey || globalKey2)) { EquipmentStorage.MoveAllToInventory(__instance); } } } [HarmonyPatch(typeof(Player), "Save")] internal static class SavePatch { private static void Prefix(Player __instance) { if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer) { EquipmentStorage.SaveSnapshot(); } } } [HarmonyPatch(typeof(Player), "Load")] internal static class LoadPatch { private static void Postfix() { EquipmentStorage.Reset(); } } internal static class Hotkeys { public static void SelectArrow(Player player, int slot) { Inventory obj = Bags.Quiver.EquippedInventory(); ItemData val = ((obj != null) ? obj.GetItemAt(slot, 0) : null); if (val != null) { if (!((Humanoid)player).IsItemEquiped(val)) { ((Humanoid)player).EquipItem(val, false); } string arg = Localization.instance.Localize(val.m_shared.m_name); ((Character)player).Message((MessageType)1, $"Arrows: {arg} ({val.m_stack})", 0, (Sprite)null, false); } } public static void EatFood(Player player) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) if (!((Character)player).TakeInput()) { return; } Inventory val = Bags.Foodbag.EquippedInventory(); if (val == null) { return; } ConfigEntry<KeyboardShortcut>[] eatKeys = EquipmentSlotsPlugin.EatKeys; for (int i = 0; i < eatKeys.Length; i++) { KeyboardShortcut value = eatKeys[i].Value; if (((KeyboardShortcut)(ref value)).IsDown()) { ItemData itemAt = val.GetItemAt(i, 0); EquipmentSlotsPlugin.Log.LogInfo((object)string.Format("Eat key {0} pressed, food: {1}", i + 1, itemAt?.m_shared.m_name ?? "none in this slot")); if (itemAt != null) { ((Humanoid)player).UseItem(val, itemAt, true); } break; } } } } internal enum PanelPlacement { RightOfInventory, BelowInventoryLeft, BelowInventoryRight } internal sealed class SlotPanel { private const float Padding = 24f; private const float Gap = 8f; private readonly Func<Inventory> _inventory; private readonly int _columns; private readonly int _rows; private readonly string _title; private readonly string[] _slotLabels; private readonly PanelPlacement _placement; private readonly Action<Inventory> _syncMarkers; private RectTransform _panel; private InventoryGrid _grid; private TMP_Text _titleText; private GameObject _labelTemplate; private List<TMP_Text> _labels; public InventoryGrid Grid => _grid; public SlotPanel(Func<Inventory> inventory, int columns, int rows, PanelPlacement placement, string title = null, string[] slotLabels = null, Action<Inventory> syncMarkers = null) { _inventory = inventory; _columns = columns; _rows = rows; _placement = placement; _title = title; _slotLabels = slotLabels; _syncMarkers = syncMarkers; } public void Update(InventoryGui gui) { Inventory val = (InventoryGui.IsVisible() ? _inventory() : null); bool flag = val != null; if ((Object)(object)_panel == (Object)null) { if (!flag) { return; } Create(gui); } if (((Component)_panel).gameObject.activeSelf != flag) { ((Component)_panel).gameObject.SetActive(flag); } if (flag) { Place(gui); _syncMarkers?.Invoke(val); if ((Object)(object)_titleText != (Object)null) { _titleText.text = _title; } _grid.UpdateInventory(val, Player.m_localPlayer, gui.m_dragItem); UpdateElements(val); } } private void Create(InventoryGui gui) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0206: 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_023e: Unknown result type (might be due to invalid IL or missing references) //IL_022d: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Unknown result type (might be due to invalid IL or missing references) RectTransform container = gui.m_container; GameObject val = Object.Instantiate<GameObject>(((Component)container).gameObject, ((Transform)container).parent); ((Object)val).name = "NathansSlotPanel"; _panel = (RectTransform)val.transform; _grid = val.GetComponentInChildren<InventoryGrid>(true); _labels = null; foreach (Transform item in (Transform)_grid.m_gridRoot) { Object.Destroy((Object)(object)((Component)item).gameObject); } Transform transform = ((Component)gui.m_containerGrid).transform; RemoveClonedPart((Transform)(object)container, transform, ((Component)gui.m_takeAllButton).transform); RemoveClonedPart((Transform)(object)container, transform, ((Component)gui.m_stackAllButton).transform); RemoveClonedPart((Transform)(object)container, transform, gui.m_containerWeight.transform); Transform val2 = CloneOf((Transform)(object)container, gui.m_containerName.transform); _labelTemplate = ((Component)val2).gameObject; if (_title != null) { _titleText = ((Component)val2).GetComponent<TMP_Text>(); } else { _labelTemplate.SetActive(false); } InventoryGrid grid = _grid; grid.m_onSelected = (Action<InventoryGrid, ItemData, Vector2i, Modifier>)Delegate.Combine(grid.m_onSelected, new Action<InventoryGrid, ItemData, Vector2i, Modifier>(gui.OnSelectedItem)); InventoryGrid grid2 = _grid; grid2.m_onReleased = (Action<InventoryGrid, ItemData, Vector2i>)Delegate.Combine(grid2.m_onReleased, new Action<InventoryGrid, ItemData, Vector2i>(gui.OnReleasedItem)); InventoryGrid grid3 = _grid; grid3.m_onRightClick = (Action<InventoryGrid, ItemData, Vector2i>)Delegate.Combine(grid3.m_onRightClick, new Action<InventoryGrid, ItemData, Vector2i>(gui.OnRightClickItem)); InventoryGrid grid4 = _grid; grid4.m_onEnter = (Action<InventoryGrid, Vector2i>)Delegate.Combine(grid4.m_onEnter, new Action<InventoryGrid, Vector2i>(gui.OnEnterElement)); InventoryGrid grid5 = _grid; grid5.CanDropDragOntoItem = (Func<ItemData, bool>)Delegate.Combine(grid5.CanDropDragOntoItem, new Func<ItemData, bool>(gui.CanDropDragOntoItem)); float elementSpace = _grid.m_elementSpace; RectTransform panel = _panel; RectTransform panel2 = _panel; Vector2 val3 = default(Vector2); ((Vector2)(ref val3))..ctor(0.5f, 0.5f); panel2.anchorMax = val3; panel.anchorMin = val3; _panel.pivot = ((_placement == PanelPlacement.BelowInventoryRight) ? new Vector2(1f, 1f) : new Vector2(0f, 1f)); _panel.sizeDelta = new Vector2((float)_columns * elementSpace + 48f, (float)_rows * elementSpace + 48f); EquipmentSlotsPlugin.Log.LogInfo((object)("Slot panel created. Hierarchy:\n" + Dump((Transform)(object)_panel, 0))); } private void RemoveClonedPart(Transform source, Transform grid, Transform original) { Transform val = original; while ((Object)(object)val.parent != (Object)null && (Object)(object)val.parent != (Object)(object)source && !grid.IsChildOf(val.parent)) { val = val.parent; } if (!grid.IsChildOf(val)) { Transform obj = CloneOf(source, val); ((Component)obj).gameObject.SetActive(false); Object.Destroy((Object)(object)((Component)obj).gameObject); } } private Transform CloneOf(Transform source, Transform original) { Stack<int> stack = new Stack<int>(); Transform val = original; while ((Object)(object)val != (Object)(object)source) { stack.Push(val.GetSiblingIndex()); val = val.parent; } Transform val2 = (Transform)(object)_panel; foreach (int item in stack) { val2 = val2.GetChild(item); } return val2; } private void Place(InventoryGui gui) { //IL_0021: 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_009a: 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_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00be: 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_00c9: 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) Vector3[] array = (Vector3[])(object)new Vector3[4]; Vector3 position = default(Vector3); if (_placement == PanelPlacement.RightOfInventory) { gui.m_player.GetWorldCorners(array); float y = ((Transform)gui.m_player).lossyScale.y; ((Vector3)(ref position))..ctor(array[2].x + EquipmentSlotsPlugin.PanelOffsetX.Value * y, array[2].y - EquipmentSlotsPlugin.PanelOffsetY.Value * y, array[2].z); } else { RectTransform obj = (((Component)gui.m_container).gameObject.activeSelf ? gui.m_container : gui.m_player); obj.GetWorldCorners(array); float y2 = ((Transform)obj).lossyScale.y; Vector3 val = ((_placement == PanelPlacement.BelowInventoryLeft) ? array[0] : array[3]); ((Vector3)(ref position))..ctor(val.x, val.y - 8f * y2, val.z); } ((Transform)_panel).position = position; } private void UpdateElements(Inventory inventory) { List<InventoryElement> elements = _grid.m_elements; if (elements.Count != _columns * _rows) { return; } if (_labels == null) { CreateLabels(elements); } for (int i = 0; i < elements.Count; i++) { InventoryElement val = elements[i]; bool flag = _slotLabels != null && string.IsNullOrEmpty(_slotLabels[i]); if (((Component)val).gameObject.activeSelf == flag) { ((Component)val).gameObject.SetActive(!flag); } Transform val2 = ((Component)val).transform.Find("binding"); TMP_Text val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<TMP_Text>() : null); if ((Object)(object)val3 != (Object)null) { ((Behaviour)val3).enabled = false; } if ((Object)(object)_labels[i] != (Object)null) { ((Behaviour)_labels[i]).enabled = inventory.GetItemAt(i % _columns, i / _columns) == null; } } } private void CreateLabels(List<InventoryElement> elements) { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: 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_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008d: 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_00a2: 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_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) _labels = new List<TMP_Text>(); for (int i = 0; i < elements.Count; i++) { if (_slotLabels == null || string.IsNullOrEmpty(_slotLabels[i])) { _labels.Add(null); continue; } GameObject obj = Object.Instantiate<GameObject>(_labelTemplate, ((Component)elements[i]).transform); obj.SetActive(true); RectTransform val = (RectTransform)obj.transform; val.anchorMin = new Vector2(0f, 0.5f); val.anchorMax = new Vector2(1f, 0.5f); val.pivot = new Vector2(0.5f, 0.5f); val.anchoredPosition = Vector2.zero; val.sizeDelta = new Vector2(0f, 24f); TMP_Text component = obj.GetComponent<TMP_Text>(); component.text = _slotLabels[i]; component.fontSize = 18f; component.alignment = (TextAlignmentOptions)514; ((Graphic)component).raycastTarget = false; ((Graphic)component).color = new Color(1f, 1f, 1f, 0.55f); _labels.Add(component); } } private static string Dump(Transform t, int depth) { //IL_0033: 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_0049: 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_00c2: Expected O, but got Unknown StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(new string(' ', depth * 2)).Append(((Object)t).name); RectTransform val = (RectTransform)(object)((t is RectTransform) ? t : null); if (val != null) { stringBuilder.Append($" anchors={val.anchorMin}-{val.anchorMax} size={val.sizeDelta}"); } stringBuilder.Append(" [").Append(string.Join(",", Array.ConvertAll(((Component)t).GetComponents<Component>(), (Component c) => ((object)c).GetType().Name))).Append("]\n"); foreach (Transform item in t) { Transform t2 = item; stringBuilder.Append(Dump(t2, depth + 1)); } return stringBuilder.ToString(); } } internal static class Panels { public static readonly SlotPanel EquipmentPanel = new SlotPanel(EquipmentStorage.Get, 2, 4, PanelPlacement.RightOfInventory, null, EquipmentStorage.Titles); public static readonly SlotPanel QuiverPanel = new SlotPanel(Bags.Quiver.EquippedInventory, Bags.Quiver.Slots, 1, PanelPlacement.BelowInventoryLeft, Bags.Quiver.Title, null, MarkEquippedAmmo); public static readonly SlotPanel FoodbagPanel = new SlotPanel(Bags.Foodbag.EquippedInventory, Bags.Foodbag.Slots, 1, PanelPlacement.BelowInventoryRight, Bags.Foodbag.Title); public static IEnumerable<SlotPanel> All => new SlotPanel[3] { EquipmentPanel, QuiverPanel, FoodbagPanel }; private static void MarkEquippedAmmo(Inventory quiver) { ItemData ammoItem = ((Humanoid)Player.m_localPlayer).GetAmmoItem(); foreach (ItemData allItem in quiver.GetAllItems()) { allItem.m_equipped = allItem == ammoItem; } } } internal interface ISlotRule { bool Accepts(ItemData item, int x, int y); bool CanAcceptAnywhere(Inventory inventory, ItemData item); } internal static class SlotRules { private static readonly ConditionalWeakTable<Inventory, ISlotRule> Rules = new ConditionalWeakTable<Inventory, ISlotRule>(); public static void Register(Inventory inventory, ISlotRule rule) { Rules.Add(inventory, rule); } public static ISlotRule Get(Inventory inventory) { if (inventory == null || !Rules.TryGetValue(inventory, out var value)) { return null; } return value; } public static bool IsManaged(Inventory inventory) { return Get(inventory) != null; } public static bool IsPlayerInventory(Inventory inventory) { if ((Object)(object)Player.m_localPlayer != (Object)null) { return inventory == ((Humanoid)Player.m_localPlayer).GetInventory(); } return false; } } } namespace NathansQol.EquipmentSlots.Quiver { internal static class FoodHud { private static bool _built; private static bool _failed; private static GameObject[] _arrowRows; private static RectTransform[] _sourceRows; private static Vector2[] _sourcePositions; private static Image[] _arrowIcons; private static TMP_Text[] _arrowLabels; private static TMP_Text[] _keyLabels; private static int _rows; public static void Update(Hud hud) { //IL_0210: Unknown result type (might be due to invalid IL or missing references) //IL_0215: 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_0191: 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_01c7: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; Inventory val = (((Object)(object)localPlayer != (Object)null) ? Bags.Quiver.EquippedInventory() : null); Inventory val2 = (((Object)(object)localPlayer != (Object)null) ? Bags.Foodbag.EquippedInventory() : null); if (_failed) { return; } if (_built && ((Object)(object)_sourceRows[0] == (Object)null || (Object)(object)_arrowRows[0] == (Object)null)) { _built = false; EquipmentSlotsPlugin.Log.LogInfo((object)"Food HUD was rebuilt by the game, copying it again"); } if (!_built) { if (val == null && val2 == null) { return; } try { Build(hud); } catch (Exception arg) { _failed = true; EquipmentSlotsPlugin.Log.LogError((object)$"Could not build the food/arrow HUD: {arg}"); return; } } try { PlaceArrowRows(hud); } catch (Exception arg2) { _failed = true; EquipmentSlotsPlugin.Log.LogError((object)$"The arrow display stopped working: {arg2}"); return; } ItemData val3 = (((Object)(object)localPlayer != (Object)null) ? ((Humanoid)localPlayer).GetAmmoItem() : null); for (int i = 0; i < _rows; i++) { ItemData val4 = ((val != null) ? val.GetItemAt(i, 0) : null); bool flag = val4 != null; _arrowRows[i].SetActive(val != null); ((Component)_arrowIcons[i]).gameObject.SetActive(flag); ((Component)_arrowLabels[i]).gameObject.SetActive(flag); if (flag) { bool flag2 = val4 == val3; _arrowIcons[i].sprite = val4.GetIcon(); ((Graphic)_arrowIcons[i]).color = new Color(1f, 1f, 1f, flag2 ? 1f : 0.6f); _arrowLabels[i].text = $"Alt+{i + 1}"; ((Graphic)_arrowLabels[i]).color = (Color)(flag2 ? new Color(1f, 0.85f, 0.4f) : Color.white); } ((Component)_keyLabels[i]).gameObject.SetActive(val2 != null); if (val2 != null) { TMP_Text obj = _keyLabels[i]; KeyboardShortcut value = EquipmentSlotsPlugin.EatKeys[i].Value; obj.text = ((object)((KeyboardShortcut)(ref value)).MainKey/*cast due to .constrained prefix*/).ToString(); } } } private static void Build(Hud hud) { //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Expected O, but got Unknown //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013f: 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) _rows = Mathf.Min(Bags.Quiver.Slots, hud.m_foodIcons.Length); _arrowRows = (GameObject[])(object)new GameObject[_rows]; _sourceRows = (RectTransform[])(object)new RectTransform[_rows]; _sourcePositions = (Vector2[])(object)new Vector2[_rows]; _arrowIcons = (Image[])(object)new Image[_rows]; _arrowLabels = (TMP_Text[])(object)new TMP_Text[_rows]; _keyLabels = (TMP_Text[])(object)new TMP_Text[_rows]; EquipmentSlotsPlugin.Log.LogInfo((object)("Food HUD hierarchy:\n" + Dump(((Component)hud.m_foodIcons[0]).transform.parent.parent, 0, 3))); Vector2 offset = default(Vector2); ((Vector2)(ref offset))..ctor(0f - EquipmentSlotsPlugin.FoodKeyHudOffsetX.Value, 0f); for (int i = 0; i < _rows; i++) { int num = _rows - 1 - i; Transform parent = ((Component)hud.m_foodIcons[num]).transform.parent; GameObject rowCopy = Object.Instantiate<GameObject>(((Component)parent).gameObject, parent.parent); ((Object)rowCopy).name = "NathansArrowRow" + i; _sourceRows[i] = (RectTransform)parent; _sourcePositions[i] = ((RectTransform)parent).anchoredPosition; _arrowRows[i] = rowCopy; _arrowIcons[i] = rowCopy.GetComponentsInChildren<Image>(true).First((Image val) => (Object)(object)((Component)val).gameObject != (Object)(object)rowCopy); _arrowLabels[i] = rowCopy.GetComponentInChildren<TMP_Text>(true); _arrowLabels[i].textWrappingMode = (TextWrappingModes)0; _arrowLabels[i].overflowMode = (TextOverflowModes)0; _keyLabels[i] = Copy<TMP_Text>(hud.m_foodTime[i], offset); _keyLabels[i].textWrappingMode = (TextWrappingModes)0; _keyLabels[i].overflowMode = (TextOverflowModes)0; } _built = true; } private static void PlaceArrowRows(Hud hud) { //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0063: 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_007c: Unknown result type (might be due to invalid IL or missing references) //IL_00af: 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_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) Vector3[] array = (Vector3[])(object)new Vector3[4]; ((Graphic)hud.m_gpIcon).rectTransform.GetWorldCorners(array); float num = array[2].x; TMP_Text[] array2 = (TMP_Text[])(object)new TMP_Text[2] { hud.m_gpName, hud.m_gpCooldown }; foreach (TMP_Text val in array2) { if (!((Object)(object)val == (Object)null)) { Transform transform = val.transform; Bounds textBounds = val.textBounds; float x = transform.TransformPoint(new Vector3(((Bounds)(ref textBounds)).max.x, 0f, 0f)).x; num = Mathf.Max(num, x); } } for (int j = 0; j < _rows; j++) { RectTransform obj = _sourceRows[j]; obj.GetWorldCorners(array); float x2 = ((Transform)obj).lossyScale.x; float num2 = (num - array[0].x) / x2 + EquipmentSlotsPlugin.ArrowHudOffsetX.Value; ((RectTransform)_arrowRows[j].transform).anchoredPosition = _sourcePositions[j] + new Vector2(num2, 0f); } } private static T Copy<T>(T original, Vector2 offset) where T : Component { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: 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_004c: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) GameObject obj = Object.Instantiate<GameObject>(((Component)original).gameObject, ((Component)original).transform.parent); ((Object)obj).name = "Nathans" + ((Object)(object)original).name; RectTransform val = (RectTransform)obj.transform; val.anchoredPosition += offset; return obj.GetComponent<T>(); } private static string Dump(Transform t, int depth, int maxDepth) { //IL_0033: 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_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Expected O, but got Unknown StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append(new string(' ', depth * 2)).Append(((Object)t).name); RectTransform val = (RectTransform)(object)((t is RectTransform) ? t : null); if (val != null) { stringBuilder.Append($" pos={val.anchoredPosition} size={val.sizeDelta}"); } stringBuilder.Append(" [").Append(string.Join(",", Array.ConvertAll(((Component)t).GetComponents<Component>(), (Component c) => ((object)c).GetType().Name))).Append("]\n"); if (depth < maxDepth) { foreach (Transform item in t) { Transform t2 = item; stringBuilder.Append(Dump(t2, depth + 1, maxDepth)); } } return stringBuilder.ToString(); } } [HarmonyPatch(typeof(Hud), "Update")] internal static class HudUpdatePatch { private static void Postfix(Hud __instance) { FoodHud.Update(__instance); } } internal static class QuiverFeature { public static void Init() { PrefabManager.OnVanillaPrefabsAvailable += RegisterPrefabs; } private static void RegisterPrefabs() { PrefabManager.OnVanillaPrefabsAvailable -= RegisterPrefabs; CreateQuiverItem(); FoodbagFeature.CreateItem(); } private static void CreateQuiverItem() { //IL_0038: 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_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008d: 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_00a0: Expected O, but got Unknown //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Expected O, but got Unknown GameObject val = PrefabManager.Instance.CreateClonedPrefab(Bags.Quiver.PrefabName, "LeatherScraps"); ApplyModel(val, QuiverMesh.Build()); SharedData shared = val.GetComponent<ItemDrop>().m_itemData.m_shared; shared.m_itemType = (ItemType)16; shared.m_maxStackSize = 1; shared.m_equipDuration = 1f; shared.m_weight = 2f; shared.m_icons = (Sprite[])(object)new Sprite[1] { LoadSprite("quiver_icon.png") }; ItemConfig val2 = new ItemConfig { Name = "Quiver", Description = "A leather quiver with three arrow slots. Put it in the quiver equipment slot to use it.", CraftingStation = "piece_workbench", MinStationLevel = 2 }; val2.AddRequirement("LeatherScraps", 15, 0); val2.AddRequirement("DeerHide", 10, 0); val2.AddRequirement("TrollHide", 5, 0); ItemManager.Instance.AddItem(new CustomItem(val, false, val2)); } internal static void ApplyModel(GameObject prefab, Mesh mesh) { //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Expected O, but got Unknown MeshFilter val = prefab.GetComponentsInChildren<MeshFilter>(true).First(); MeshRenderer renderer = ((Component)val).GetComponent<MeshRenderer>(); val.sharedMesh = mesh; Texture2D val2 = LoadTexture("quiver_atlas.png"); ((Texture)val2).filterMode = (FilterMode)0; Material val3 = new Material(((Renderer)renderer).sharedMaterial) { mainTexture = (Texture)(object)val2 }; ((Renderer)renderer).sharedMaterials = (Material[])(object)new Material[1] { val3 }; foreach (Renderer item in from r in prefab.GetComponentsInChildren<Renderer>(true) where (Object)(object)r != (Object)(object)renderer select r) { item.enabled = false; } } private static byte[] ReadResource(string name) { using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name); if (stream == null) { throw new FileNotFoundException("Embedded resource " + name + " not found"); } using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); return memoryStream.ToArray(); } internal static Texture2D LoadTexture(string name) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Expected O, but got Unknown Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); typeof(ImageConversion).GetMethod("LoadImage", new Type[3] { typeof(Texture2D), typeof(byte[]), typeof(bool) }).Invoke(null, new object[3] { val, ReadResource(name), false }); return val; } internal static Sprite LoadSprite(string name) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) Texture2D val = LoadTexture(name); return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)); } } internal static class QuiverMesh { internal sealed class Builder { private readonly List<Vector3> _v = new List<Vector3>(); private readonly List<Vector2> _uv = new List<Vector2>(); private readonly List<int> _t = new List<int>(); private static Vector2 Mid(Rect r) { //IL_002a: Unknown result type (might be due to invalid IL or missing references) return new Vector2(((Rect)(ref r)).x + ((Rect)(ref r)).width * 0.5f, ((Rect)(ref r)).y + ((Rect)(ref r)).height * 0.5f); } public void Tri(Vector3 a, Vector3 b, Vector3 c, Vector3 outward, Rect uv) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //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_0007: 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_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_006b: 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) bool num = Vector3.Dot(Vector3.Cross(b - a, c - a), outward) < 0f; int count = _v.Count; _v.Add(a); _v.Add(b); _v.Add(c); Vector2 item = Mid(uv); _uv.Add(item); _uv.Add(item); _uv.Add(item); if (num) { _t.Add(count); _t.Add(count + 2); _t.Add(count + 1); } else { _t.Add(count); _t.Add(count + 1); _t.Add(count + 2); } } public void Quad(Vector3 a, Vector3 b, Vector3 c, Vector3 d, Vector3 outward, Rect uv, bool doubleSided = false) { //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_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000e: 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) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0021: 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_0023: 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_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0033: 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_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0039: 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) Tri(a, b, c, outward, uv); Tri(a, c, d, outward, uv); if (doubleSided) { Tri(a, b, c, -outward, uv); Tri(a, c, d, -outward, uv); } } private static Vector3 Ring(int i, float r, float y) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) float num = (float)i * (float)Math.PI * 2f / 8f; return new Vector3(r * Mathf.Cos(num), y, r * Mathf.Sin(num)); } public void Prism(float y0, float y1, float r0, float r1, Rect uv, bool capBottom, bool capTop) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0028: 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) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0048: 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) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_006f: 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_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: 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) for (int i = 0; i < 8; i++) { int i2 = (i + 1) % 8; Vector3 outward = Ring(i, 1f, 0f) + Ring(i2, 1f, 0f); Quad(Ring(i, r0, y0), Ring(i2, r0, y0), Ring(i2, r1, y1), Ring(i, r1, y1), outward, uv); if (capBottom) { Tri(new Vector3(0f, y0, 0f), Ring(i, r0, y0), Ring(i2, r0, y0), Vector3.down, uv); } if (capTop) { Tri(new Vector3(0f, y1, 0f), Ring(i, r1, y1), Ring(i2, r1, y1), Vector3.up, uv); } } } public void Disc(float y, float r, Rect uv) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0018: 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) for (int i = 0; i < 8; i++) { Tri(new Vector3(0f, y, 0f), Ring(i, r, y), Ring((i + 1) % 8, r, y), Vector3.up, uv); } } public void Box(Vector3 center, Vector3 half, Rect uv, Vector2 uvOverride) { //IL_0002: 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_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: 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_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: 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_00ba: 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_00bc: 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_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: 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_00cc: 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_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: 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_00e0: 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_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: 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_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_00fe: Unknown result type (might be due to invalid IL or missing references) //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_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0110: 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_0117: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) Rect uv2 = default(Rect); ((Rect)(ref uv2))..ctor(uvOverride.x - 0.05f, uvOverride.y - 0.05f, 0.1f, 0.1f); Vector3[] array = (Vector3[])(object)new Vector3[6] { Vector3.right, Vector3.left, Vector3.up, Vector3.down, Vector3.forward, Vector3.back }; foreach (Vector3 val in array) { Vector3 val2 = ((Mathf.Abs(val.y) > 0.5f) ? Vector3.right : Vector3.up); Vector3 val3 = Vector3.Cross(val, val2); Vector3 normalized = ((Vector3)(ref val3)).normalized; Vector3 val4 = center + Vector3.Scale(val, half); Vector3 val5 = Vector3.Scale(val2, half); Vector3 val6 = Vector3.Scale(normalized, half); Quad(val4 - val5 - val6, val4 + val5 - val6, val4 + val5 + val6, val4 - val5 + val6, val, uv2); } } public void Rod(Vector3 from, Vector3 to, float r, Rect uv) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //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_0007: 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_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) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_003d: 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_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: 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_004c: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002b: 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_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: 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_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_00cc: 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_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: 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_00dc: 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) //IL_00e4: 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_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: 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_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Unknown result type (might be due to invalid IL or missing references) Vector3 val = to - from; Vector3 normalized = ((Vector3)(ref val)).normalized; Vector3 val2 = Vector3.Cross(normalized, Vector3.forward); if (((Vector3)(ref val2)).sqrMagnitude < 0.001f) { val2 = Vector3.Cross(normalized, Vector3.right); } ((Vector3)(ref val2)).Normalize(); val = Vector3.Cross(normalized, val2); Vector3 normalized2 = ((Vector3)(ref val)).normalized; for (int i = 0; i < 4; i++) { float num = (float)i * (float)Math.PI * 2f / 4f; float num2 = (float)(i + 1) * (float)Math.PI * 2f / 4f; Vector3 val3 = (val2 * Mathf.Cos(num) + normalized2 * Mathf.Sin(num)) * r; Vector3 val4 = (val2 * Mathf.Cos(num2) + normalized2 * Mathf.Sin(num2)) * r; Quad(from + val3, from + val4, to + val4, to + val3, val3 + val4, uv); } } public Mesh ToMesh(string name) { //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_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Expected O, but got Unknown Mesh val = new Mesh { name = name }; val.SetVertices(_v.ConvertAll((Vector3 v) => v * 4.25f)); val.SetUVs(0, _uv); val.SetTriangles(_t, 0); val.RecalculateNormals(); val.RecalculateBounds(); return val; } } private const int Sides = 8; private const float Scale = 4.25f; internal static readonly Rect Leather = Cell(0, 1); internal static readonly Rect DarkLeather = Cell(1, 1); internal static readonly Rect Wood = Cell(0, 0); internal static readonly Rect Feather = Cell(1, 0); private static Rect Cell(int x, int y) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) return new Rect((float)x * 0.5f + 0.1f, (float)y * 0.5f + 0.1f, 0.3f, 0.3f); } public static Mesh Build() { //IL_001b: 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_0051: 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_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: 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_00ed: 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_00fd: 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_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0122: 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_0125: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0176: Unknown result type (might be due to invalid IL or missing references) //IL_0190: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Unknown result type (might be due to invalid IL or missing references) Builder builder = new Builder(); builder.Prism(-0.25f, 0.2f, 0.052f, 0.068f, Leather, capBottom: true, capTop: false); builder.Disc(0.19f, 0.06f, DarkLeather); builder.Prism(-0.215f, -0.17f, 0.058f, 0.06f, DarkLeather, capBottom: true, capTop: true); builder.Prism(0.12f, 0.17f, 0.066f, 0.069f, DarkLeather, capBottom: true, capTop: true); builder.Prism(0.185f, 0.205f, 0.068f, 0.072f, DarkLeather, capBottom: false, capTop: false); builder.Box(new Vector3(0.06f, -0.192f, 0f), new Vector3(0.012f, 0.035f, 0.03f), Feather, new Vector2(0.75f, 0.12f)); Vector3 val3 = default(Vector3); for (int i = 0; i < 8; i++) { Vector3 val = StrapPoint((float)i / 8f); Vector3 val2 = StrapPoint((float)(i + 1) / 8f); ((Vector3)(ref val3))..ctor(0f, 0f, 0.014f); builder.Quad(val - val3, val + val3, val2 + val3, val2 - val3, Vector3.right, DarkLeather, doubleSided: true); } Arrow(builder, new Vector3(-0.02f, 0.15f, 0.01f), new Vector3(-0.045f, 0.38f, 0.02f)); Arrow(builder, new Vector3(0.015f, 0.15f, -0.015f), new Vector3(0.02f, 0.4f, -0.025f)); Arrow(builder, new Vector3(0.01f, 0.15f, 0.025f), new Vector3(0.05f, 0.37f, 0.04f)); return builder.ToMesh("NathansQuiver"); } private static Vector3 StrapPoint(float t) { //IL_002d: Unknown result type (might be due to invalid IL or missing references) return new Vector3(0.072f + 0.075f * Mathf.Sin((float)Math.PI * t), Mathf.Lerp(0.15f, -0.192f, t), 0f); } private static void Arrow(Builder b, Vector3 from, Vector3 to) { //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_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001d: 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_0023: 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_0050: 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) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: 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_0060: 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_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: 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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008e: 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_0097: Unknown result type (might be due to invalid IL or missing references) //IL_003d: 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_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: 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_00ba: 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_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: 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_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: 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_00d8: 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_00df: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: 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_00e7: 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) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) b.Rod(from, to, 0.0065f, Wood); Vector3 val = to - from; Vector3 normalized = ((Vector3)(ref val)).normalized; Vector3 val2 = Vector3.Cross(normalized, Vector3.forward); if (((Vector3)(ref val2)).sqrMagnitude < 0.001f) { val2 = Vector3.Cross(normalized, Vector3.right); } ((Vector3)(ref val2)).Normalize(); val = Vector3.Cross(normalized, val2); Vector3 normalized2 = ((Vector3)(ref val)).normalized; Vector3 val3 = to - normalized * 0.075f; Vector3 val4 = to - normalized * 0.008f; Vector3[] array = (Vector3[])(object)new Vector3[2] { val2, normalized2 }; foreach (Vector3 val5 in array) { Vector3 val6 = val5 * 0.02f; Vector3 a = val3 - val6; Vector3 b2 = val3 + val6; Vector3 c = val4 + val6; Vector3 d = val4 - val6; val = Vector3.Cross(normalized, val5); b.Quad(a, b2, c, d, ((Vector3)(ref val)).normalized, Feather, doubleSided: true); } } } } namespace NathansQol.EquipmentSlots.Foodbag { internal static class FoodbagFeature { public static void CreateItem() { //IL_0038: 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_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008d: 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_00a0: Expected O, but got Unknown //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Expected O, but got Unknown GameObject val = PrefabManager.Instance.CreateClonedPrefab(Bags.Foodbag.PrefabName, "LeatherScraps"); QuiverFeature.ApplyModel(val, FoodbagMesh.Build()); SharedData shared = val.GetComponent<ItemDrop>().m_itemData.m_shared; shared.m_itemType = (ItemType)16; shared.m_maxStackSize = 1; shared.m_equipDuration = 1f; shared.m_weight = 1f; shared.m_icons = (Sprite[])(object)new Sprite[1] { QuiverFeature.LoadSprite("foodbag_icon.png") }; ItemConfig val2 = new ItemConfig { Name = "Food bag", Description = "A leather pouch with three food slots. Put it in the food bag equipment slot to use it; eat the food in its slots with the food hotkeys.", CraftingStation = "piece_workbench", MinStationLevel = 1 }; val2.AddRequirement("LeatherScraps", 5, 0); ItemManager.Instance.AddItem(new CustomItem(val, false, val2)); } } internal static class FoodbagMesh { public static Mesh Build() { //IL_001a: 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_005c: Unknown result type (might be due to invalid IL or missing references) //IL_007d: 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) QuiverMesh.Builder builder = new QuiverMesh.Builder(); builder.Prism(-0.06f, 0f, 0.048f, 0.064f, QuiverMesh.Leather, capBottom: true, capTop: false); builder.Prism(0f, 0.045f, 0.064f, 0.04f, QuiverMesh.Leather, capBottom: false, capTop: false); builder.Prism(0.035f, 0.058f, 0.042f, 0.046f, QuiverMesh.DarkLeather, capBottom: true, capTop: true); builder.Prism(0.058f, 0.09f, 0.04f, 0.062f, QuiverMesh.Leather, capBottom: false, capTop: false); builder.Disc(0.088f, 0.05f, QuiverMesh.DarkLeather); return builder.ToMesh("NathansFoodbag"); } } } namespace NathansQol.EquipmentSlots.Equipment { internal static class EquipmentStorage { private enum Slot { Head, Back, Chest, Accessory, Legs, Trinket, Quiver, Foodbag } private sealed class Rule : ISlotRule { public bool Accepts(ItemData item, int x, int y) { int num = y * 2 + x; if (item == null || item.m_shared.m_questItem || num < 0 || num >= Layout.Length) { return false; } return Fits(Layout[num], item); } public bool CanAcceptAnywhere(Inventory inventory, ItemData item) { return FindFreeSlot(inventory, item).HasValue; } } public const int Columns = 2; public const int Rows = 4; private const string DataKey = "nathan.equip.inv"; private const string PendingKey = "nathan.equip.pending"; private static readonly Slot[] Layout = new Slot[8] { Slot.Head, Slot.Back, Slot.Chest, Slot.Accessory, Slot.Legs, Slot.Trinket, Slot.Quiver, Slot.Foodbag }; public static readonly string[] Titles = new string[8] { "Head", "Back", "Chest", "Accessory", "Legs", "Trinket", "Quiver", "Food bag" }; private static Player _owner; private static Inventory _inventory; private static bool Fits(Slot slot, ItemData item) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: 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_0036: Invalid comparison between Unknown and I4 //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Invalid comparison between Unknown and I4 //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Invalid comparison between Unknown and I4 //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Invalid comparison between Unknown and I4 //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Invalid comparison between Unknown and I4 //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Invalid comparison between Unknown and I4 ItemType itemType = item.m_shared.m_itemType; return slot switch { Slot.Head => (int)itemType == 6, Slot.Back => (int)itemType == 17, Slot.Chest => (int)itemType == 7, Slot.Accessory => (int)itemType == 18, Slot.Legs => (int)itemType == 11, Slot.Trinket => (int)itemType == 24, Slot.Quiver => Bags.Quiver.IsBag(item), Slot.Foodbag => Bags.Foodbag.IsBag(item), _ => false, }; } public static Inventory Get() { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Expected O, but got Unknown Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return null; } if (_inventory != null && (Object)(object)_owner == (Object)(object)localPlayer) { return _inventory; } _owner = localPlayer; _inventory = new Inventory("Equipment", (Sprite)null, 2, 4); SlotRules.Register(_inventory, new Rule()); if (localPlayer.m_customData.TryGetValue("nathan.equip.inv", out var value) && !string.IsNullOrEmpty(value)) { try { _inventory.Load(new ZPackage(value)); } catch (Exception arg) { EquipmentSlotsPlugin.Log.LogError((object)$"Could not load equipment slots: {arg}"); } } EquipmentSlotsPlugin.Log.LogInfo((object)string.Format("Equipment slots loaded: {0} item(s), saved data present: {1}", _inventory.NrOfItems(), localPlayer.m_customData.ContainsKey("nathan.equip.inv"))); Inventory inventory = _inventory; inventory.m_onChanged = (Action)Delegate.Combine(inventory.m_onChanged, new Action(SaveSnapshot)); return _inventory; } public static void SaveSnapshot() { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown if (_inventory != null && !((Object)(object)_owner == (Object)null)) { ZPackage val = new ZPackage(); _inventory.Save(val); _owner.m_customData["nathan.equip.inv"] = val.GetBase64(); } } public static void Reset() { _inventory = null; _owner = null; } public static ItemData FindItem(Func<ItemData, bool> predicate) { Inventory obj = Get(); if (obj == null) { return null; } return obj.GetAllItems().FirstOrDefault(predicate); } public static bool IsInSlots(ItemData item) { if (item != null && Get() != null) { return Get().GetAllItems().Contains(item); } return false; } public static bool IsSlotItem(ItemData item) { if (item != null) { return SlotFor(item).HasValue; } return false; } public static bool IsBag(ItemData item) { if (!Bags.Quiver.IsBag(item)) { return Bags.Foodbag.IsBag(item); } return true; } public static Vector2i? SlotFor(ItemData item) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) if (item == null || item.m_shared.m_questItem) { return null; } for (int i = 0; i < Layout.Length; i++) { if (Fits(Layout[i], item)) { return new Vector2i(i % 2, i / 2); } } return null; } public static Vector2i? FindFreeSlot(Inventory inventory, ItemData item) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) Vector2i? result = SlotFor(item); if (!result.HasValue || inventory.GetItemAt(result.Value.x, result.Value.y) != null) { return null; } return result; } private static void Transfer(Inventory from, Inventory to, ItemData item, Vector2i position) { //IL_000e: 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) from.m_inventory.Remove(item); item.m_gridPos = position; to.m_inventory.Add(item); from.Changed(false, false); to.Changed(false, false); } public static bool MoveIntoSlot(Player player, ItemData item) { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0056: 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_0049: 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_0089: 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_00a2: Unknown result type (might be due to invalid IL or missing references) Inventory val = Get(); Vector2i? val2 = SlotFor(item); if (val == null || !val2.HasValue) { return false; } Inventory inventory = ((Humanoid)player).GetInventory(); ItemData itemAt = val.GetItemAt(val2.Value.x, val2.Value.y); if (itemAt == null) { Transfer(inventory, val, item, val2.Value); return true; } Vector2i gridPos = item.m_gridPos; inventory.m_inventory.Remove(item); val.m_inventory.Remove(itemAt); if (IsBag(itemAt)) { itemAt.m_equipped = false; } itemAt.m_gridPos = gridPos; inventory.m_inventory.Add(itemAt); item.m_gridPos = val2.Value; val.m_inventory.Add(item); inventory.Changed(false, false); val.Changed(false, false); return true; } public static bool MoveOutOfSlot(Player player, ItemData item) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: 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) //IL_0046: Unknown result type (might be due to invalid IL or missing references) Inventory val = Get(); if (val == null) { return false; } Inventory inventory = ((Humanoid)player).GetInventory(); Vector2i val2 = inventory.FindEmptySlot(false); if (val2.x < 0) { ((Character)player).Message((MessageType)2, "Inventory full", 0, (Sprite)null, false); return false; } if (IsBag(item)) { item.m_equipped = false; } Transfer(val, inventory, item, val2); return true; } public static void MoveAllToInventory(Player player) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) Inventory val = Get(); if (val == null) { return; } Inventory inventory = ((Humanoid)player).GetInventory(); foreach (ItemData item in val.GetAllItems().ToList()) { item.m_customData["nathan.equip.pending"] = "1"; if (IsBag(item)) { item.m_equipped = false; } Vector2i val2 = inventory.FindEmptySlot(false); Transfer(val, inventory, item, (Vector2i)((val2.x >= 0) ? val2 : new Vector2i(0, 0))); } } public static void Reconcile(Player player) { //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) Inventory val = Get(); if (val == null || ((Character)player).IsDead()) { return; } Inventory inventory = ((Humanoid)player).GetInventory(); foreach (ItemData item in inventory.GetAllItems().ToList()) { if (item.m_customData.Remove("nathan.equip.pending")) { Vector2i? val2 = FindFreeSlot(val, item); if (val2.HasValue) { Transfer(inventory, val, item, val2.Value); } } } ItemData[] array = WornItems(player); foreach (ItemData val3 in array) { if (val3 != null && inventory.m_inventory.Contains(val3)) { Vector2i? val4 = FindFreeSlot(val, val3); if (val4.HasValue) { Transfer(inventory, val, val3, val4.Value); } } } foreach (ItemData allItem in val.GetAllItems()) { if (IsBag(allItem)) { allItem.m_equipped = true; } else if (!((Humanoid)player).IsItemEquiped(allItem)) { ((Humanoid)player).EquipItem(allItem, false); } } array = WornItems(player); foreach (ItemData val5 in array) { if (val5 != null && !inventory.ContainsItem(val5)) { ((Humanoid)player).UnequipItem(val5, false); } } } private static ItemData[] WornItems(Player player) { return (ItemData[])(object)new ItemData[6] { ((Humanoid)player).m_helmetItem, ((Humanoid)player).m_chestItem, ((Humanoid)player).m_legItem, ((Humanoid)player).m_shoulderItem, ((Humanoid)player).m_utilityItem, ((Humanoid)player).m_trinketItem }; } public static void AddWornItems(List<ItemData> worn) { Inventory val = Get(); if (val != null) { List<ItemData> list = new List<ItemData>(); val.GetWornItems(list); worn.AddRange(list); } } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }