From 06cf2d7f8f4d61d1cc081cbcd2749ae310051f49 Mon Sep 17 00:00:00 2001 From: Yamato <66829532+louis1706@users.noreply.github.com> Date: Fri, 9 Aug 2024 10:05:15 +0200 Subject: [PATCH] `Item::Get()` and `Pickup::Get()` (#17) * `Item::::Get()` and `Pickup::Get()` * Revert doc change * Add `Hazard::Get()` * doc fix * `Door::Get()` * AdminToy.Get() * More implementation * WeirdFix * simplify Scp244Spawning patch and AddedComment & NO IL error * Remove Log.info * DroppingItem light modifiication * Moving Item.Get inside the eventargs instead of transpiller --- EXILED/Exiled.API/Features/Doors/Door.cs | 57 ++++++++++++++----- EXILED/Exiled.API/Features/Hazards/Hazard.cs | 9 +++ .../Features/Items/ExplosiveGrenade.cs | 2 +- .../Exiled.API/Features/Items/FlashGrenade.cs | 2 +- EXILED/Exiled.API/Features/Items/Item.cs | 45 ++++++++++++++- EXILED/Exiled.API/Features/Items/Scp018.cs | 2 +- EXILED/Exiled.API/Features/Items/Scp2176.cs | 2 +- EXILED/Exiled.API/Features/Items/Scp330.cs | 4 +- EXILED/Exiled.API/Features/Items/Throwable.cs | 2 +- EXILED/Exiled.API/Features/Lift.cs | 4 +- EXILED/Exiled.API/Features/Map.cs | 2 +- EXILED/Exiled.API/Features/Pickups/Pickup.cs | 52 +++++++++++++++++ .../Pickups/Projectiles/Projectile.cs | 43 ++++++++++++-- EXILED/Exiled.API/Features/Player.cs | 4 +- EXILED/Exiled.API/Features/TeslaGate.cs | 2 +- EXILED/Exiled.API/Features/Toys/AdminToy.cs | 9 +++ .../Patches/PlayerInventorySee.cs | 3 +- .../Item/ChangingAttachmentsEventArgs.cs | 14 ++--- .../Map/ExplodingGrenadeEventArgs.cs | 4 +- .../EventArgs/Map/Scp244SpawningEventArgs.cs | 13 +++-- .../Player/CancellingItemUseEventArgs.cs | 2 +- .../Player/ChangingMicroHIDStateEventArgs.cs | 2 +- .../Player/ChangingRadioPresetEventArgs.cs | 2 +- .../EventArgs/Player/DroppedItemEventArgs.cs | 5 +- .../Player/ThrowingRequestEventArgs.cs | 2 +- .../Player/ThrownProjectileEventArgs.cs | 4 +- .../Player/TogglingFlashlightEventArgs.cs | 2 +- .../Player/TogglingRadioEventArgs.cs | 2 +- .../Player/UsingMicroHIDEnergyEventArgs.cs | 2 +- .../Player/UsingRadioBatteryEventArgs.cs | 2 +- .../Scp096/StartPryingGateEventArgs.cs | 2 +- .../EventArgs/Scp244/UsingScp244EventArgs.cs | 2 +- .../Scp330/DroppingScp330EventArgs.cs | 2 +- .../Events/Item/ChangingAttachments.cs | 7 +-- .../Patches/Events/Map/Scp244Spawning.cs | 39 ++++++------- .../Patches/Events/Player/DroppingItem.cs | 7 +-- .../Events/Player/FirearmRequestReceived.cs | 3 +- .../Patches/Fixes/GrenadePropertiesFix.cs | 3 +- .../Exiled.Events/Patches/Generic/DoorList.cs | 2 +- .../Patches/Generic/PickupControlPatch.cs | 7 ++- 40 files changed, 271 insertions(+), 103 deletions(-) diff --git a/EXILED/Exiled.API/Features/Doors/Door.cs b/EXILED/Exiled.API/Features/Doors/Door.cs index 230e05b0b..c06a13b9b 100644 --- a/EXILED/Exiled.API/Features/Doors/Door.cs +++ b/EXILED/Exiled.API/Features/Doors/Door.cs @@ -14,7 +14,9 @@ namespace Exiled.API.Features.Doors using Exiled.API.Enums; using Exiled.API.Extensions; using Exiled.API.Features.Core; + using Exiled.API.Features.Hazards; using Exiled.API.Interfaces; + using global::Hazards; using Interactables.Interobjects; using Interactables.Interobjects.DoorUtils; using MEC; @@ -309,6 +311,31 @@ public static Door Get(DoorVariant doorVariant) return DoorVariantToDoor[doorVariant]; } + /// + /// Gets the by . + /// + /// The to convert into an door. + /// The specified type. + /// The door wrapper for the given . + public static T Get(DoorVariant doorVariant) + where T : Door => Get(doorVariant) as T; + + /// + /// Gets a given the specified . + /// + /// The to search for. + /// The with the given or if not found. + public static Door Get(DoorType doorType) => List.FirstOrDefault(x => x.Type == doorType); + + /// + /// Gets the by . + /// + /// The to convert into an door. + /// The specified type. + /// The door wrapper for the given . + public static T Get(DoorType doorType) + where T : Door => Get(doorType) as T; + /// /// Gets a given the specified name. /// @@ -320,6 +347,15 @@ public static Door Get(string name) return nameExtension is null ? null : Get(nameExtension.TargetDoor); } + /// + /// Gets the by . + /// + /// The name to search for. + /// The specified type. + /// The door wrapper for the given . + public static T Get(string name) + where T : Door => Get(name) as T; + /// /// Gets the door object associated with a specific , or creates a new one if there isn't one. /// @@ -327,20 +363,6 @@ public static Door Get(string name) /// The with the given name or if not found. public static Door Get(GameObject gameObject) => gameObject is null ? null : Get(gameObject.GetComponentInChildren()); - /// - /// Gets a of filtered based on a predicate. - /// - /// The condition to satify. - /// A of which contains elements that satify the condition. - public static IEnumerable Get(Func predicate) => List.Where(predicate); - - /// - /// Gets a given the specified . - /// - /// The to search for. - /// The with the given or if not found. - public static Door Get(DoorType doorType) => List.FirstOrDefault(x => x.Type == doorType); - /// /// Returns the closest to the given . /// @@ -367,6 +389,13 @@ public static Door Random(ZoneType type = ZoneType.Unspecified, bool onlyUnbroke return doors[UnityEngine.Random.Range(0, doors.Count)]; } + /// + /// Gets a of filtered based on a predicate. + /// + /// The condition to satify. + /// A of which contains elements that satify the condition. + public static IEnumerable Get(Func predicate) => List.Where(predicate); + /// /// Locks all doors given the specified . /// diff --git a/EXILED/Exiled.API/Features/Hazards/Hazard.cs b/EXILED/Exiled.API/Features/Hazards/Hazard.cs index 36695f6de..253825530 100644 --- a/EXILED/Exiled.API/Features/Hazards/Hazard.cs +++ b/EXILED/Exiled.API/Features/Hazards/Hazard.cs @@ -123,6 +123,15 @@ public static Hazard Get(EnvironmentalHazard environmentalHazard) => _ => new Hazard(environmentalHazard) }; + /// + /// Gets the by . + /// + /// The to convert into an hazard. + /// The specified type. + /// The hazard wrapper for the given . + public static T Get(EnvironmentalHazard environmentalHazard) + where T : Hazard => Get(environmentalHazard) as T; + /// /// Gets the hazard by the room where it's located. /// diff --git a/EXILED/Exiled.API/Features/Items/ExplosiveGrenade.cs b/EXILED/Exiled.API/Features/Items/ExplosiveGrenade.cs index 8f9aa165c..0002d5d76 100644 --- a/EXILED/Exiled.API/Features/Items/ExplosiveGrenade.cs +++ b/EXILED/Exiled.API/Features/Items/ExplosiveGrenade.cs @@ -119,7 +119,7 @@ public ExplosionGrenadeProjectile SpawnActive(Vector3 position, Player owner = n ipb.Info = new PickupSyncInfo(Type, Weight, ItemSerialGenerator.GenerateNext()); - ExplosionGrenadeProjectile grenade = (ExplosionGrenadeProjectile)Pickup.Get(ipb); + ExplosionGrenadeProjectile grenade = Pickup.Get(ipb); grenade.Base.gameObject.SetActive(true); diff --git a/EXILED/Exiled.API/Features/Items/FlashGrenade.cs b/EXILED/Exiled.API/Features/Items/FlashGrenade.cs index e2d009ac7..979784f2c 100644 --- a/EXILED/Exiled.API/Features/Items/FlashGrenade.cs +++ b/EXILED/Exiled.API/Features/Items/FlashGrenade.cs @@ -100,7 +100,7 @@ public FlashbangProjectile SpawnActive(Vector3 position, Player owner = null) ipb.Info = new PickupSyncInfo(Type, Weight, ItemSerialGenerator.GenerateNext()); - FlashbangProjectile grenade = (FlashbangProjectile)Pickup.Get(ipb); + FlashbangProjectile grenade = Pickup.Get(ipb); grenade.Base.gameObject.SetActive(true); diff --git a/EXILED/Exiled.API/Features/Items/Item.cs b/EXILED/Exiled.API/Features/Items/Item.cs index b38f4aa18..96d02257f 100644 --- a/EXILED/Exiled.API/Features/Items/Item.cs +++ b/EXILED/Exiled.API/Features/Items/Item.cs @@ -25,7 +25,6 @@ namespace Exiled.API.Features.Items using InventorySystem.Items.Radio; using InventorySystem.Items.ThrowableProjectiles; using InventorySystem.Items.ToggleableLights; - using InventorySystem.Items.ToggleableLights.Flashlight; using InventorySystem.Items.Usables; using InventorySystem.Items.Usables.Scp1576; using InventorySystem.Items.Usables.Scp244; @@ -33,7 +32,6 @@ namespace Exiled.API.Features.Items using UnityEngine; using BaseConsumable = InventorySystem.Items.Usables.Consumable; - using Object = UnityEngine.Object; /// /// A wrapper class for . @@ -219,6 +217,15 @@ public static Item Get(ItemBase itemBase) }; } + /// + /// Gets an existing or creates a new instance of one. + /// + /// The to convert into an item. + /// The specified type. + /// The item wrapper for the given . + public static T Get(ItemBase itemBase) + where T : Item => Get(itemBase) as T; + /// /// Gets the Item belonging to the specified serial. /// @@ -279,6 +286,40 @@ ItemType.KeycardGuard or ItemType.KeycardJanitor or ItemType.KeycardO5 or ItemTy _ => new Item(type), }; + /// + /// Creates a new with the proper inherited subclass. + /// + /// Based on the , the returned can be casted into a subclass to gain more control over the object. + ///
- Usable items (Adrenaline, Medkit, Painkillers, SCP-207, SCP-268, and SCP-500) should be casted to the class. + ///
- All valid ammo should be casted to the class. + ///
- All valid firearms (not including the Micro HID) should be casted to the class. + ///
- All valid keycards should be casted to the class. + ///
- All valid armor should be casted to the class. + ///
- Explosive grenades and SCP-018 should be casted to the class. + ///
- Flash grenades should be casted to the class. + ///
+ /// + ///
The following have their own respective classes: + ///
- Flashlights can be casted to . + ///
- Radios can be casted to . + ///
- The Micro HID can be casted to . + ///
- SCP-244 A and B variants can be casted to . + ///
- SCP-330 can be casted to . + ///
- SCP-2176 can be casted to the class. + ///
- SCP-1576 can be casted to the class. + ///
- Jailbird can be casted to the class. + ///
+ /// + /// Items that are not listed above do not have a subclass, and can only use the base class. + /// + ///
+ /// The of the item to create. + /// The who owns the item by default. + /// The specified type. + /// The created. This can be cast as a subclass. + public static Item Create(ItemType type, Player owner = null) + where T : Item => Create(type, owner) as T; + /// /// Gives this item to a . /// diff --git a/EXILED/Exiled.API/Features/Items/Scp018.cs b/EXILED/Exiled.API/Features/Items/Scp018.cs index 57f8122c1..7c08c7c6d 100644 --- a/EXILED/Exiled.API/Features/Items/Scp018.cs +++ b/EXILED/Exiled.API/Features/Items/Scp018.cs @@ -86,7 +86,7 @@ public Scp018Projectile SpawnActive(Vector3 position, Player owner = null) ipb.Info = new PickupSyncInfo(Type, Weight, ItemSerialGenerator.GenerateNext()); - Scp018Projectile grenade = (Scp018Projectile)Pickup.Get(ipb); + Scp018Projectile grenade = Pickup.Get(ipb); grenade.Base.gameObject.SetActive(true); diff --git a/EXILED/Exiled.API/Features/Items/Scp2176.cs b/EXILED/Exiled.API/Features/Items/Scp2176.cs index 412c371d6..0ca9fc54d 100644 --- a/EXILED/Exiled.API/Features/Items/Scp2176.cs +++ b/EXILED/Exiled.API/Features/Items/Scp2176.cs @@ -71,7 +71,7 @@ public Scp2176Projectile SpawnActive(Vector3 position, Player owner = null) ipb.Info = new PickupSyncInfo(Type, Weight, ItemSerialGenerator.GenerateNext()); - Scp2176Projectile grenade = (Scp2176Projectile)Pickup.Get(ipb); + Scp2176Projectile grenade = Pickup.Get(ipb); grenade.Base.gameObject.SetActive(true); diff --git a/EXILED/Exiled.API/Features/Items/Scp330.cs b/EXILED/Exiled.API/Features/Items/Scp330.cs index d0a7e3b9c..689929f12 100644 --- a/EXILED/Exiled.API/Features/Items/Scp330.cs +++ b/EXILED/Exiled.API/Features/Items/Scp330.cs @@ -197,7 +197,7 @@ public IEnumerable DropCandy(CandyKindID type, bool dropAll = fals ipb.Info = new(Type, Weight, ItemSerialGenerator.GenerateNext()); - Scp330Pickup pickup = (Scp330Pickup)Pickup.Get(ipb); + Scp330Pickup pickup = Pickup.Get(ipb); if (exposedType is not CandyKindID.None) pickup.ExposedCandy = exposedType; @@ -218,7 +218,7 @@ public IEnumerable DropCandy(CandyKindID type, bool dropAll = fals ipb.Info = new(Type, Weight, ItemSerialGenerator.GenerateNext()); - Scp330Pickup pickup = (Scp330Pickup)Pickup.Get(ipb); + Scp330Pickup pickup = Pickup.Get(ipb); if (exposedType is not CandyKindID.None) pickup.ExposedCandy = exposedType; diff --git a/EXILED/Exiled.API/Features/Items/Throwable.cs b/EXILED/Exiled.API/Features/Items/Throwable.cs index 4946d1722..4de522295 100644 --- a/EXILED/Exiled.API/Features/Items/Throwable.cs +++ b/EXILED/Exiled.API/Features/Items/Throwable.cs @@ -29,7 +29,7 @@ public Throwable(ThrowableItem itemBase) { Base = itemBase; Base.Projectile.gameObject.SetActive(false); - Projectile = (Projectile)Pickup.Get(Object.Instantiate(Base.Projectile)); + Projectile = Pickup.Get(Object.Instantiate(Base.Projectile)); Base.Projectile.gameObject.SetActive(true); Projectile.Serial = Serial; } diff --git a/EXILED/Exiled.API/Features/Lift.cs b/EXILED/Exiled.API/Features/Lift.cs index 5222ca985..9a3b183c2 100644 --- a/EXILED/Exiled.API/Features/Lift.cs +++ b/EXILED/Exiled.API/Features/Lift.cs @@ -76,7 +76,7 @@ internal Lift(ElevatorChamber elevator) /// /// Gets a value of the internal doors list. /// - public IReadOnlyCollection Doors => internalDoorsList.Select(x => Door.Get(x).As()).ToList(); + public IReadOnlyCollection Doors => internalDoorsList.Select(x => Door.Get(x)).ToList(); /// /// Gets a of in the . @@ -201,7 +201,7 @@ public float AnimationTime /// /// Gets the . /// - public Doors.ElevatorDoor CurrentDestination => Door.Get(Base.CurrentDestination).As(); + public Doors.ElevatorDoor CurrentDestination => Door.Get(Base.CurrentDestination); /// /// Gets a of which contains all the instances from the specified . diff --git a/EXILED/Exiled.API/Features/Map.cs b/EXILED/Exiled.API/Features/Map.cs index 24edcc90c..4e8f2b094 100644 --- a/EXILED/Exiled.API/Features/Map.cs +++ b/EXILED/Exiled.API/Features/Map.cs @@ -294,7 +294,7 @@ public static TantrumHazard PlaceTantrum(Vector3 position, bool isActive = true) NetworkServer.Spawn(tantrum.gameObject); - return Hazard.Get(tantrum).Cast(); + return Hazard.Get(tantrum); } /// diff --git a/EXILED/Exiled.API/Features/Pickups/Pickup.cs b/EXILED/Exiled.API/Features/Pickups/Pickup.cs index 70db62a8a..3f7373dee 100644 --- a/EXILED/Exiled.API/Features/Pickups/Pickup.cs +++ b/EXILED/Exiled.API/Features/Pickups/Pickup.cs @@ -338,6 +338,15 @@ public static Pickup Get(ItemPickupBase pickupBase) }; } + /// + /// Gets an existing or creates a new instance of one. + /// + /// The to convert into an pickup. + /// The specified type. + /// The pickup wrapper for the given . + public static T Get(ItemPickupBase pickupBase) + where T : Pickup => Get(pickupBase) as T; + /// /// Gets the given a . /// @@ -487,6 +496,36 @@ public static IEnumerable Get(IEnumerable gameObjects) _ => new Pickup(type), }; + /// + /// Creates and returns a new with the proper inherited subclass. + /// + /// Based on the , the returned can be cast into a subclass to gain more control over the object. + ///
- All valid ammo should be cast to the class. + ///
- All valid firearms (not including the Micro HID) should be cast to the class. + ///
- All valid keycards should be cast to the class. + ///
- All valid armor should be cast to the class. + ///
- All grenades and throwables (not including SCP-018 and SCP-2176) should be cast to the class. + ///
+ /// + ///
The following have their own respective classes: + ///
- Radios can be cast to . + ///
- The Micro HID can be cast to . + ///
- SCP-244 A and B variants can be cast to . + ///
- SCP-330 can be cast to . + ///
- SCP-018 can be cast to . + ///
- SCP-2176 can be cast to . + ///
+ /// + /// Items that are not listed above do not have a subclass, and can only use the base class. + /// + ///
+ /// The of the pickup. + /// The specified type. + /// The created . + /// + public static Pickup Create(ItemType type) + where T : Pickup => Create(type) as T; + /// /// Creates and spawns a . /// @@ -498,6 +537,19 @@ public static IEnumerable Get(IEnumerable gameObjects) /// public static Pickup CreateAndSpawn(ItemType type, Vector3 position, Quaternion rotation, Player previousOwner = null) => Create(type).Spawn(position, rotation, previousOwner); + /// + /// Creates and spawns a . + /// + /// The of the pickup. + /// The position to spawn the at. + /// The rotation to spawn the . + /// An optional previous owner of the item. + /// The specified type. + /// The . See documentation of for more information on casting. + /// + public static Pickup CreateAndSpawn(ItemType type, Vector3 position, Quaternion rotation, Player previousOwner = null) + where T : Pickup => CreateAndSpawn(type, position, rotation, previousOwner) as T; + /// /// Spawns a . /// diff --git a/EXILED/Exiled.API/Features/Pickups/Projectiles/Projectile.cs b/EXILED/Exiled.API/Features/Pickups/Projectiles/Projectile.cs index cd18059bc..5406d6414 100644 --- a/EXILED/Exiled.API/Features/Pickups/Projectiles/Projectile.cs +++ b/EXILED/Exiled.API/Features/Pickups/Projectiles/Projectile.cs @@ -83,17 +83,37 @@ internal Projectile(ItemType type) /// Projectile that are not listed will cause an Exception. /// ///
- /// The of the pickup. - /// The created . + /// The of the projectile. + /// The created . public static Projectile Create(ProjectileType projectiletype) => projectiletype switch { ProjectileType.Scp018 => new Scp018Projectile(), ProjectileType.Flashbang => new FlashbangProjectile(), ProjectileType.Scp2176 => new Scp2176Projectile(), ProjectileType.FragGrenade => new ExplosionGrenadeProjectile(ItemType.GrenadeHE), - _ => throw new System.Exception($"ProjectileType does not contain a valid value : {projectiletype}"), + _ => throw new Exception($"ProjectileType does not contain a valid value : {projectiletype}"), }; + /// + /// Creates and returns a new with the proper inherited subclass. + /// + /// Based on the , the returned can be casted into a subclass to gain more control over the object. + ///
The following have their own respective classes: + ///
- FragGrenade can be casted to . + ///
- Flashbang can be casted to . + ///
- Scp018 A and B variants can be casted to . + ///
- Scp2176 can be casted to . + ///
+ /// + /// Projectile that are not listed will cause an Exception. + /// + ///
+ /// The of the projectile. + /// The specified type. + /// The created . + public static Projectile Create(ProjectileType projectiletype) + where T : Projectile => Create(projectiletype) as T; + /// /// Spawns a . /// @@ -110,14 +130,27 @@ public static Projectile Spawn(Projectile pickup, Vector3 position, Quaternion r /// /// Creates and spawns a . /// - /// The of the pickup. + /// The of the projectile. /// The position to spawn the at. /// The rotation to spawn the . /// Whether the should be in active state after spawn. /// An optional previous owner of the item. - /// The . See documentation of for more information on casting. + /// The . See documentation of for more information on casting. public static Projectile CreateAndSpawn(ProjectileType type, Vector3 position, Quaternion rotation, bool shouldBeActive = true, Player previousOwner = null) => Create(type).Spawn(position, rotation, shouldBeActive, previousOwner); + /// + /// Creates and spawns a . + /// + /// The of the projectile. + /// The position to spawn the at. + /// The rotation to spawn the . + /// Whether the should be in active state after spawn. + /// An optional previous owner of the item. + /// The specified type. + /// The . See documentation of for more information on casting. + public static Projectile CreateAndSpawn(ProjectileType type, Vector3 position, Quaternion rotation, bool shouldBeActive = true, Player previousOwner = null) + where T : Projectile => CreateAndSpawn(type, position, rotation, shouldBeActive, previousOwner) as T; + /// /// Activates the current . /// diff --git a/EXILED/Exiled.API/Features/Player.cs b/EXILED/Exiled.API/Features/Player.cs index f7403cdb6..cb9e84fa3 100644 --- a/EXILED/Exiled.API/Features/Player.cs +++ b/EXILED/Exiled.API/Features/Player.cs @@ -969,7 +969,7 @@ public Item CurrentItem /// /// Gets the armor that the player is currently wearing. Value will be if the player is not wearing any armor. /// - public Armor CurrentArmor => Inventory.TryGetBodyArmor(out BodyArmor armor) ? (Armor)Item.Get(armor) : null; + public Armor CurrentArmor => Inventory.TryGetBodyArmor(out BodyArmor armor) ? Item.Get(armor) : null; /// /// Gets the class. @@ -2767,7 +2767,7 @@ public void AddItem(Firearm item, IEnumerable identifiers) /// The that was added. public Item AddItem(FirearmPickup pickup, IEnumerable identifiers) { - Firearm firearm = (Firearm)Item.Get(Inventory.ServerAddItem(pickup.Type, pickup.Serial, pickup.Base)); + Firearm firearm = Item.Get(Inventory.ServerAddItem(pickup.Type, pickup.Serial, pickup.Base)); if (identifiers is not null) firearm.AddAttachment(identifiers); diff --git a/EXILED/Exiled.API/Features/TeslaGate.cs b/EXILED/Exiled.API/Features/TeslaGate.cs index d161e6b08..4d7909592 100644 --- a/EXILED/Exiled.API/Features/TeslaGate.cs +++ b/EXILED/Exiled.API/Features/TeslaGate.cs @@ -178,7 +178,7 @@ public bool UseInstantBurst /// /// Gets a of which contains all the tantrums to destroy. /// - public IEnumerable TantrumsToDestroy => Base.TantrumsToBeDestroyed.Select(x => Hazard.Get(x) as TantrumHazard); + public IEnumerable TantrumsToDestroy => Base.TantrumsToBeDestroyed.Select(x => Hazard.Get(x)); /// /// Gets a of which contains all the players inside the hurt range. diff --git a/EXILED/Exiled.API/Features/Toys/AdminToy.cs b/EXILED/Exiled.API/Features/Toys/AdminToy.cs index 2139059e9..5287096a1 100644 --- a/EXILED/Exiled.API/Features/Toys/AdminToy.cs +++ b/EXILED/Exiled.API/Features/Toys/AdminToy.cs @@ -159,6 +159,15 @@ public static AdminToy Get(AdminToyBase adminToyBase) }; } + /// + /// Gets the by . + /// + /// The to convert into an admintoy. + /// The specified type. + /// The admintoy wrapper for the given . + public static T Get(AdminToyBase adminToyBase) + where T : AdminToy => Get(adminToyBase) as T; + /// /// Spawns the toy into the game. Use to remove it. /// diff --git a/EXILED/Exiled.CustomItems/Patches/PlayerInventorySee.cs b/EXILED/Exiled.CustomItems/Patches/PlayerInventorySee.cs index 8f35712fb..1620477ba 100644 --- a/EXILED/Exiled.CustomItems/Patches/PlayerInventorySee.cs +++ b/EXILED/Exiled.CustomItems/Patches/PlayerInventorySee.cs @@ -8,6 +8,7 @@ namespace Exiled.CustomItems.Patches { using System.Collections.Generic; + using System.Linq; using System.Reflection; using System.Reflection.Emit; @@ -52,7 +53,7 @@ private static IEnumerable Transpiler(IEnumerable !x.IsGenericMethod && x.Name is nameof(Item.Get) && x.GetParameters().Length is 1 && x.GetParameters()[0].ParameterType == typeof(ItemBase))), new(OpCodes.Dup), new(OpCodes.Stloc_S, item.LocalIndex), new(OpCodes.Brfalse_S, continueLabel), diff --git a/EXILED/Exiled.Events/EventArgs/Item/ChangingAttachmentsEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Item/ChangingAttachmentsEventArgs.cs index 0e1c8fbed..fad3ec0b5 100644 --- a/EXILED/Exiled.Events/EventArgs/Item/ChangingAttachmentsEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Item/ChangingAttachmentsEventArgs.cs @@ -38,17 +38,13 @@ public class ChangingAttachmentsEventArgs : IPlayerEvent, IDeniableEvent, IFirea /// /// /// - public ChangingAttachmentsEventArgs( - Player player, - Firearm firearm, - uint code, - bool isAllowed = true) + public ChangingAttachmentsEventArgs(Player player, InventorySystem.Items.Firearms.Firearm firearm, uint code, bool isAllowed = true) { Player = player; - Firearm = firearm; - CurrentAttachmentIdentifiers = firearm.AttachmentIdentifiers; - NewAttachmentIdentifiers = firearm.FirearmType.GetAttachmentIdentifiers(code).ToList(); - CurrentCode = firearm.Base.GetCurrentAttachmentsCode(); + Firearm = Item.Get(firearm); + CurrentAttachmentIdentifiers = Firearm.AttachmentIdentifiers; + NewAttachmentIdentifiers = Firearm.FirearmType.GetAttachmentIdentifiers(code).ToList(); + CurrentCode = firearm.GetCurrentAttachmentsCode(); NewCode = code; IsAllowed = isAllowed; } diff --git a/EXILED/Exiled.Events/EventArgs/Map/ExplodingGrenadeEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Map/ExplodingGrenadeEventArgs.cs index 28b7b30f0..a0dbd7920 100644 --- a/EXILED/Exiled.Events/EventArgs/Map/ExplodingGrenadeEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Map/ExplodingGrenadeEventArgs.cs @@ -37,7 +37,7 @@ public class ExplodingGrenadeEventArgs : IPlayerEvent, IDeniableEvent public ExplodingGrenadeEventArgs(Footprint thrower, Vector3 position, ExplosionGrenade grenade, Collider[] targets) { Player = Player.Get(thrower.Hub); - Projectile = (EffectGrenadeProjectile)Pickup.Get(grenade); + Projectile = Pickup.Get(grenade); Position = position; TargetsToAffect = ListPool.Pool.Get(); @@ -97,7 +97,7 @@ public ExplodingGrenadeEventArgs(Footprint thrower, Vector3 position, ExplosionG public ExplodingGrenadeEventArgs(Player thrower, EffectGrenade grenade, List targetsToAffect, bool isAllowed = true) { Player = thrower ?? Server.Host; - Projectile = (EffectGrenadeProjectile)Pickup.Get(grenade); + Projectile = Pickup.Get(grenade); Position = Projectile.Position; TargetsToAffect = ListPool.Pool.Get(targetsToAffect ?? new()); IsAllowed = isAllowed; diff --git a/EXILED/Exiled.Events/EventArgs/Map/Scp244SpawningEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Map/Scp244SpawningEventArgs.cs index 1ed101269..fd6a6fa76 100644 --- a/EXILED/Exiled.Events/EventArgs/Map/Scp244SpawningEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Map/Scp244SpawningEventArgs.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) Exiled Team. All rights reserved. // Licensed under the CC BY-SA 3.0 license. @@ -10,6 +10,8 @@ namespace Exiled.Events.EventArgs.Map using API.Features; using Exiled.API.Features.Pickups; using Interfaces; + using InventorySystem.Items.Usables.Scp244; + using MapGeneration; /// /// Contains all information up to spawning Scp244. @@ -25,11 +27,10 @@ public class Scp244SpawningEventArgs : IRoomEvent, IPickupEvent, IDeniableEvent /// /// /// - public Scp244SpawningEventArgs(Room room, Pickup scp244Pickup) + public Scp244SpawningEventArgs(RoomIdentifier room, Scp244DeployablePickup scp244Pickup) { - Room = room; - Pickup = scp244Pickup; - Scp244Pickup = scp244Pickup.As(); + Room = Room.Get(room); + Scp244Pickup = Pickup.Get(scp244Pickup); } /// @@ -38,7 +39,7 @@ public Scp244SpawningEventArgs(Room room, Pickup scp244Pickup) public Room Room { get; } /// - public Pickup Pickup { get; } + public Pickup Pickup => Scp244Pickup; /// /// Gets a value indicating the pickup being spawning. diff --git a/EXILED/Exiled.Events/EventArgs/Player/CancellingItemUseEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/CancellingItemUseEventArgs.cs index ac07393e7..f3f623f40 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/CancellingItemUseEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/CancellingItemUseEventArgs.cs @@ -27,7 +27,7 @@ public class CancellingItemUseEventArgs : IPlayerEvent, IDeniableEvent, IUsableE public CancellingItemUseEventArgs(Player player, UsableItem item) { Player = player; - Usable = Item.Get(item) is Usable usable ? usable : null; + Usable = Item.Get(item); } /// diff --git a/EXILED/Exiled.Events/EventArgs/Player/ChangingMicroHIDStateEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/ChangingMicroHIDStateEventArgs.cs index 4cb941b0a..2b9bacdbf 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/ChangingMicroHIDStateEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/ChangingMicroHIDStateEventArgs.cs @@ -40,7 +40,7 @@ public class ChangingMicroHIDStateEventArgs : IPlayerEvent, IDeniableEvent public ChangingMicroHIDStateEventArgs(Player player, MicroHIDItem microHID, HidState oldState, HidState newState, bool isAllowed = true) { Player = player; - MicroHID = (MicroHid)Item.Get(microHID); + MicroHID = Item.Get(microHID); OldState = oldState; NewState = newState; IsAllowed = isAllowed; diff --git a/EXILED/Exiled.Events/EventArgs/Player/ChangingRadioPresetEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/ChangingRadioPresetEventArgs.cs index 7b59f2fb9..70af9b581 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/ChangingRadioPresetEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/ChangingRadioPresetEventArgs.cs @@ -44,7 +44,7 @@ public class ChangingRadioPresetEventArgs : IPlayerEvent, IItemEvent, IDeniableE public ChangingRadioPresetEventArgs(Player player, RadioItem item, RadioRangeLevel oldValue, RadioRangeLevel newValue, bool isAllowed = true) { Player = player; - Radio = (Radio)Item.Get(item); + Radio = Item.Get(item); OldValue = (RadioRange)oldValue; NewValue = (RadioRange)newValue; IsAllowed = isAllowed; diff --git a/EXILED/Exiled.Events/EventArgs/Player/DroppedItemEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/DroppedItemEventArgs.cs index 14d298c84..0109a4bba 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/DroppedItemEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/DroppedItemEventArgs.cs @@ -10,6 +10,7 @@ namespace Exiled.Events.EventArgs.Player using API.Features; using Exiled.API.Features.Pickups; using Interfaces; + using InventorySystem.Items.Pickups; /// /// Contains all information after a player drops an item. @@ -28,10 +29,10 @@ public class DroppedItemEventArgs : IPlayerEvent, IPickupEvent /// /// /// - public DroppedItemEventArgs(Player player, Pickup pickup, bool wasThrown) + public DroppedItemEventArgs(Player player, ItemPickupBase pickup, bool wasThrown) { Player = player; - Pickup = pickup; + Pickup = Pickup.Get(pickup); WasThrown = wasThrown; } diff --git a/EXILED/Exiled.Events/EventArgs/Player/ThrowingRequestEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/ThrowingRequestEventArgs.cs index 273763fda..089695333 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/ThrowingRequestEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/ThrowingRequestEventArgs.cs @@ -28,7 +28,7 @@ public class ThrowingRequestEventArgs : IPlayerEvent, IItemEvent public ThrowingRequestEventArgs(Player player, ThrowableItem item, ThrowableNetworkHandler.RequestType request) { Player = player; - Throwable = (Throwable)Item.Get(item); + Throwable = Item.Get(item); RequestType = (ThrowRequest)request; } diff --git a/EXILED/Exiled.Events/EventArgs/Player/ThrownProjectileEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/ThrownProjectileEventArgs.cs index aaf654d42..26984b839 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/ThrownProjectileEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/ThrownProjectileEventArgs.cs @@ -29,8 +29,8 @@ public class ThrownProjectileEventArgs : IPlayerEvent, IItemEvent, IPickupEvent public ThrownProjectileEventArgs(ThrownProjectile projectile, Player player, ThrowableItem item) { Player = player; - Throwable = (Throwable)Item.Get(item); - Projectile = (Projectile)Pickup.Get(projectile); + Throwable = Item.Get(item); + Projectile = Pickup.Get(projectile); } /// diff --git a/EXILED/Exiled.Events/EventArgs/Player/TogglingFlashlightEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/TogglingFlashlightEventArgs.cs index b8990f85d..3a87a66a1 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/TogglingFlashlightEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/TogglingFlashlightEventArgs.cs @@ -35,7 +35,7 @@ public class TogglingFlashlightEventArgs : IPlayerEvent, IDeniableEvent, IItemEv public TogglingFlashlightEventArgs(ReferenceHub hub, ToggleableLightItemBase flashlight, bool newState) { Player = Player.Get(hub); - Flashlight = (Flashlight)Item.Get(flashlight); + Flashlight = Item.Get(flashlight); initialState = newState; NewState = newState; } diff --git a/EXILED/Exiled.Events/EventArgs/Player/TogglingRadioEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/TogglingRadioEventArgs.cs index 67db54505..38d0fe09b 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/TogglingRadioEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/TogglingRadioEventArgs.cs @@ -36,7 +36,7 @@ public class TogglingRadioEventArgs : IPlayerEvent, IDeniableEvent, IItemEvent public TogglingRadioEventArgs(Player player, RadioItem radio, bool newState, bool isAllowed = true) { Player = player; - Radio = (Radio)Item.Get(radio); + Radio = Item.Get(radio); NewState = newState; IsAllowed = isAllowed; } diff --git a/EXILED/Exiled.Events/EventArgs/Player/UsingMicroHIDEnergyEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/UsingMicroHIDEnergyEventArgs.cs index d98f014ed..402d20e1b 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/UsingMicroHIDEnergyEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/UsingMicroHIDEnergyEventArgs.cs @@ -40,7 +40,7 @@ public class UsingMicroHIDEnergyEventArgs : IPlayerEvent, IDeniableEvent, IItemE public UsingMicroHIDEnergyEventArgs(Player player, MicroHIDItem microHIDitem, HidState currentState, float drain, bool isAllowed = true) { Player = player; - MicroHID = (MicroHid)Item.Get(microHIDitem); + MicroHID = Item.Get(microHIDitem); CurrentState = currentState; Drain = drain; IsAllowed = isAllowed; diff --git a/EXILED/Exiled.Events/EventArgs/Player/UsingRadioBatteryEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Player/UsingRadioBatteryEventArgs.cs index 90369883f..1f07dadde 100644 --- a/EXILED/Exiled.Events/EventArgs/Player/UsingRadioBatteryEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Player/UsingRadioBatteryEventArgs.cs @@ -36,7 +36,7 @@ public class UsingRadioBatteryEventArgs : IPlayerEvent, IDeniableEvent, IItemEve /// public UsingRadioBatteryEventArgs(RadioItem radio, Player player, float drain, bool isAllowed = true) { - Radio = (Radio)Item.Get(radio); + Radio = Item.Get(radio); Player = player; Drain = drain; IsAllowed = isAllowed; diff --git a/EXILED/Exiled.Events/EventArgs/Scp096/StartPryingGateEventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp096/StartPryingGateEventArgs.cs index f40e1e874..be8cef0ce 100644 --- a/EXILED/Exiled.Events/EventArgs/Scp096/StartPryingGateEventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Scp096/StartPryingGateEventArgs.cs @@ -36,7 +36,7 @@ public StartPryingGateEventArgs(Player player, PryableDoor gate, bool isAllowed { Player = player; Scp096 = player.Role.As(); - Gate = Door.Get(gate).As(); + Gate = Door.Get(gate); IsAllowed = isAllowed; } diff --git a/EXILED/Exiled.Events/EventArgs/Scp244/UsingScp244EventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp244/UsingScp244EventArgs.cs index c3077777c..5dca87a99 100644 --- a/EXILED/Exiled.Events/EventArgs/Scp244/UsingScp244EventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Scp244/UsingScp244EventArgs.cs @@ -33,7 +33,7 @@ public class UsingScp244EventArgs : IPlayerEvent, IDeniableEvent /// public UsingScp244EventArgs(Scp244Item scp244, Player player, bool isAllowed = true) { - Scp244 = (Scp244)Item.Get(scp244); + Scp244 = Item.Get(scp244); Player = player; IsAllowed = isAllowed; } diff --git a/EXILED/Exiled.Events/EventArgs/Scp330/DroppingScp330EventArgs.cs b/EXILED/Exiled.Events/EventArgs/Scp330/DroppingScp330EventArgs.cs index 0105cc1a1..985e90337 100644 --- a/EXILED/Exiled.Events/EventArgs/Scp330/DroppingScp330EventArgs.cs +++ b/EXILED/Exiled.Events/EventArgs/Scp330/DroppingScp330EventArgs.cs @@ -34,7 +34,7 @@ public class DroppingScp330EventArgs : IPlayerEvent, IScp330Event, IDeniableEven public DroppingScp330EventArgs(Player player, Scp330Bag scp330, CandyKindID candy) { Player = player; - Scp330 = (Scp330)Item.Get(scp330); + Scp330 = Item.Get(scp330); Candy = candy; } diff --git a/EXILED/Exiled.Events/Patches/Events/Item/ChangingAttachments.cs b/EXILED/Exiled.Events/Patches/Events/Item/ChangingAttachments.cs index 3e49274a0..17394e444 100644 --- a/EXILED/Exiled.Events/Patches/Events/Item/ChangingAttachments.cs +++ b/EXILED/Exiled.Events/Patches/Events/Item/ChangingAttachments.cs @@ -8,6 +8,7 @@ namespace Exiled.Events.Patches.Events.Item { using System.Collections.Generic; + using System.Linq; using System.Reflection.Emit; using API.Features; @@ -67,10 +68,8 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable newInstructions = ListPool.Pool.Get(instructions); - Label continueLabel = generator.DefineLabel(); - LocalBuilder pickup = generator.DeclareLocal(typeof(ItemPickupBase)); - int index = newInstructions.FindLastIndex(i => i.opcode == OpCodes.Dup); - - newInstructions.RemoveRange(index, 1); - - int offset = 1; - index = newInstructions.FindIndex(i => i.opcode == OpCodes.Dup) + offset; - newInstructions.InsertRange(index, new CodeInstruction[] - { - new(OpCodes.Dup), - new(OpCodes.Stloc_S, pickup.LocalIndex), - }); + Label continueLabel = generator.DefineLabel(); - offset = -2; - index = newInstructions.FindIndex(i => i.Calls(Method(typeof(NetworkServer), nameof(NetworkServer.Spawn), new[] { typeof(GameObject), typeof(NetworkConnection) }))) + offset; + int offset = -2; + int index = newInstructions.FindIndex(i => i.Calls(Method(typeof(NetworkServer), nameof(NetworkServer.Spawn), new[] { typeof(GameObject), typeof(NetworkConnection) }))) + offset; newInstructions.InsertRange(index, new[] { - new CodeInstruction(OpCodes.Ldsfld, Field(typeof(Scp244Spawner), nameof(Scp244Spawner.CompatibleRooms))).MoveLabelsFrom(newInstructions[index]), + // save Pickup from the stack + new CodeInstruction(OpCodes.Stloc_S, pickup.LocalIndex).MoveLabelsFrom(newInstructions[index]), + + // Scp244Spawner.CompatibleRooms[num] + new(OpCodes.Ldsfld, Field(typeof(Scp244Spawner), nameof(Scp244Spawner.CompatibleRooms))), new(OpCodes.Ldloc_0), new(OpCodes.Callvirt, PropertyGetter(typeof(List), "Item")), - new(OpCodes.Ldloc_S, pickup.LocalIndex), - new(OpCodes.Call, Method(typeof(Pickup), nameof(Pickup.Get), new[] { typeof(ItemPickupBase) })), + // scp244DeployablePickup + new(OpCodes.Ldloc_2), + // Scp244SpawningEventArgs ev = new(Room, Scp244DeployablePickup) new(OpCodes.Newobj, GetDeclaredConstructors(typeof(Scp244SpawningEventArgs))[0]), new(OpCodes.Dup), new(OpCodes.Call, Method(typeof(Handlers.Map), nameof(Handlers.Map.OnScp244Spawning))), + // if (ev.IsAllowed) goto continueLabel; new(OpCodes.Call, PropertyGetter(typeof(Scp244SpawningEventArgs), nameof(Scp244SpawningEventArgs.IsAllowed))), new(OpCodes.Brtrue_S, continueLabel), - new(OpCodes.Ldloc_S, pickup.LocalIndex), + // scp244DeployablePickup.gameObject.Destroy() + // return; + new(OpCodes.Ldloc_2), new(OpCodes.Callvirt, PropertyGetter(typeof(ItemPickupBase), nameof(ItemPickupBase.gameObject))), new(OpCodes.Call, Method(typeof(NetworkServer), nameof(NetworkServer.Destroy))), new(OpCodes.Ret), - new CodeInstruction(OpCodes.Nop).WithLabels(continueLabel), - new(OpCodes.Ldloc_S, pickup.LocalIndex), + // load pickup back into the stack + new CodeInstruction(OpCodes.Ldloc_S, pickup.LocalIndex).WithLabels(continueLabel), }); for (int z = 0; z < newInstructions.Count; z++) diff --git a/EXILED/Exiled.Events/Patches/Events/Player/DroppingItem.cs b/EXILED/Exiled.Events/Patches/Events/Player/DroppingItem.cs index 0e0311532..26d8cb2cc 100644 --- a/EXILED/Exiled.Events/Patches/Events/Player/DroppingItem.cs +++ b/EXILED/Exiled.Events/Patches/Events/Player/DroppingItem.cs @@ -11,14 +11,12 @@ namespace Exiled.Events.Patches.Events.Player using System.Reflection.Emit; using API.Features.Pools; - using Exiled.API.Features.Pickups; using Exiled.Events.Attributes; using Exiled.Events.EventArgs.Player; using HarmonyLib; using InventorySystem; - using InventorySystem.Items.Pickups; using static HarmonyLib.AccessTools; @@ -117,15 +115,14 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable !x.IsGenericMethod && x.Name is nameof(API.Features.Items.Item.Get) && x.GetParameters().Length is 1 && x.GetParameters()[0].ParameterType == typeof(ItemBase))), new(OpCodes.Isinst, typeof(Firearm)), new(OpCodes.Dup), new(OpCodes.Stloc_S, firearm.LocalIndex), diff --git a/EXILED/Exiled.Events/Patches/Fixes/GrenadePropertiesFix.cs b/EXILED/Exiled.Events/Patches/Fixes/GrenadePropertiesFix.cs index 8c37c4f9a..e37fb8993 100644 --- a/EXILED/Exiled.Events/Patches/Fixes/GrenadePropertiesFix.cs +++ b/EXILED/Exiled.Events/Patches/Fixes/GrenadePropertiesFix.cs @@ -8,6 +8,7 @@ namespace Exiled.Events.Patches.Fixes { using System.Collections.Generic; + using System.Linq; using System.Reflection.Emit; using API.Features.Items; @@ -58,7 +59,7 @@ private static IEnumerable Transpiler(IEnumerable !x.IsGenericMethod && x.Name is nameof(Item.Get) && x.GetParameters().Length is 1 && x.GetParameters()[0].ParameterType == typeof(ItemBase))), new(OpCodes.Isinst, typeof(Throwable)), new(OpCodes.Dup), new(OpCodes.Stloc_S, throwable.LocalIndex), diff --git a/EXILED/Exiled.Events/Patches/Generic/DoorList.cs b/EXILED/Exiled.Events/Patches/Generic/DoorList.cs index 1b63ec329..4f1ce6e33 100644 --- a/EXILED/Exiled.Events/Patches/Generic/DoorList.cs +++ b/EXILED/Exiled.Events/Patches/Generic/DoorList.cs @@ -50,7 +50,7 @@ private static void Postfix(DoorVariant __instance) foreach (DoorVariant subDoor in checkpoint.Base.SubDoors) { subDoor.RegisterRooms(); - BreakableDoor targetDoor = Door.Get(subDoor).Cast(); + BreakableDoor targetDoor = Door.Get(subDoor); targetDoor.ParentCheckpointDoor = checkpoint; checkpoint.SubDoorsValue.Add(targetDoor); diff --git a/EXILED/Exiled.Events/Patches/Generic/PickupControlPatch.cs b/EXILED/Exiled.Events/Patches/Generic/PickupControlPatch.cs index c76a8f247..fc319c474 100644 --- a/EXILED/Exiled.Events/Patches/Generic/PickupControlPatch.cs +++ b/EXILED/Exiled.Events/Patches/Generic/PickupControlPatch.cs @@ -9,6 +9,7 @@ namespace Exiled.Events.Patches.Generic { using System; using System.Collections.Generic; + using System.Linq; using System.Reflection.Emit; using API.Features.Pickups; @@ -48,11 +49,11 @@ private static IEnumerable Transpiler( { // pickup = Pickup.Get(pickupBase); new(OpCodes.Ldloc_0), - new(OpCodes.Call, Method(typeof(Pickup), nameof(Pickup.Get), new[] { typeof(ItemPickupBase) })), + new(OpCodes.Call, GetDeclaredMethods(typeof(Pickup)).First(x => !x.IsGenericMethod && x.Name is nameof(Pickup.Get) && x.GetParameters().Length is 1 && x.GetParameters()[0].ParameterType == typeof(ItemPickupBase))), // Item.Get(itemBase); new(OpCodes.Ldarg_0), - new(OpCodes.Call, Method(typeof(Item), nameof(Item.Get), new[] { typeof(ItemBase) })), + new(OpCodes.Call, GetDeclaredMethods(typeof(Item)).First(x => !x.IsGenericMethod && x.Name is nameof(Item.Get) && x.GetParameters().Length is 1 && x.GetParameters()[0].ParameterType == typeof(ItemBase))), // pickup.ReadItemInfo(item); new(OpCodes.Callvirt, Method(typeof(Pickup), nameof(Pickup.ReadItemInfo))), @@ -79,7 +80,7 @@ private static IEnumerable Transpiler(IEnumerable !x.IsGenericMethod && x.Name is nameof(Pickup.Get) && x.GetParameters().Length is 1 && x.GetParameters()[0].ParameterType == typeof(ItemPickupBase))), new(OpCodes.Pop), });