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 ItemQuickSwitchFix v1.1.1
ItemQuickSwitchMod.dll
Decompiled a year agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using GameNetcodeStuff; using HarmonyLib; using Microsoft.CodeAnalysis; using Unity.Netcode; 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: AssemblyCompany("ItemQuickSwitchMod")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Mod for selecting item slots directly")] [assembly: AssemblyFileVersion("1.1.0.0")] [assembly: AssemblyInformationalVersion("1.1.0")] [assembly: AssemblyProduct("ItemQuickSwitchMod")] [assembly: AssemblyTitle("ItemQuickSwitchMod")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.1.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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 ItemQuickSwitchMod { public sealed class CustomAction { public class ActionItem { public string Id { get; } public Key Shortcut { get; } public string Description { get; } public int SlotNumber { get; } public ConfigEntry<Key> ConfigEntry { get; set; } public ActionItem(string id, Key config, string description, int slotNumber) { //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_0017: 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) Id = id; Shortcut = config; Description = description; SlotNumber = slotNumber; } } public static readonly ActionItem Emote1 = new ActionItem("Emote1", (Key)94, "Dance emote", 0); public static readonly ActionItem Emote2 = new ActionItem("Emote2", (Key)95, "Point emote", 0); public static readonly ActionItem Slot1 = new ActionItem("Slot1", (Key)41, "Equip Slot 1", 0); public static readonly ActionItem Slot2 = new ActionItem("Slot2", (Key)42, "Equip Slot 2", 1); public static readonly ActionItem Slot3 = new ActionItem("Slot3", (Key)43, "Equip Slot 3", 2); public static readonly ActionItem Slot4 = new ActionItem("Slot4", (Key)44, "Equip Slot 4", 3); public static readonly ActionItem[] AllActions = new ActionItem[6] { Emote1, Emote2, Slot1, Slot2, Slot3, Slot4 }; } [BepInPlugin("PaLaS0.ItemQuickSwitchMod", "ItemQuickSwitchMod", "1.1.0")] public class ItemQuickSwitchMod : BaseUnityPlugin { private Harmony _harmony; private void Awake() { //IL_0030: 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_0062: Expected O, but got Unknown ((BaseUnityPlugin)this).Logger.LogInfo((object)"ItemQuickSwitchMod is creating binds!"); CustomAction.ActionItem[] allActions = CustomAction.AllActions; foreach (CustomAction.ActionItem actionItem in allActions) { ConfigEntry<Key> configEntry = ((BaseUnityPlugin)this).Config.Bind<Key>("Bindings", actionItem.Id, actionItem.Shortcut, actionItem.Description); actionItem.ConfigEntry = configEntry; } _harmony = new Harmony("PaLaS0.ItemQuickSwitchMod"); _harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin ItemQuickSwitchMod is loaded!"); } } public static class StaticPluginInfo { public const string GUID = "PaLaS0.ItemQuickSwitchMod"; public const string NAME = "ItemQuickSwitchMod"; } public static class PluginInfo { public const string PLUGIN_GUID = "ItemQuickSwitchMod"; public const string PLUGIN_NAME = "ItemQuickSwitchMod"; public const string PLUGIN_VERSION = "1.1.0"; } } namespace ItemQuickSwitchMod.Patches { [HarmonyPatch(typeof(PlayerControllerB))] internal class PlayerControllerBPatch { private static Dictionary<int, float> lastGrabTime = new Dictionary<int, float>(); private static readonly Dictionary<string, MethodInfo> MethodCache = new Dictionary<string, MethodInfo>(); private static readonly object[] BackwardsParam = new object[1] { false }; private static readonly object[] ForwardsParam = new object[1] { true }; private static object InvokePrivateMethod(PlayerControllerB instance, string methodName, object[] parameters = null) { MethodCache.TryGetValue(methodName, out var value); if ((object)value == null) { value = typeof(PlayerControllerB).GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic); } MethodCache[methodName] = value; return value?.Invoke(instance, parameters); } [HarmonyPatch("Update")] [HarmonyPostfix] public static void PlayerControllerB_Update(PlayerControllerB __instance, ref float ___timeSinceSwitchingSlots, ref bool ___throwingObject) { if ((!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer) { return; } CustomAction.ActionItem actionItem = Array.Find(CustomAction.AllActions, (CustomAction.ActionItem it) => ((ButtonControl)Keyboard.current[it.ConfigEntry.Value]).wasPressedThisFrame); if (actionItem == null) { return; } string id = actionItem.Id; if (!(id == "Emote1")) { if (id == "Emote2") { PerformEmote(__instance, 2); return; } StopEmotes(__instance); if (SwitchItemSlots(__instance, actionItem.SlotNumber, ___timeSinceSwitchingSlots, ___throwingObject)) { ___timeSinceSwitchingSlots = 0f; } } else { PerformEmote(__instance, 1); } } private static void PerformEmote(PlayerControllerB __instance, int emoteId) { __instance.timeSinceStartingEmote = 0f; __instance.performingEmote = true; __instance.playerBodyAnimator.SetInteger("emoteNumber", emoteId); __instance.StartPerformingEmoteServerRpc(); } private static bool SwitchItemSlots(PlayerControllerB __instance, int requestedSlot, float timeSinceSwitchingSlots, bool isThrowingObject) { if (!IsItemSwitchPossible(__instance, timeSinceSwitchingSlots, isThrowingObject) || __instance.currentItemSlot == requestedSlot) { return false; } int num = __instance.currentItemSlot - requestedSlot; bool flag = num > 0; if (Math.Abs(num) == __instance.ItemSlots.Length - 1) { object[] parameters = (flag ? ForwardsParam : BackwardsParam); InvokePrivateMethod(__instance, "SwitchItemSlotsServerRpc", parameters); } else { object[] parameters2 = (flag ? BackwardsParam : ForwardsParam); do { InvokePrivateMethod(__instance, "SwitchItemSlotsServerRpc", parameters2); num += ((!flag) ? 1 : (-1)); } while (num != 0); } ShipBuildModeManager.Instance.CancelBuildMode(true); __instance.playerBodyAnimator.SetBool("GrabValidated", false); object[] parameters3 = new object[2] { requestedSlot, null }; InvokePrivateMethod(__instance, "SwitchToItemSlot", parameters3); if ((Object)(object)__instance.currentlyHeldObjectServer != (Object)null) { ((Component)__instance.currentlyHeldObjectServer).gameObject.GetComponent<AudioSource>().PlayOneShot(__instance.currentlyHeldObjectServer.itemProperties.grabSFX, 0.6f); } return true; } private static bool IsItemSwitchPossible(PlayerControllerB __instance, float timeSinceSwitchingSlots, bool isThrowingObject) { if (!((double)timeSinceSwitchingSlots < 0.01 || __instance.inTerminalMenu || __instance.isGrabbingObjectAnimation || __instance.inSpecialInteractAnimation || isThrowingObject) && !__instance.isTypingChat && !__instance.twoHanded && !__instance.activatingItem && !__instance.jetpackControls) { return !__instance.disablingJetpackControls; } return false; } private static void StopEmotes(PlayerControllerB __instance) { __instance.performingEmote = false; __instance.StopPerformingEmoteServerRpc(); __instance.timeSinceStartingEmote = 0f; } [HarmonyPatch(typeof(PlayerControllerB), "BeginGrabObject")] [HarmonyPrefix] private static bool AddItemGrabDelay(PlayerControllerB __instance) { float time = Time.time; int instanceID = ((Object)__instance).GetInstanceID(); if (!lastGrabTime.TryGetValue(instanceID, out var value)) { lastGrabTime[instanceID] = 0f; } float num = 0.5f; if (time - value < num) { return false; } lastGrabTime[instanceID] = time; return true; } [HarmonyPatch(typeof(PlayerControllerB), "Interact_performed")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> PatchInteractInterval(IEnumerable<CodeInstruction> instructions) { List<CodeInstruction> list = new List<CodeInstruction>(instructions); for (int i = 0; i < list.Count; i++) { if (list[i].opcode == OpCodes.Ldc_R4 && (float)list[i].operand == 0.2f) { list[i].operand = 0.5f; break; } } return list.AsEnumerable(); } } }