using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Pigeon.Movement; using Unity.Netcode; using UnityEngine; using UnityEngine.InputSystem; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Sparroh")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("EquipAllWeapons")] [assembly: AssemblyTitle("EquipAllWeapons")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace EquipAllWeapons { [HarmonyPatch] internal static class AmmoPatches { [HarmonyPatch(typeof(Player), "RefillAllAmmo")] [HarmonyPrefix] private static bool RefillAllAmmoPrefix(Player __instance) { if (!ConfigManager.Enabled.Value) { return true; } if (((__instance != null) ? __instance.Gear : null) == null) { return true; } for (int i = 0; i < __instance.Gear.Length; i++) { if (GearSlotUtil.IsPrimaryGearIndex(i)) { IGear obj = __instance.Gear[i]; IWeapon val = (IWeapon)(object)((obj is IWeapon) ? obj : null); if (val != null) { val.AddStoredAmmo(9999f, true, -1); } } } return false; } [HarmonyPatch(typeof(Player), "ReloadEquippedWeapon")] [HarmonyPrefix] private static bool ReloadEquippedWeaponPrefix(Player __instance, float ammoEffiency) { if (!ConfigManager.Enabled.Value) { return true; } int selectedGearSlot = __instance.SelectedGearSlot; if (GearSlotUtil.IsPrimarySelectedSlot(selectedGearSlot)) { IGear obj = __instance.Gear[selectedGearSlot - 1]; IWeapon val = (IWeapon)(object)((obj is IWeapon) ? obj : null); if (val != null) { val.AddAmmo(ammoEffiency, true); return false; } } int lastSelectedGearSlot = __instance.LastSelectedGearSlot; if (GearSlotUtil.IsPrimarySelectedSlot(lastSelectedGearSlot) && lastSelectedGearSlot - 1 < __instance.Gear.Length) { IGear obj2 = __instance.Gear[lastSelectedGearSlot - 1]; IWeapon val2 = (IWeapon)(object)((obj2 is IWeapon) ? obj2 : null); if (val2 != null) { val2.AddAmmo(ammoEffiency, true); return false; } } return false; } } public static class ConfigManager { private const float DebounceSeconds = 0.25f; private static ConfigFile config; private static ManualLogSource logger; private static FileSystemWatcher configWatcher; private static volatile bool reloadPending; private static float lastReloadTime; public static ConfigEntry Enabled { get; private set; } public static ConfigEntry UnlockedOnly { get; private set; } public static ConfigEntry ScrollAllPrimaries { get; private set; } public static void Initialize(ConfigFile configFile, ManualLogSource log) { config = configFile; logger = log; Enabled = config.Bind("General", "Enabled", true, "When enabled, all unlocked primary weapons are equipped at once and can be switched between."); UnlockedOnly = config.Bind("General", "UnlockedOnly", true, "When true, only unlocked primaries are equipped. When false, every primary in the catalog is equipped."); ScrollAllPrimaries = config.Bind("Controls", "ScrollAllPrimaries", true, "When enabled, mouse-wheel / switch-slot cycles through every equipped primary (not just the first two)."); try { SetupFileWatcher(); } catch (Exception ex) { logger.LogError((object)("Error setting up config file watcher: " + ex.Message)); } } public static void Tick() { if (!reloadPending || Time.unscaledTime - lastReloadTime < 0.25f) { return; } reloadPending = false; lastReloadTime = Time.unscaledTime; try { config.Reload(); logger.LogInfo((object)"Config reloaded from disk."); } catch (Exception ex) { logger.LogError((object)("Error reloading config: " + ex.Message)); } } public static void Dispose() { if (configWatcher != null) { configWatcher.EnableRaisingEvents = false; configWatcher.Changed -= OnConfigFileChanged; configWatcher.Created -= OnConfigFileChanged; configWatcher.Renamed -= OnConfigFileChanged; configWatcher.Dispose(); configWatcher = null; } } private static void SetupFileWatcher() { configWatcher = new FileSystemWatcher(Paths.ConfigPath, "sparroh.equipallweapons.cfg"); configWatcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.Size | NotifyFilters.LastWrite; configWatcher.Changed += OnConfigFileChanged; configWatcher.Created += OnConfigFileChanged; configWatcher.Renamed += OnConfigFileChanged; configWatcher.EnableRaisingEvents = true; } private static void OnConfigFileChanged(object sender, FileSystemEventArgs e) { reloadPending = true; } } [HarmonyPatch] internal static class GearExpandPatches { private static readonly FieldInfo IsGearInitializedField = AccessTools.Field(typeof(Player), "isGearInitialized"); private static bool expandInProgress; private static int lastExpandFrame = -1; [HarmonyPatch(typeof(Player), "OnAllGearSpawned_ClientRpc")] [HarmonyPostfix] private static void OnAllGearSpawnedPostfix(Player __instance) { if (ConfigManager.Enabled.Value && !((Object)(object)__instance == (Object)null) && ((NetworkBehaviour)__instance).IsOwner && __instance.IsGearInitialized) { ((MonoBehaviour)__instance).StartCoroutine(ExpandNextFrame(__instance)); } } [HarmonyPatch(typeof(GearSelectionWindow), "OnCloseCallback")] [HarmonyPostfix] private static void GearMenuClosedPostfix() { if (ConfigManager.Enabled.Value) { Player localPlayer = Player.LocalPlayer; if (!((Object)(object)localPlayer == (Object)null) && ((NetworkBehaviour)localPlayer).IsOwner && localPlayer.IsGearInitialized) { ((MonoBehaviour)localPlayer).StartCoroutine(ExpandNextFrame(localPlayer)); } } } private static IEnumerator ExpandNextFrame(Player player) { yield return null; TryExpandAndEquip(player); } internal static void TryExpandAndEquip(Player player) { if (!ConfigManager.Enabled.Value || (Object)(object)player == (Object)null || !((NetworkBehaviour)player).IsOwner || expandInProgress || Time.frameCount == lastExpandFrame || Global.Instance?.AllGear == null) { return; } expandInProgress = true; lastExpandFrame = Time.frameCount; try { List list = CollectPrimaries(player); if (list.Count == 0) { ManualLogSource log = EquipAllWeaponsPlugin.Log; if (log != null) { log.LogWarning((object)"No primaries found to equip."); } return; } int num = Mathf.Max(0, list.Count - 2); int minLength = 6 + num; if (!GearSlotUtil.EnsureGearCapacity(player, minLength)) { return; } HashSet hashSet = new HashSet(); for (int i = 0; i < player.Gear.Length; i++) { if (GearSlotUtil.IsPrimaryGearIndex(i)) { IGear val = player.Gear[i]; object obj; if (val == null) { obj = null; } else { IUpgradable prefab = ((IUpgradable)val).Prefab; obj = ((prefab != null) ? prefab.Info : null); } if ((Object)obj != (Object)null) { hashSet.Add(((IUpgradable)val).Prefab.Info.ID); } else if ((Object)(object)((val != null) ? ((IUpgradable)val).Info : null) != (Object)null) { hashSet.Add(((IUpgradable)val).Info.ID); } } } OrderPrimariesForSlots(list, player); for (int j = 0; j < list.Count; j++) { int num2 = ((j < 2) ? j : (6 + (j - 2))); if (num2 >= player.Gear.Length && !GearSlotUtil.EnsureGearCapacity(player, num2 + 1)) { break; } IUpgradable val2 = list[j]; IGear val3 = player.Gear[num2]; if (IsSamePrefab(val3, val2)) { continue; } int num3 = Array.IndexOf(Global.Instance.AllGear, val2); if (num3 < 0) { ManualLogSource log2 = EquipAllWeaponsPlugin.Log; if (log2 != null) { object obj2; if (val2 == null) { obj2 = null; } else { GearInfo info = val2.Info; obj2 = ((info != null) ? info.APIName : null); } log2.LogWarning((object)("Primary '" + (string?)obj2 + "' not in AllGear — skip.")); } continue; } bool flag = val3 != null; try { player.SpawnGear_ServerRpc(num2, num3, false, flag); } catch (Exception arg) { ManualLogSource log3 = EquipAllWeaponsPlugin.Log; if (log3 != null) { log3.LogError((object)$"Failed SpawnGear slot={num2} allGearIndex={num3}: {arg}"); } } } ManualLogSource log4 = EquipAllWeaponsPlugin.Log; if (log4 != null) { log4.LogInfo((object)($"Equipped {list.Count} primaries " + $"(Gear.Length={player.Gear.Length}, extras={num}).")); } } catch (Exception arg2) { ManualLogSource log5 = EquipAllWeaponsPlugin.Log; if (log5 != null) { log5.LogError((object)$"Expand/equip failed: {arg2}"); } } finally { expandInProgress = false; } } private static List CollectPrimaries(Player player) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) List list = new List(16); bool value = ConfigManager.UnlockedOnly.Value; for (int i = 0; i < Global.Instance.AllGear.Length; i++) { IUpgradable val = Global.Instance.AllGear[i]; if (val != null && (int)val.GearType == 0 && val.CanEquipInGearSelect() && (!value || PlayerData.IsGearUnlocked(val))) { list.Add(val); } } list.Sort((IUpgradable a, IUpgradable b) => Array.IndexOf(Global.Instance.AllGear, a).CompareTo(Array.IndexOf(Global.Instance.AllGear, b))); return list; } private static void OrderPrimariesForSlots(List primaries, Player player) { List preferred = new List(4); if (player.Gear != null) { if (player.Gear.Length != 0 && player.Gear[0] != null) { Prefer((IUpgradable)(((object)((IUpgradable)player.Gear[0]).Prefab) ?? ((object)player.Gear[0]))); } if (player.Gear.Length > 1 && player.Gear[1] != null) { Prefer((IUpgradable)(((object)((IUpgradable)player.Gear[1]).Prefab) ?? ((object)player.Gear[1]))); } } if (PlayerData.Instance != null) { Prefer(ResolveGearById(PlayerData.Instance.weapon1ID)); Prefer(ResolveGearById(PlayerData.Instance.weapon2ID)); } if (preferred.Count == 0) { return; } List list = new List(primaries.Count); for (int i = 0; i < primaries.Count; i++) { if (!preferred.Contains(primaries[i])) { list.Add(primaries[i]); } } primaries.Clear(); primaries.AddRange(preferred); primaries.AddRange(list); void Prefer(IUpgradable g) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) if (g != null) { IUpgradable prefab = g.GetPrefab(); if (prefab != null && (int)prefab.GearType == 0 && (primaries.Contains(prefab) || primaries.Contains(g))) { IUpgradable item = prefab ?? g; if (!preferred.Contains(item) && primaries.Contains(item)) { preferred.Add(item); } } } } } private static IUpgradable ResolveGearById(int id) { if (id == 0 || Global.Instance?.AllGear == null) { return null; } for (int i = 0; i < Global.Instance.AllGear.Length; i++) { IUpgradable val = Global.Instance.AllGear[i]; if ((Object)(object)((val != null) ? val.Info : null) != (Object)null && val.Info.ID == id) { return val; } } try { GearData gearData = PlayerData.GetGearData(id); return (gearData != null) ? gearData.Gear : null; } catch { return null; } } private static bool IsSamePrefab(IGear live, IUpgradable desired) { if (live == null || desired == null) { return false; } IUpgradable val = (IUpgradable)(((object)((IUpgradable)live).Prefab) ?? ((object)live)); IUpgradable val2 = desired.GetPrefab() ?? desired; if (val == val2) { return true; } if ((Object)(object)((val != null) ? val.Info : null) != (Object)null && (Object)(object)((val2 != null) ? val2.Info : null) != (Object)null) { return val.Info.ID == val2.Info.ID; } return false; } } [HarmonyPatch] internal static class GearMenuPatches { [HarmonyPatch(typeof(Player), "EquipNewGearFromPrefab")] [HarmonyPrefix] private static bool EquipNewGearFromPrefabPrefix(Player __instance, IUpgradable g) { if (!ConfigManager.Enabled.Value || ((__instance != null) ? __instance.Gear : null) == null || g == null) { return true; } for (int i = 0; i < __instance.Gear.Length; i++) { if (!GearSlotUtil.IsPrimaryGearIndex(i)) { continue; } IGear val = __instance.Gear[i]; if (val != null) { IUpgradable prefab = ((IUpgradable)val).Prefab; if (prefab == g || ((Object)(object)((prefab != null) ? prefab.Info : null) != (Object)null && (Object)(object)g.Info != (Object)null && prefab.Info.ID == g.Info.ID)) { __instance.EquipGear(GearSlotUtil.GearIndexToSelectedSlot(i)); return false; } } } return true; } [HarmonyPatch(typeof(Player), "SpawnGear_Server")] [HarmonyPrefix] private static void SpawnGearServerPrefix(Player __instance, int slot) { if (ConfigManager.Enabled.Value && !((Object)(object)__instance == (Object)null) && slot >= 0) { GearSlotUtil.EnsureGearCapacity(__instance, slot + 1); } } } internal static class GearSlotUtil { public const int VanillaGearLength = 6; public const int ExtraPrimaryStartIndex = 6; public const int ExtraPrimaryStartSlot = 7; private static readonly FieldInfo GearBackingField = AccessTools_Field(typeof(Player), "k__BackingField"); private static FieldInfo AccessTools_Field(Type type, string name) { return AccessTools.Field(type, name); } public static bool IsPrimarySelectedSlot(int selectedSlot) { if (selectedSlot == 1 || selectedSlot == 2) { return true; } return selectedSlot >= 7; } public static bool IsPrimaryGearIndex(int gearIndex) { if (gearIndex == 0 || gearIndex == 1) { return true; } return gearIndex >= 6; } public static int GearIndexToSelectedSlot(int gearIndex) { return gearIndex + 1; } public static int SelectedSlotToGearIndex(int selectedSlot) { return selectedSlot - 1; } public static bool TrySetGearArray(Player player, IGear[] newArray) { if ((Object)(object)player == (Object)null || newArray == null) { return false; } if (GearBackingField != null) { GearBackingField.SetValue(player, newArray); return true; } PropertyInfo propertyInfo = AccessTools.Property(typeof(Player), "Gear"); if (propertyInfo?.SetMethod != null) { propertyInfo.SetValue(player, newArray); return true; } ManualLogSource log = EquipAllWeaponsPlugin.Log; if (log != null) { log.LogError((object)"Could not set Player.Gear array."); } return false; } public static bool EnsureGearCapacity(Player player, int minLength) { if (((player != null) ? player.Gear : null) == null) { return false; } if (player.Gear.Length >= minLength) { return true; } IGear[] array = (IGear[])(object)new IGear[minLength]; for (int i = 0; i < player.Gear.Length; i++) { array[i] = player.Gear[i]; } return TrySetGearArray(player, array); } public static List GetPrimarySelectedSlots(Player player, bool requireNonNull = true) { List slots = new List(16); Player obj = player; if (((obj != null) ? obj.Gear : null) == null) { return slots; } Consider(0); Consider(1); for (int i = 6; i < player.Gear.Length; i++) { Consider(i); } return slots; void Consider(int gearIndex) { if (gearIndex >= 0 && gearIndex < player.Gear.Length && (!requireNonNull || player.Gear[gearIndex] != null)) { slots.Add(GearIndexToSelectedSlot(gearIndex)); } } } public static int GetNextPrimarySelectedSlot(Player player, int currentSelectedSlot, int direction) { List primarySelectedSlots = GetPrimarySelectedSlots(player); if (primarySelectedSlots.Count == 0) { if (currentSelectedSlot <= 0) { return 1; } return currentSelectedSlot; } int num = primarySelectedSlots.IndexOf(currentSelectedSlot); if (num < 0) { if (direction <= 0) { return primarySelectedSlots[primarySelectedSlots.Count - 1]; } return primarySelectedSlots[0]; } if (direction > 0) { return primarySelectedSlots[(num + 1) % primarySelectedSlots.Count]; } return primarySelectedSlots[(num - 1 + primarySelectedSlots.Count) % primarySelectedSlots.Count]; } } [HarmonyPatch] internal static class HudPatches { private static readonly FieldInfo GearHudsField = AccessTools.Field(typeof(Player), "gearHUDs"); private static int lastPrimaryHudSlot = 1; [HarmonyPatch(typeof(Player), "SwitchSlotCoroutine")] [HarmonyPrefix] private static void SwitchSlotCoroutinePrefix(Player __instance, int slot) { if (ConfigManager.Enabled.Value && !((Object)(object)__instance == (Object)null) && ((NetworkBehaviour)__instance).IsOwner && GearSlotUtil.IsPrimarySelectedSlot(slot)) { int selectedGearSlot = __instance.SelectedGearSlot; if (GearSlotUtil.IsPrimarySelectedSlot(selectedGearSlot)) { lastPrimaryHudSlot = selectedGearSlot; } if (slot >= 7) { RefreshPrimaryHotbar(__instance, slot, lastPrimaryHudSlot); } } } [HarmonyPatch(typeof(Player), "set_SelectedGearSlot")] [HarmonyPostfix] [HarmonyPriority(0)] private static void SelectedGearSlotPostfix(Player __instance, int value) { if (ConfigManager.Enabled.Value && !((Object)(object)__instance == (Object)null) && ((NetworkBehaviour)__instance).IsOwner && GearSlotUtil.IsPrimarySelectedSlot(value)) { RefreshPrimaryHotbar(__instance, value, lastPrimaryHudSlot); lastPrimaryHudSlot = value; } } internal static void RefreshPrimaryHotbar(Player player, int selectedSlot, int previousSelectedSlot) { //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) //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_00da: Unknown result type (might be due to invalid IL or missing references) if (((player != null) ? player.Gear : null) == null || !GearSlotUtil.IsPrimarySelectedSlot(selectedSlot) || !(GearHudsField?.GetValue(player) is EquippableHUDOverlay[] array) || array.Length < 2 || (Object)(object)array[0] == (Object)null || (Object)(object)array[1] == (Object)null) { return; } int num = GearSlotUtil.SelectedSlotToGearIndex(selectedSlot); if (num < 0 || num >= player.Gear.Length) { return; } IGear val = player.Gear[num]; if (val == null) { return; } try { if (array.Length > 2 && (Object)(object)array[2] != (Object)null && ((Component)array[2]).gameObject.activeSelf && !player.IsGearStored()) { ((Component)array[2]).gameObject.SetActive(false); } IGear val2 = ResolveOtherPrimary(player, selectedSlot, previousSelectedSlot, val); Vector2 basePos = array[0].BasePos; Vector2 basePos2 = array[1].BasePos; array[0].Setup(val, basePos); if (val2 != null) { array[1].Setup(val2, basePos2); } array[0].SetHeight(0); int num2 = 1; for (int i = 1; i < array.Length; i++) { if (!((Object)(object)array[i] == (Object)null) && (i != 2 || ((Component)array[i]).gameObject.activeSelf)) { array[i].SetHeight(num2++); } } } catch (Exception ex) { ManualLogSource log = EquipAllWeaponsPlugin.Log; if (log != null) { log.LogWarning((object)("Primary HUD refresh failed: " + ex.Message)); } } } private static IGear ResolveOtherPrimary(Player player, int currentSelectedSlot, int previousSelectedSlot, IGear current) { if (previousSelectedSlot != currentSelectedSlot && GearSlotUtil.IsPrimarySelectedSlot(previousSelectedSlot)) { int num = GearSlotUtil.SelectedSlotToGearIndex(previousSelectedSlot); if (num >= 0 && num < player.Gear.Length) { IGear val = player.Gear[num]; if (val != null && val != current) { return val; } } } List primarySelectedSlots = GearSlotUtil.GetPrimarySelectedSlots(player); int num2 = primarySelectedSlots.IndexOf(currentSelectedSlot); if (num2 >= 0 && primarySelectedSlots.Count > 1) { int selectedSlot = primarySelectedSlots[(num2 - 1 + primarySelectedSlots.Count) % primarySelectedSlots.Count]; IGear val2 = player.Gear[GearSlotUtil.SelectedSlotToGearIndex(selectedSlot)]; if (val2 != null && val2 != current) { return val2; } } for (int i = 0; i < primarySelectedSlots.Count; i++) { IGear val3 = player.Gear[GearSlotUtil.SelectedSlotToGearIndex(primarySelectedSlots[i])]; if (val3 != null && val3 != current) { return val3; } } return null; } } [BepInPlugin("sparroh.equipallweapons", "EquipAllWeapons", "1.0.0")] [MycoMod(/*Could not decode attribute arguments.*/)] public class EquipAllWeaponsPlugin : BaseUnityPlugin { public const string PluginGUID = "sparroh.equipallweapons"; public const string PluginName = "EquipAllWeapons"; public const string PluginVersion = "1.0.0"; internal static ManualLogSource Log; private Harmony _harmony; private void Awake() { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; try { ConfigManager.Initialize(((BaseUnityPlugin)this).Config, Log); _harmony = new Harmony("sparroh.equipallweapons"); _harmony.PatchAll(typeof(GearExpandPatches)); _harmony.PatchAll(typeof(SwitchSlotPatches)); _harmony.PatchAll(typeof(AmmoPatches)); _harmony.PatchAll(typeof(GearMenuPatches)); _harmony.PatchAll(typeof(HudPatches)); Log.LogInfo((object)"EquipAllWeapons v1.0.0 loaded — all unlocked primaries will be equipped."); } catch (Exception arg) { Log.LogError((object)string.Format("Failed to initialize {0}: {1}", "EquipAllWeapons", arg)); } } private void Update() { ConfigManager.Tick(); } private void OnDestroy() { try { ConfigManager.Dispose(); Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } catch (Exception arg) { Log.LogError((object)string.Format("Failed to unpatch {0}: {1}", "EquipAllWeapons", arg)); } } } [HarmonyPatch] internal static class SwitchSlotPatches { [HarmonyPatch(typeof(Player), "OnSwitchSlot")] [HarmonyPrefix] private static bool OnSwitchSlotPrefix(Player __instance, CallbackContext context) { if (!ConfigManager.Enabled.Value || !ConfigManager.ScrollAllPrimaries.Value) { return true; } if ((Object)(object)__instance == (Object)null || !((NetworkBehaviour)__instance).IsOwner) { return true; } if (AccessTools.Field(typeof(Player), "switchSlotCoroutine")?.GetValue(__instance) is IEnumerator) { return false; } float num = ((CallbackContext)(ref context)).ReadValue(); if (num == 0f) { return false; } int direction = ((num > 0f) ? 1 : (-1)); int nextPrimarySelectedSlot = GearSlotUtil.GetNextPrimarySelectedSlot(__instance, __instance.SelectedGearSlot, direction); if (nextPrimarySelectedSlot > 0) { __instance.EquipSlot(nextPrimarySelectedSlot, false); } return false; } [HarmonyPatch(typeof(Player), "set_SelectedGearSlot")] [HarmonyPrefix] private static bool SelectedGearSlotSetterPrefix(Player __instance, int value) { if (!ConfigManager.Enabled.Value) { return true; } FieldInfo fieldInfo = AccessTools.Field(typeof(Player), "_selectedGearSlot"); FieldInfo fieldInfo2 = AccessTools.Field(typeof(Player), "lastSelectedPrimaryGearSlot"); FieldInfo fieldInfo3 = AccessTools.Field(typeof(Player), "lastSelectedGearSlot"); if (fieldInfo == null || fieldInfo2 == null || fieldInfo3 == null) { return true; } int num = (int)fieldInfo.GetValue(__instance); if (num > 0) { if (GearSlotUtil.IsPrimarySelectedSlot(num)) { fieldInfo2.SetValue(__instance, num); fieldInfo3.SetValue(__instance, num); } else if (num == 6) { fieldInfo3.SetValue(__instance, num); } } fieldInfo.SetValue(__instance, value); return false; } [HarmonyPatch(typeof(Player), "SwitchToPrimaryGearNow")] [HarmonyPrefix] private static bool SwitchToPrimaryGearNowPrefix(Player __instance) { if (!ConfigManager.Enabled.Value) { return true; } FieldInfo fieldInfo = AccessTools.Field(typeof(Player), "pocketGear"); FieldInfo fieldInfo2 = AccessTools.Field(typeof(Player), "heldGear"); if (fieldInfo == null) { return true; } object value = fieldInfo.GetValue(__instance); object obj = fieldInfo2?.GetValue(__instance); IPocketGear val = null; IPocketGear val2 = (IPocketGear)((value is IPocketGear) ? value : null); if (val2 != null && value != obj) { val = val2; } fieldInfo.SetValue(__instance, null); int num = __instance.LastSelectedGearSlot; if (!GearSlotUtil.IsPrimarySelectedSlot(num)) { FieldInfo fieldInfo3 = AccessTools.Field(typeof(Player), "lastSelectedPrimaryGearSlot"); num = ((!(fieldInfo3 != null)) ? 1 : ((int)fieldInfo3.GetValue(__instance))); if (!GearSlotUtil.IsPrimarySelectedSlot(num)) { num = 1; } } __instance.EquipSlot(num, true); if (val != null && val.Exists()) { bool flag = true; NetworkBehaviour val3 = (NetworkBehaviour)(object)((val is NetworkBehaviour) ? val : null); if (val3 != null) { flag = val3.IsSpawned; } if (flag) { val.TryEquipFromPocket(__instance); } } return false; } } public static class MyPluginInfo { public const string PLUGIN_GUID = "EquipAllWeapons"; public const string PLUGIN_NAME = "EquipAllWeapons"; public const string PLUGIN_VERSION = "1.0.0"; } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }