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 ExtraSlots v1.0.0
ExtraSlots.dll
Decompiled 3 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; using TMPro; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyVersion("0.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ExtraSlots { [BepInPlugin("rev.extraslots", "ExtraSlots", "1.0.0")] public class Plugin : BaseUnityPlugin { public const string Guid = "rev.extraslots"; public const string Name = "ExtraSlots"; public const string Version = "1.0.0"; public const int VanillaSlots = 3; public const int MaxSlots = 9; internal static ManualLogSource Log; internal static ConfigEntry<int> SlotCount; internal static readonly List<ConfigEntry<Key>> SlotKeys = new List<ConfigEntry<Key>>(); internal static int ExtraSlotCount => Mathf.Clamp(SlotCount.Value, 3, 9) - 3; private void Awake() { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Expected O, but got Unknown //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; SlotCount = ((BaseUnityPlugin)this).Config.Bind<int>("General", "SlotCount", 5, new ConfigDescription($"How many item slots the player has. {3} = vanilla.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(3, 9), Array.Empty<object>())); for (int i = 3; i < 9; i++) { Key val = (Key)((i < 9) ? (41 + i) : 50); SlotKeys.Add(((BaseUnityPlugin)this).Config.Bind<Key>("Keys", $"Slot{i + 1}", val, $"Key that equips or unequips the item in slot {i + 1}.")); } new Harmony("rev.extraslots").PatchAll(typeof(Patches)); ((Component)this).gameObject.AddComponent<SlotHotkeys>(); Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); Log.LogInfo((object)string.Format("{0} {1} loaded ({2} slots)", "ExtraSlots", "1.0.0", SlotCount.Value)); } } internal static class Patches { [HarmonyPatch(typeof(Inventory), "Awake")] [HarmonyPostfix] private static void InventoryAwake(Inventory __instance) { List<InventorySpot> allSpots = __instance.GetAllSpots(); while (allSpots.Count < 3 + Plugin.ExtraSlotCount) { allSpots.Add(null); } } [HarmonyPatch(typeof(Inventory), "InventorySpotAddAtIndex")] [HarmonyPostfix] private static void InventorySpotAdded(Inventory __instance, InventorySpot spot, int index) { if (index != 2 || (Object)(object)spot == (Object)null) { return; } try { SlotBuilder.BuildExtraSpots(__instance, spot); } catch (Exception arg) { Plugin.Log.LogError((object)$"Failed to create extra inventory slots: {arg}"); } } } internal static class SlotBuilder { public static void BuildExtraSpots(Inventory inventory, InventorySpot lastVanillaSpot) { //IL_0038: 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_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: 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_00c1: 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_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) int extraSlotCount = Plugin.ExtraSlotCount; if (extraSlotCount <= 0) { return; } List<InventorySpot> allSpots = inventory.GetAllSpots(); while (allSpots.Count < 3 + extraSlotCount) { allSpots.Add(null); } Transform parent = ((Component)lastVanillaSpot).transform.parent; Vector3 localPosition = ((Component)lastVanillaSpot).transform.localPosition; Vector3 val = StepBetweenSpots(allSpots, localPosition); for (int i = 3; i < 3 + extraSlotCount; i++) { if (!((Object)(object)allSpots[i] != (Object)null)) { GameObject val2 = Object.Instantiate<GameObject>(((Component)lastVanillaSpot).gameObject, parent); val2.SetActive(false); ((Object)val2).name = $"Inventory Spot {i + 1}"; PhotonView[] componentsInChildren = val2.GetComponentsInChildren<PhotonView>(true); for (int j = 0; j < componentsInChildren.Length; j++) { Object.DestroyImmediate((Object)(object)componentsInChildren[j]); } val2.transform.localPosition = localPosition + val * (float)(i - 2); val2.transform.localRotation = ((Component)lastVanillaSpot).transform.localRotation; val2.transform.localScale = ((Component)lastVanillaSpot).transform.localScale; InventorySpot component = val2.GetComponent<InventorySpot>(); component.inventorySpotIndex = i; SetSlotLabel(component, i); val2.SetActive(true); Plugin.Log.LogInfo((object)$"Created inventory slot {i + 1}"); } } } private static Vector3 StepBetweenSpots(List<InventorySpot> spots, Vector3 anchor) { //IL_001d: 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_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_003d: 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) InventorySpot val = ((spots.Count > 1) ? spots[1] : null); if ((Object)(object)val != (Object)null) { Vector3 result = anchor - ((Component)val).transform.localPosition; if (((Vector3)(ref result)).sqrMagnitude > 0.01f) { return result; } } Transform transform = ((Component)spots[2]).transform; RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null); float num; if (!((Object)(object)val2 != (Object)null)) { num = 40f; } else { Rect rect = val2.rect; num = ((Rect)(ref rect)).height; } float num2 = num; return new Vector3(0f, 0f - num2, 0f); } private static void SetSlotLabel(InventorySpot spot, int index) { //IL_0032: Unknown result type (might be due to invalid IL or missing references) TextMeshProUGUI noItem = spot.noItem; if (!((Object)(object)noItem == (Object)null)) { int num = index - 3; if (num >= 0 && num < Plugin.SlotKeys.Count) { ((TMP_Text)noItem).text = KeyLabel(Plugin.SlotKeys[num].Value); } } } private unsafe static string KeyLabel(Key key) { string text = ((object)(*(Key*)(&key))/*cast due to .constrained prefix*/).ToString(); if (!text.StartsWith("Digit")) { return text; } return text.Substring("Digit".Length); } } internal class SlotHotkeys : MonoBehaviour { private static readonly MethodInfo HandleInputMethod = AccessTools.Method(typeof(InventorySpot), "HandleInput", (Type[])null, (Type[])null); private static readonly FieldInfo ChatActiveField = AccessTools.Field(typeof(ChatManager), "chatActive"); private static readonly FieldInfo DisableMovementField = AccessTools.Field(typeof(InputManager), "disableMovementTimer"); private void Update() { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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) if (Keyboard.current == null || (Object)(object)Inventory.instance == (Object)null || InputBlocked()) { return; } List<InventorySpot> allSpots = Inventory.instance.GetAllSpots(); for (int i = 3; i < allSpots.Count && i - 3 < Plugin.SlotKeys.Count; i++) { InventorySpot val = allSpots[i]; if (!((Object)(object)val == (Object)null)) { Key value = Plugin.SlotKeys[i - 3].Value; if ((int)value != 0 && ((ButtonControl)Keyboard.current[value]).wasPressedThisFrame) { HandleInputMethod.Invoke(val, null); } } } } private static bool InputBlocked() { if (SemiFunc.MenuLevel() || SemiFunc.RunIsArena()) { return true; } if ((Object)(object)ChatManager.instance != (Object)null && ChatActiveField != null && (bool)ChatActiveField.GetValue(ChatManager.instance)) { return true; } if ((Object)(object)InputManager.instance != (Object)null && DisableMovementField != null && (float)DisableMovementField.GetValue(InputManager.instance) > 0f) { return true; } return false; } } }