From 6f83b3b5a4d7a87330c7110ddd8abf89bef729d8 Mon Sep 17 00:00:00 2001
From: VALERA771 <72030575+VALERA771@users.noreply.github.com>
Date: Sun, 7 Apr 2024 20:46:14 +0300
Subject: [PATCH 1/3] `[Exiled::API]` Scp914 processors (#2450)
* standart + base
* new
* fix
* events
* fix
---------
Co-authored-by: Yamato <66829532+louis1706@users.noreply.github.com>
---
Exiled.API/Features/Map.cs | 2 +
Exiled.API/Features/Scp914.cs | 9 ++
.../Scp914Processors/AmmoProcessor.cs | 67 +++++++++++
.../Scp914Processors/FirearmProcessor.cs | 93 +++++++++++++++
.../Scp914Processors/MicroHidProcessor.cs | 35 ++++++
.../Scp914Processors/Scp914Processor.cs | 82 ++++++++++++++
.../Scp914Processors/StandardProcessor.cs | 106 ++++++++++++++++++
.../CustomItems/UpgradingEventArgs.cs | 2 +-
.../CustomItems/UpgradingItemEventArgs.cs | 2 +-
.../Scp914/UpgradedInventoryItemEventArgs.cs | 44 ++++++++
.../Scp914/UpgradedPickupEventArgs.cs | 40 +++++++
.../Scp914/UpgradingInventoryItemEventArgs.cs | 13 ++-
.../Scp914/UpgradingPickupEventArgs.cs | 12 +-
Exiled.Events/Handlers/Scp914.cs | 22 ++++
.../Patches/Events/Scp914/UpgradingItem.cs | 30 ++++-
.../Patches/Events/Scp914/UpgradingPlayer.cs | 48 +++++++-
16 files changed, 595 insertions(+), 12 deletions(-)
create mode 100644 Exiled.API/Features/Scp914Processors/AmmoProcessor.cs
create mode 100644 Exiled.API/Features/Scp914Processors/FirearmProcessor.cs
create mode 100644 Exiled.API/Features/Scp914Processors/MicroHidProcessor.cs
create mode 100644 Exiled.API/Features/Scp914Processors/Scp914Processor.cs
create mode 100644 Exiled.API/Features/Scp914Processors/StandardProcessor.cs
create mode 100644 Exiled.Events/EventArgs/Scp914/UpgradedInventoryItemEventArgs.cs
create mode 100644 Exiled.Events/EventArgs/Scp914/UpgradedPickupEventArgs.cs
diff --git a/Exiled.API/Features/Map.cs b/Exiled.API/Features/Map.cs
index 6b8a5f317b..c8e4215dd4 100644
--- a/Exiled.API/Features/Map.cs
+++ b/Exiled.API/Features/Map.cs
@@ -17,6 +17,7 @@ namespace Exiled.API.Features
using Exiled.API.Extensions;
using Exiled.API.Features.Hazards;
using Exiled.API.Features.Pickups;
+ using Exiled.API.Features.Scp914Processors;
using Exiled.API.Features.Toys;
using global::Hazards;
using InventorySystem;
@@ -413,6 +414,7 @@ internal static void ClearCache()
Firearm.BaseCodesValue.Clear();
Firearm.AvailableAttachmentsValue.Clear();
+ Scp914Processor.ProcessorToWrapper.Clear();
Workstation.BaseToWrapper.Clear();
}
}
diff --git a/Exiled.API/Features/Scp914.cs b/Exiled.API/Features/Scp914.cs
index c344f397e3..73f0392f32 100644
--- a/Exiled.API/Features/Scp914.cs
+++ b/Exiled.API/Features/Scp914.cs
@@ -13,7 +13,9 @@ namespace Exiled.API.Features
using Exiled.API.Features.Core.Generic.Pools;
using Exiled.API.Features.Doors;
using Exiled.API.Features.Pickups;
+ using Exiled.API.Features.Scp914Processors;
using global::Scp914;
+ using global::Scp914.Processors;
using UnityEngine;
///
@@ -141,5 +143,12 @@ public static IEnumerable Scp914InputObject(out IEnumerable
/// who interacts with Scp914.
/// Interact code.
public static void Start(Player player = null, Scp914InteractCode code = Scp914InteractCode.Activate) => Scp914Controller.ServerInteract((player ?? Server.Host).ReferenceHub, (byte)code);
+
+ ///
+ /// Gets the for .
+ ///
+ /// Item for which processor should be returned.
+ /// The if item has it. Otherwise, .
+ public static Scp914Processor GetProcessor(ItemType itemType) => Scp914Upgrader.TryGetProcessor(itemType, out Scp914ItemProcessor scp914ItemProcessor) ? Scp914Processor.Get(scp914ItemProcessor) : null;
}
}
diff --git a/Exiled.API/Features/Scp914Processors/AmmoProcessor.cs b/Exiled.API/Features/Scp914Processors/AmmoProcessor.cs
new file mode 100644
index 0000000000..5b97b89fa1
--- /dev/null
+++ b/Exiled.API/Features/Scp914Processors/AmmoProcessor.cs
@@ -0,0 +1,67 @@
+// -----------------------------------------------------------------------
+//
+// Copyright (c) Exiled Team. All rights reserved.
+// Licensed under the CC BY-SA 3.0 license.
+//
+// -----------------------------------------------------------------------
+
+namespace Exiled.API.Features.Scp914Processors
+{
+ using Exiled.API.Interfaces;
+ using global::Scp914;
+ using global::Scp914.Processors;
+
+ ///
+ /// A processor for .
+ ///
+ public class AmmoProcessor : Scp914Processor, IWrapper
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The instance.
+ public AmmoProcessor(AmmoItemProcessor scp914ItemProcessor)
+ : base(scp914ItemProcessor)
+ {
+ Base = scp914ItemProcessor;
+ }
+
+ ///
+ public new AmmoItemProcessor Base { get; }
+
+ ///
+ /// Gets or sets a new to which item will be upgraded on or .
+ ///
+ public ItemType PreviousAmmo
+ {
+ get => Base._previousAmmo;
+ set => Base._previousAmmo = value;
+ }
+
+ ///
+ /// Gets or sets a new to which item will be upgraded on .
+ ///
+ public ItemType OneToOneAmmo
+ {
+ get => Base._oneToOne;
+ set => Base._oneToOne = value;
+ }
+
+ ///
+ /// Gets or sets a new to which item will be upgraded on or .
+ ///
+ public ItemType NextAmmo
+ {
+ get => Base._nextAmmo;
+ set => Base._nextAmmo = value;
+ }
+
+ ///
+ public override ItemType GetRandomOutput(Scp914KnobSetting knobSetting, ItemType previousItem) => knobSetting switch
+ {
+ Scp914KnobSetting.Rough or Scp914KnobSetting.Coarse => PreviousAmmo,
+ Scp914KnobSetting.OneToOne => OneToOneAmmo,
+ _ => NextAmmo
+ };
+ }
+}
\ No newline at end of file
diff --git a/Exiled.API/Features/Scp914Processors/FirearmProcessor.cs b/Exiled.API/Features/Scp914Processors/FirearmProcessor.cs
new file mode 100644
index 0000000000..58d71f9dd1
--- /dev/null
+++ b/Exiled.API/Features/Scp914Processors/FirearmProcessor.cs
@@ -0,0 +1,93 @@
+// -----------------------------------------------------------------------
+//
+// Copyright (c) Exiled Team. All rights reserved.
+// Licensed under the CC BY-SA 3.0 license.
+//
+// -----------------------------------------------------------------------
+
+namespace Exiled.API.Features.Scp914Processors
+{
+ using System.Collections.Generic;
+ using System.Linq;
+
+ using Exiled.API.Extensions;
+ using Exiled.API.Interfaces;
+ using global::Scp914;
+ using global::Scp914.Processors;
+
+ ///
+ /// A processor for .
+ ///
+ public class FirearmProcessor : Scp914Processor, IWrapper
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The instance.
+ public FirearmProcessor(FirearmItemProcessor scp914ItemProcessor)
+ : base(scp914ItemProcessor)
+ {
+ Base = scp914ItemProcessor;
+ }
+
+ ///
+ public new FirearmItemProcessor Base { get; }
+
+ ///
+ /// Gets or sets a value indicating whether or not magazine should be refilled.
+ ///
+ public bool RefillAmmo
+ {
+ get => Base._refillAmmo;
+ set => Base._refillAmmo = value;
+ }
+
+ ///
+ /// Gets or sets a list of items that replace upgrading item when is .
+ ///
+ public IEnumerable RoughOutputs
+ {
+ get => Base._roughOutputs;
+ set => Base._roughOutputs = value.ToArray();
+ }
+
+ ///
+ /// Gets or sets a list of items that replace upgrading item when is .
+ ///
+ public IEnumerable CoarseOutputs
+ {
+ get => Base._coarseOutputs;
+ set => Base._coarseOutputs = value.ToArray();
+ }
+
+ ///
+ /// Gets or sets a list of items that replace upgrading item when is .
+ ///
+ public IEnumerable OneToOneOutputs
+ {
+ get => Base._oneToOneOutputs;
+ set => Base._oneToOneOutputs = value.ToArray();
+ }
+
+ ///
+ /// Gets or sets a list of items that replace upgrading item when is .
+ ///
+ public IEnumerable FineOutputs
+ {
+ get => Base._fineOutputs;
+ set => Base._fineOutputs = value.ToArray();
+ }
+
+ ///
+ /// Gets or sets a list of items that replace upgrading item when is .
+ ///
+ public IEnumerable VeryFineOutputs
+ {
+ get => Base._veryFineOutputs;
+ set => Base._veryFineOutputs = value.ToArray();
+ }
+
+ ///
+ public override ItemType GetRandomOutput(Scp914KnobSetting knobSetting, ItemType previousItem) => Base.GetItems(knobSetting, previousItem).Random();
+ }
+}
\ No newline at end of file
diff --git a/Exiled.API/Features/Scp914Processors/MicroHidProcessor.cs b/Exiled.API/Features/Scp914Processors/MicroHidProcessor.cs
new file mode 100644
index 0000000000..12cbbe3ce8
--- /dev/null
+++ b/Exiled.API/Features/Scp914Processors/MicroHidProcessor.cs
@@ -0,0 +1,35 @@
+// -----------------------------------------------------------------------
+//
+// Copyright (c) Exiled Team. All rights reserved.
+// Licensed under the CC BY-SA 3.0 license.
+//
+// -----------------------------------------------------------------------
+
+namespace Exiled.API.Features.Scp914Processors
+{
+ using Exiled.API.Interfaces;
+ using global::Scp914;
+ using global::Scp914.Processors;
+
+ ///
+ /// A processor for .
+ ///
+ public class MicroHidProcessor : Scp914Processor, IWrapper
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The instance.
+ public MicroHidProcessor(MicroHidItemProcessor scp914ItemProcessor)
+ : base(scp914ItemProcessor)
+ {
+ Base = scp914ItemProcessor;
+ }
+
+ ///
+ public new MicroHidItemProcessor Base { get; }
+
+ ///
+ public override ItemType GetRandomOutput(Scp914KnobSetting knobSetting, ItemType previousItem) => Base.GetOutput(knobSetting);
+ }
+}
\ No newline at end of file
diff --git a/Exiled.API/Features/Scp914Processors/Scp914Processor.cs b/Exiled.API/Features/Scp914Processors/Scp914Processor.cs
new file mode 100644
index 0000000000..f6c7dea43b
--- /dev/null
+++ b/Exiled.API/Features/Scp914Processors/Scp914Processor.cs
@@ -0,0 +1,82 @@
+// -----------------------------------------------------------------------
+//
+// Copyright (c) Exiled Team. All rights reserved.
+// Licensed under the CC BY-SA 3.0 license.
+//
+// -----------------------------------------------------------------------
+
+namespace Exiled.API.Features.Scp914Processors
+{
+ using System.Collections.Generic;
+
+ using Exiled.API.Features.Core;
+ using Exiled.API.Features.Items;
+ using Exiled.API.Features.Pickups;
+ using Exiled.API.Interfaces;
+ using global::Scp914;
+ using global::Scp914.Processors;
+
+ ///
+ /// A wrapper for base class for all processors.
+ ///
+ public class Scp914Processor : TypeCastObject, IWrapper
+ {
+ ///
+ /// Gets the with and .
+ ///
+ internal static readonly Dictionary ProcessorToWrapper = new();
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The instance.
+ public Scp914Processor(Scp914ItemProcessor scp914ItemProcessor)
+ {
+ Base = scp914ItemProcessor;
+
+ ProcessorToWrapper.Add(scp914ItemProcessor, this);
+ }
+
+ ///
+ public Scp914ItemProcessor Base { get; }
+
+ ///
+ /// Gets a from it's base .
+ ///
+ /// The instance.
+ /// The instance.
+ public static Scp914Processor Get(Scp914ItemProcessor scp914ItemProcessor) => ProcessorToWrapper.TryGetValue(scp914ItemProcessor, out Scp914Processor processor) ? processor : scp914ItemProcessor switch
+ {
+ AmmoItemProcessor ammoItemProcessor => new AmmoProcessor(ammoItemProcessor),
+ FirearmItemProcessor firearmItemProcessor => new FirearmProcessor(firearmItemProcessor),
+ MicroHidItemProcessor microHidItemProcessor => new MicroHidProcessor(microHidItemProcessor),
+ StandardItemProcessor standardItemProcessor => new StandardProcessor(standardItemProcessor),
+ _ => new Scp914Processor(scp914ItemProcessor)
+ };
+
+ ///
+ /// Upgrades an item from player's inventory.
+ ///
+ /// Player from whose inventory item will be chosen.
+ /// Item to update.
+ /// Setting to use.
+ /// A new upgraded item.
+ public Item UpgradeInventoryItem(Player player, Item item, Scp914KnobSetting scp914KnobSetting) => Item.Get(Base.OnInventoryItemUpgraded(scp914KnobSetting, player.ReferenceHub, item.Serial));
+
+ ///
+ /// Upgrades an pickup from player's inventory.
+ ///
+ /// Pickup to update.
+ /// Setting to use.
+ /// A new upgraded pickup.
+ public Pickup UpgradePickup(Pickup pickup, Scp914KnobSetting scp914KnobSetting) => Pickup.Get(Base.OnPickupUpgraded(scp914KnobSetting, pickup.Base, Scp914.MovingVector));
+
+ ///
+ /// Gets a random output item.
+ ///
+ /// Selected .
+ /// The item to be updated.
+ /// A new item.
+ public virtual ItemType GetRandomOutput(Scp914KnobSetting knobSetting, ItemType previousItem) => previousItem;
+ }
+}
\ No newline at end of file
diff --git a/Exiled.API/Features/Scp914Processors/StandardProcessor.cs b/Exiled.API/Features/Scp914Processors/StandardProcessor.cs
new file mode 100644
index 0000000000..a834627422
--- /dev/null
+++ b/Exiled.API/Features/Scp914Processors/StandardProcessor.cs
@@ -0,0 +1,106 @@
+// -----------------------------------------------------------------------
+//
+// Copyright (c) Exiled Team. All rights reserved.
+// Licensed under the CC BY-SA 3.0 license.
+//
+// -----------------------------------------------------------------------
+
+namespace Exiled.API.Features.Scp914Processors
+{
+ using System.Collections.Generic;
+ using System.Linq;
+
+ using Exiled.API.Features.Pickups;
+ using Exiled.API.Interfaces;
+ using global::Scp914;
+ using global::Scp914.Processors;
+ using UnityEngine;
+
+ ///
+ /// A processor for most of items.
+ ///
+ public class StandardProcessor : Scp914Processor, IWrapper
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The base instance.
+ public StandardProcessor(StandardItemProcessor processor)
+ : base(processor)
+ {
+ Base = processor;
+ }
+
+ ///
+ public new StandardItemProcessor Base { get; }
+
+ ///
+ /// Gets or sets a list of items that replace upgrading item when is .
+ ///
+ public IEnumerable RoughOutputs
+ {
+ get => Base._roughOutputs;
+ set => Base._roughOutputs = value.ToArray();
+ }
+
+ ///
+ /// Gets or sets a list of items that replace upgrading item when is .
+ ///
+ public IEnumerable CoarseOutputs
+ {
+ get => Base._coarseOutputs;
+ set => Base._coarseOutputs = value.ToArray();
+ }
+
+ ///
+ /// Gets or sets a list of items that replace upgrading item when is .
+ ///
+ public IEnumerable OneToOneOutputs
+ {
+ get => Base._oneToOneOutputs;
+ set => Base._oneToOneOutputs = value.ToArray();
+ }
+
+ ///
+ /// Gets or sets a list of items that replace upgrading item when is .
+ ///
+ public IEnumerable FineOutputs
+ {
+ get => Base._fineOutputs;
+ set => Base._fineOutputs = value.ToArray();
+ }
+
+ ///
+ /// Gets or sets a list of items that replace upgrading item when is .
+ ///
+ public IEnumerable VeryFineOutputs
+ {
+ get => Base._veryFineOutputs;
+ set => Base._veryFineOutputs = value.ToArray();
+ }
+
+ ///
+ /// Gets or sets a value indicating whether or not item which has will execute method for updating.
+ ///
+ public bool FireTrigger
+ {
+ get => Base._fireUpgradeTrigger;
+ set => Base._fireUpgradeTrigger = value;
+ }
+
+ ///
+ public override ItemType GetRandomOutput(Scp914KnobSetting knobSetting, ItemType previousItem) => Base.RandomOutput(knobSetting, previousItem);
+
+ ///
+ /// Handles pickup if new was None.
+ ///
+ /// Pickup to handle.
+ public void HandleNone(Pickup pickup) => Base.HandleNone(pickup.Base, Vector3.zero);
+
+ ///
+ /// Handles old pickup that has been upgraded.
+ ///
+ /// Pickup to handle.
+ public void HandleOldPickup(Pickup pickup) => Base.HandleOldPickup(pickup.Base, Vector3.zero);
+ }
+}
\ No newline at end of file
diff --git a/Exiled.CustomModules/Events/EventArgs/CustomItems/UpgradingEventArgs.cs b/Exiled.CustomModules/Events/EventArgs/CustomItems/UpgradingEventArgs.cs
index 02aa779b02..969bae59e9 100644
--- a/Exiled.CustomModules/Events/EventArgs/CustomItems/UpgradingEventArgs.cs
+++ b/Exiled.CustomModules/Events/EventArgs/CustomItems/UpgradingEventArgs.cs
@@ -31,7 +31,7 @@ public class UpgradingEventArgs : UpgradingPickupEventArgs, ICustomPickupEvent
///
///
public UpgradingEventArgs(Pickup pickup, CustomItem customItem, ItemBehaviour itemBehaviour, Vector3 newPos, Scp914KnobSetting knobSetting, bool isAllowed = true)
- : base(pickup.Base, newPos, knobSetting)
+ : base(pickup.Base, newPos, knobSetting, Exiled.API.Features.Scp914.GetProcessor(customItem.Settings.ItemType))
{
IsAllowed = isAllowed;
CustomItem = customItem;
diff --git a/Exiled.CustomModules/Events/EventArgs/CustomItems/UpgradingItemEventArgs.cs b/Exiled.CustomModules/Events/EventArgs/CustomItems/UpgradingItemEventArgs.cs
index 6cdc67c046..fc4cb972f6 100644
--- a/Exiled.CustomModules/Events/EventArgs/CustomItems/UpgradingItemEventArgs.cs
+++ b/Exiled.CustomModules/Events/EventArgs/CustomItems/UpgradingItemEventArgs.cs
@@ -31,7 +31,7 @@ public class UpgradingItemEventArgs : UpgradingInventoryItemEventArgs, ICustomIt
///
///
public UpgradingItemEventArgs(Player player, ItemBase item, CustomItem customItem, ItemBehaviour itemBehaviour, Scp914KnobSetting knobSetting, bool isAllowed = true)
- : base(player, item, knobSetting, isAllowed)
+ : base(player, item, knobSetting, Exiled.API.Features.Scp914.GetProcessor(item.ItemTypeId).Base, isAllowed)
{
CustomItem = customItem;
ItemBehaviour = itemBehaviour;
diff --git a/Exiled.Events/EventArgs/Scp914/UpgradedInventoryItemEventArgs.cs b/Exiled.Events/EventArgs/Scp914/UpgradedInventoryItemEventArgs.cs
new file mode 100644
index 0000000000..95bbb1d4f5
--- /dev/null
+++ b/Exiled.Events/EventArgs/Scp914/UpgradedInventoryItemEventArgs.cs
@@ -0,0 +1,44 @@
+// -----------------------------------------------------------------------
+//
+// Copyright (c) Exiled Team. All rights reserved.
+// Licensed under the CC BY-SA 3.0 license.
+//
+// -----------------------------------------------------------------------
+
+namespace Exiled.Events.EventArgs.Scp914
+{
+ using Exiled.API.Features;
+ using Exiled.API.Features.Items;
+ using Exiled.Events.EventArgs.Interfaces;
+ using global::Scp914;
+
+ ///
+ /// Contains all information after SCP-914 upgrades an item.
+ ///
+ public class UpgradedInventoryItemEventArgs : IItemEvent, IPlayerEvent
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ ///
+ ///
+ public UpgradedInventoryItemEventArgs(Player player, Item item, Scp914KnobSetting scp914KnobSetting)
+ {
+ Player = player;
+ Item = item;
+ Setting = scp914KnobSetting;
+ }
+
+ ///
+ /// Gets the on which item was upgraded.
+ ///
+ public Scp914KnobSetting Setting { get; }
+
+ ///
+ public Item Item { get; }
+
+ ///
+ public Player Player { get; }
+ }
+}
\ No newline at end of file
diff --git a/Exiled.Events/EventArgs/Scp914/UpgradedPickupEventArgs.cs b/Exiled.Events/EventArgs/Scp914/UpgradedPickupEventArgs.cs
new file mode 100644
index 0000000000..088083db9f
--- /dev/null
+++ b/Exiled.Events/EventArgs/Scp914/UpgradedPickupEventArgs.cs
@@ -0,0 +1,40 @@
+// -----------------------------------------------------------------------
+//
+// Copyright (c) Exiled Team. All rights reserved.
+// Licensed under the CC BY-SA 3.0 license.
+//
+// -----------------------------------------------------------------------
+
+namespace Exiled.Events.EventArgs.Scp914
+{
+ using Exiled.API.Features.Pickups;
+ using Exiled.Events.EventArgs.Interfaces;
+ using global::Scp914;
+
+ ///
+ /// Contains all information after SCP-914 upgrades an item.
+ ///
+ public class UpgradedPickupEventArgs : IPickupEvent
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ ///
+ ///
+ public UpgradedPickupEventArgs(Pickup pickup, Scp914KnobSetting scp914KnobSetting)
+ {
+ Pickup = pickup;
+ Setting = scp914KnobSetting;
+ }
+
+ ///
+ /// Gets the upgraded pickup.
+ ///
+ public Pickup Pickup { get; }
+
+ ///
+ /// Gets the on which item was upgraded.
+ ///
+ public Scp914KnobSetting Setting { get; }
+ }
+}
\ No newline at end of file
diff --git a/Exiled.Events/EventArgs/Scp914/UpgradingInventoryItemEventArgs.cs b/Exiled.Events/EventArgs/Scp914/UpgradingInventoryItemEventArgs.cs
index 8dd471a7fd..b765a0e638 100644
--- a/Exiled.Events/EventArgs/Scp914/UpgradingInventoryItemEventArgs.cs
+++ b/Exiled.Events/EventArgs/Scp914/UpgradingInventoryItemEventArgs.cs
@@ -11,7 +11,9 @@ namespace Exiled.Events.EventArgs.Scp914
using API.Features;
using API.Features.Items;
+ using Exiled.API.Features.Scp914Processors;
using global::Scp914;
+ using global::Scp914.Processors;
using Interfaces;
using InventorySystem.Items;
@@ -32,15 +34,19 @@ public class UpgradingInventoryItemEventArgs : IPlayerEvent, IItemEvent, IDeniab
///
///
///
+ ///
+ ///
+ ///
///
///
///
- public UpgradingInventoryItemEventArgs(Player player, ItemBase item, Scp914KnobSetting knobSetting, bool isAllowed = true)
+ public UpgradingInventoryItemEventArgs(Player player, ItemBase item, Scp914KnobSetting knobSetting, Scp914ItemProcessor processor, bool isAllowed = true)
{
Player = player;
Item = Item.Get(item);
KnobSetting = knobSetting;
IsAllowed = isAllowed;
+ Processor = Scp914Processor.Get(processor);
}
///
@@ -54,6 +60,11 @@ public UpgradingInventoryItemEventArgs(Player player, ItemBase item, Scp914KnobS
///
public Scp914KnobSetting KnobSetting { get; set; }
+ ///
+ /// Gets or sets a that will be used for upgrading item.
+ ///
+ public Scp914Processor Processor { get; set; }
+
///
/// Gets or sets a value indicating whether or not the upgrade is successful.
///
diff --git a/Exiled.Events/EventArgs/Scp914/UpgradingPickupEventArgs.cs b/Exiled.Events/EventArgs/Scp914/UpgradingPickupEventArgs.cs
index 22744d5885..8645d3a53b 100644
--- a/Exiled.Events/EventArgs/Scp914/UpgradingPickupEventArgs.cs
+++ b/Exiled.Events/EventArgs/Scp914/UpgradingPickupEventArgs.cs
@@ -10,6 +10,7 @@ namespace Exiled.Events.EventArgs.Scp914
using System;
using Exiled.API.Features.Pickups;
+ using Exiled.API.Features.Scp914Processors;
using Exiled.Events.EventArgs.Interfaces;
using global::Scp914;
using InventorySystem.Items.Pickups;
@@ -32,11 +33,15 @@ public class UpgradingPickupEventArgs : IPickupEvent, IDeniableEvent
///
///
///
- public UpgradingPickupEventArgs(ItemPickupBase item, Vector3 newPos, Scp914KnobSetting knobSetting)
+ ///
+ ///
+ ///
+ public UpgradingPickupEventArgs(ItemPickupBase item, Vector3 newPos, Scp914KnobSetting knobSetting, Scp914Processor processor)
{
Pickup = Pickup.Get(item);
OutputPosition = newPos;
KnobSetting = knobSetting;
+ Processor = processor;
}
///
@@ -60,6 +65,11 @@ public UpgradingPickupEventArgs(ItemPickupBase item, Vector3 newPos, Scp914KnobS
///
public Scp914KnobSetting KnobSetting { get; set; }
+ ///
+ /// Gets the for this item.
+ ///
+ public Scp914Processor Processor { get; }
+
///
/// Gets or sets a value indicating whether or not the upgrade is successful.
///
diff --git a/Exiled.Events/Handlers/Scp914.cs b/Exiled.Events/Handlers/Scp914.cs
index 77157ef904..37c21e4528 100644
--- a/Exiled.Events/Handlers/Scp914.cs
+++ b/Exiled.Events/Handlers/Scp914.cs
@@ -42,6 +42,16 @@ public static class Scp914
///
public static Event ChangingKnobSetting { get; set; } = new();
+ ///
+ /// Invoked after SCP-914 upgrades an item.
+ ///
+ public static Event UpgradedPickup { get; set; } = new();
+
+ ///
+ /// Invoked after SCP-914 upgrades an item.
+ ///
+ public static Event UpgradedInventoryItem { get; set; } = new();
+
///
/// Called before SCP-914 upgrades a item.
///
@@ -71,5 +81,17 @@ public static class Scp914
///
/// The instance.
public static void OnChangingKnobSetting(ChangingKnobSettingEventArgs ev) => ChangingKnobSetting.InvokeSafely(ev);
+
+ ///
+ /// Invoked after SCP-914 upgrades an item.
+ ///
+ /// The instance.
+ public static void OnUpgradedPickup(UpgradedPickupEventArgs ev) => UpgradedPickup.InvokeSafely(ev);
+
+ ///
+ /// Called after SCP-914 upgrades an item.
+ ///
+ /// The instance.
+ public static void OnUpgradedInventoryItem(UpgradedInventoryItemEventArgs ev) => UpgradedInventoryItem.InvokeSafely(ev);
}
}
\ No newline at end of file
diff --git a/Exiled.Events/Patches/Events/Scp914/UpgradingItem.cs b/Exiled.Events/Patches/Events/Scp914/UpgradingItem.cs
index 969be09191..df0abd12c2 100644
--- a/Exiled.Events/Patches/Events/Scp914/UpgradingItem.cs
+++ b/Exiled.Events/Patches/Events/Scp914/UpgradingItem.cs
@@ -11,22 +11,23 @@ namespace Exiled.Events.Patches.Events.Scp914
using System.Reflection.Emit;
using API.Features.Core.Generic.Pools;
+ using Exiled.API.Features.Pickups;
+ using Exiled.API.Features.Scp914Processors;
using Exiled.Events.Attributes;
using Exiled.Events.EventArgs.Scp914;
-
using global::Scp914;
-
using Handlers;
-
using HarmonyLib;
+ using InventorySystem.Items.Pickups;
using static HarmonyLib.AccessTools;
///
/// Patches .
- /// Adds the event.
+ /// Adds the and events.
///
[EventPatch(typeof(Scp914), nameof(Scp914.UpgradingPickup))]
+ [EventPatch(typeof(Scp914), nameof(Scp914.UpgradedPickup))]
[HarmonyPatch(typeof(Scp914Upgrader), nameof(Scp914Upgrader.ProcessPickup))]
internal static class UpgradingItem
{
@@ -53,6 +54,9 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable
/// Patches
- /// to add the and event.
+ /// to add the , and events.
///
[EventPatch(typeof(Scp914), nameof(Scp914.UpgradingPlayer))]
+ [EventPatch(typeof(Scp914), nameof(Scp914.UpgradedInventoryItem))]
[EventPatch(typeof(Scp914), nameof(Scp914.UpgradingInventoryItem))]
[HarmonyPatch(typeof(Scp914Upgrader), nameof(Scp914Upgrader.ProcessPlayer))]
internal static class UpgradingPlayer
@@ -37,7 +40,7 @@ private static IEnumerable Transpiler(IEnumerable newInstructions = ListPool.Pool.Get(instructions);
// Find override position
- const int offset = -3;
+ int offset = -3;
int index = newInstructions.FindIndex(instruction => instruction.Calls(Method(typeof(FpcExtensionMethods), nameof(FpcExtensionMethods.TryOverridePosition)))) + offset;
Label returnLabel = generator.DefineLabel();
@@ -144,9 +147,14 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable x.opcode == OpCodes.Newobj) + offset;
+
+ newInstructions.InsertRange(
+ index,
+ new[]
+ {
+ // Player.Get(ply)
+ new CodeInstruction(OpCodes.Ldarg_1).MoveLabelsFrom(newInstructions[index]),
+ new(OpCodes.Call, Method(typeof(Player), nameof(Player.Get), new[] { typeof(ReferenceHub) })),
+
+ // Item.Get(itemBase2)
+ new(OpCodes.Ldloc_S, 10),
+ new(OpCodes.Call, Method(typeof(Item), nameof(Item.Get), new[] { typeof(ItemBase) })),
+
+ // knobSetting
+ new(OpCodes.Ldarg_S, 4),
+
+ // UpgradedInventoryItemEventArgs ev = new(Player, Item, Scp914KnobSetting)
+ new(OpCodes.Newobj, GetDeclaredConstructors(typeof(UpgradedInventoryItemEventArgs))[0]),
+
+ // Scp914.OnUpgradedInventoryItem(ev)
+ new(OpCodes.Call, Method(typeof(Scp914), nameof(Scp914.OnUpgradedInventoryItem))),
});
newInstructions[newInstructions.Count - 1].labels.Add(returnLabel);
From 42978423a6bdc68bac71c90dbb565b9e37c85dc5 Mon Sep 17 00:00:00 2001
From: Yamato <66829532+louis1706@users.noreply.github.com>
Date: Sun, 7 Apr 2024 19:47:16 +0200
Subject: [PATCH 2/3] Small rework of background api & consistency of it
(#2453)
* small rework of background API
* lazy
* Fix .ToArray()
* .
* unused var
* Better Fix For Scp0492
* .
* Not finish
* DoorBeepType
* Revert
* .
* Remove Change to prevent conflict
* Update Exiled.Events/Patches/Generic/TargetOffset.cs
---
Exiled.API/Enums/DoorBeepType.cs | 5 --
Exiled.API/Features/Doors/Door.cs | 6 +-
Exiled.API/Features/Lift.cs | 2 +-
Exiled.API/Features/Player.cs | 2 +-
Exiled.API/Features/Room.cs | 12 ++--
.../Patches/Fixes/PositionSpawnScp0492Fix.cs | 25 +++----
.../Patches/Generic/AirlockListAdd.cs | 10 +--
Exiled.Events/Patches/Generic/CameraList.cs | 69 ++-----------------
.../Generic/DestroyRecontainerInstance.cs | 19 +----
Exiled.Events/Patches/Generic/HazardList.cs | 4 +-
.../Generic/InitRecontainerInstance.cs | 26 +------
Exiled.Events/Patches/Generic/LiftList.cs | 2 +-
Exiled.Events/Patches/Generic/RoomList.cs | 24 +------
.../Patches/Generic/SpeakerInRoom.cs | 5 +-
Exiled.Events/Patches/Generic/StaminaRegen.cs | 1 +
Exiled.Events/Patches/Generic/StaminaUsage.cs | 1 +
Exiled.Events/Patches/Generic/TeleportList.cs | 49 +++++++++++--
Exiled.Events/Patches/Generic/TeslaList.cs | 9 +--
18 files changed, 89 insertions(+), 182 deletions(-)
diff --git a/Exiled.API/Enums/DoorBeepType.cs b/Exiled.API/Enums/DoorBeepType.cs
index 59760b8880..6cc12c1b51 100644
--- a/Exiled.API/Enums/DoorBeepType.cs
+++ b/Exiled.API/Enums/DoorBeepType.cs
@@ -25,11 +25,6 @@ public enum DoorBeepType
///
LockBypassDenied,
- ///
- /// Interaction denied.
- ///
- InteractionDenied,
-
///
/// Interaction allowed.
///
diff --git a/Exiled.API/Features/Doors/Door.cs b/Exiled.API/Features/Doors/Door.cs
index c167de4b6b..49fc4153fd 100644
--- a/Exiled.API/Features/Doors/Door.cs
+++ b/Exiled.API/Features/Doors/Door.cs
@@ -563,11 +563,11 @@ public void PlaySound(DoorBeepType beep)
{
switch (Base)
{
- case Interactables.Interobjects.BasicDoor basic:
- basic.RpcPlayBeepSound(beep is not DoorBeepType.InteractionAllowed);
+ case Interactables.Interobjects.BasicDoor basic when beep is DoorBeepType.PermissionDenied or DoorBeepType.LockBypassDenied:
+ basic.RpcPlayBeepSound(beep is DoorBeepType.PermissionDenied);
break;
case Interactables.Interobjects.CheckpointDoor chkPt:
- chkPt.RpcPlayBeepSound((byte)Mathf.Min((int)beep, 3));
+ chkPt.RpcPlayBeepSound((byte)Mathf.Min((int)beep, 2));
break;
}
}
diff --git a/Exiled.API/Features/Lift.cs b/Exiled.API/Features/Lift.cs
index 191ef101b1..b71325e405 100644
--- a/Exiled.API/Features/Lift.cs
+++ b/Exiled.API/Features/Lift.cs
@@ -52,7 +52,7 @@ internal Lift(ElevatorChamber elevator)
Base = elevator;
ElevatorChamberToLift.Add(elevator, this);
- internalDoorsList.AddRange(Interactables.Interobjects.ElevatorDoor.AllElevatorDoors[Group]);
+ internalDoorsList.AddRange(Elevator.AllElevatorDoors[Group]);
}
///
diff --git a/Exiled.API/Features/Player.cs b/Exiled.API/Features/Player.cs
index 403db9b8da..11dffcbdbe 100644
--- a/Exiled.API/Features/Player.cs
+++ b/Exiled.API/Features/Player.cs
@@ -1856,7 +1856,7 @@ public bool UnloadWeapon()
/// if the weapon flashlight toggle request is received. Returns otherwise, or if the player is not an or is not holding a .
public bool ToggleWeaponFlashlight()
{
- if (RoleManager.CurrentRole is not IFpcRole fpc || CurrentItem is not Firearm firearm)
+ if (RoleManager.CurrentRole is not IFpcRole || CurrentItem is not Firearm firearm)
return false;
bool oldCheck = firearm.FlashlightEnabled; // Temporary Solution
diff --git a/Exiled.API/Features/Room.cs b/Exiled.API/Features/Room.cs
index 683168fca4..394217f8aa 100644
--- a/Exiled.API/Features/Room.cs
+++ b/Exiled.API/Features/Room.cs
@@ -35,15 +35,15 @@ public class Room : GameEntity, IWorldSpace
///
internal static readonly Dictionary RoomIdentifierToRoom = new(250, new ComponentsEqualityComparer());
- private GameObject gameObject;
+ private readonly GameObject gameObject;
///
/// Initializes a new instance of the class.
///
- /// The room's .
- internal Room(GameObject go)
+ /// The room's .
+ internal Room(RoomIdentifier roomIdentifier)
{
- gameObject = go;
+ gameObject = roomIdentifier.gameObject;
Identifier = gameObject.GetComponent();
RoomIdentifierToRoom.Add(Identifier, this);
@@ -252,7 +252,7 @@ public bool AreLightsOff
/// The to search with.
/// The of the given identified, if any. Can be .
public static Room Get(RoomIdentifier roomIdentifier) => roomIdentifier == null ? null :
- RoomIdentifierToRoom.TryGetValue(roomIdentifier, out Room room) ? room : null;
+ RoomIdentifierToRoom.TryGetValue(roomIdentifier, out Room room) ? room : new Room(roomIdentifier);
///
/// Gets a from a given .
@@ -307,7 +307,7 @@ public static Room FindParentRoom(GameObject objectInRoom)
// First try to find the room owner quickly.
if (!objectInRoom.CompareTag(playerTag))
{
- room = objectInRoom.GetComponentInParent();
+ room = Get(objectInRoom.GetComponentInParent());
}
else
{
diff --git a/Exiled.Events/Patches/Fixes/PositionSpawnScp0492Fix.cs b/Exiled.Events/Patches/Fixes/PositionSpawnScp0492Fix.cs
index e7a33157f1..3507ebc87a 100644
--- a/Exiled.Events/Patches/Fixes/PositionSpawnScp0492Fix.cs
+++ b/Exiled.Events/Patches/Fixes/PositionSpawnScp0492Fix.cs
@@ -17,14 +17,14 @@ namespace Exiled.Events.Patches.Fixes
using HarmonyLib;
using PlayerRoles.PlayableScps.Scp049;
-
+ using PlayerRoles.Ragdolls;
using UnityEngine;
using static HarmonyLib.AccessTools;
///
/// Patches delegate.
- /// Removes useless position setter for Scp0492.
+ /// Fix bug where Scp0492 respawn at wrong place partially fix nw bug (https://trello.com/c/T1P333XK/5482-scp049-able-to-revive-old-player-corpse?filter=SCP049).
///
[HarmonyPatch(typeof(Scp049ResurrectAbility), nameof(Scp049ResurrectAbility.ServerComplete))]
internal static class PositionSpawnScp0492Fix
@@ -33,20 +33,21 @@ private static IEnumerable Transpiler(IEnumerable newInstructions = ListPool.Pool.Get(instructions);
- Label continueLabel = generator.DefineLabel();
-
- LocalBuilder player = generator.DeclareLocal(typeof(Player));
- LocalBuilder eventArgs = generator.DeclareLocal(typeof(SpawningEventArgs));
-
- const int toRemove = 7;
+ const int toRemove = 4;
- const int offset = -1;
+ const int offset = 1;
int index = newInstructions.FindLastIndex(instruction => instruction.Calls(PropertyGetter(typeof(Component), nameof(Component.transform)))) + offset;
- newInstructions[index + toRemove].MoveLabelsFrom(newInstructions[index]);
-
+ // replace "ownerHub.transform.position = base.CastRole.FpcModule.Position;"
+ // with "ownerHub.transform.position = base.CurRagdoll.Info.StartPosition;"
newInstructions.RemoveRange(index, toRemove);
-
+ newInstructions.InsertRange(index, new CodeInstruction[]
+ {
+ new(OpCodes.Ldarg_0),
+ new(OpCodes.Call, PropertyGetter(typeof(RagdollAbilityBase), nameof(RagdollAbilityBase.CurRagdoll))),
+ new(OpCodes.Ldflda, Field(typeof(BasicRagdoll), nameof(BasicRagdoll.Info))),
+ new(OpCodes.Ldfld, Field(typeof(RagdollData), nameof(RagdollData.StartPosition))),
+ });
for (int z = 0; z < newInstructions.Count; z++)
yield return newInstructions[z];
diff --git a/Exiled.Events/Patches/Generic/AirlockListAdd.cs b/Exiled.Events/Patches/Generic/AirlockListAdd.cs
index 99932f14e8..1e094e79a9 100644
--- a/Exiled.Events/Patches/Generic/AirlockListAdd.cs
+++ b/Exiled.Events/Patches/Generic/AirlockListAdd.cs
@@ -19,10 +19,7 @@ namespace Exiled.Events.Patches.Generic
[HarmonyPatch(typeof(AirlockController), nameof(AirlockController.Start))]
internal class AirlockListAdd
{
- private static void Postfix(AirlockController __instance)
- {
- _ = new API.Features.Doors.AirlockController(__instance);
- }
+ private static void Postfix(AirlockController __instance) => API.Features.Doors.AirlockController.Get(__instance);
}
///
@@ -31,9 +28,6 @@ private static void Postfix(AirlockController __instance)
[HarmonyPatch(typeof(AirlockController), nameof(AirlockController.OnDestroy))]
internal class AirlockListRemove
{
- private static void Postfix(AirlockController __instance)
- {
- API.Features.Doors.AirlockController.BaseToExiledControllers.Remove(__instance);
- }
+ private static void Postfix(AirlockController __instance) => API.Features.Doors.AirlockController.BaseToExiledControllers.Remove(__instance);
}
}
\ No newline at end of file
diff --git a/Exiled.Events/Patches/Generic/CameraList.cs b/Exiled.Events/Patches/Generic/CameraList.cs
index 22f697d809..1684f91d06 100644
--- a/Exiled.Events/Patches/Generic/CameraList.cs
+++ b/Exiled.Events/Patches/Generic/CameraList.cs
@@ -8,6 +8,7 @@
namespace Exiled.Events.Patches.Generic
{
#pragma warning disable SA1402
+#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
using System.Collections.Generic;
using System.Reflection.Emit;
@@ -30,40 +31,10 @@ namespace Exiled.Events.Patches.Generic
[HarmonyPatch(typeof(Scp079InteractableBase), nameof(Scp079InteractableBase.OnRegistered))]
internal class CameraList
{
- private static IEnumerable Transpiler(IEnumerable codeInstructions, ILGenerator generator)
+ private static void Postfix(Scp079InteractableBase __instance)
{
- List newInstructions = ListPool.Pool.Get(codeInstructions);
-
- LocalBuilder cameraBase = generator.DeclareLocal(typeof(Scp079Camera));
- Label ret = generator.DefineLabel();
-
- // if (this is Scp079Camera camera)
- // Room.RoomIdentifierToRoom[Room].CamerasValue.Add(new Camera(camera));
- newInstructions.InsertRange(
- newInstructions.Count - 1,
- new CodeInstruction[]
- {
- new(OpCodes.Ldarg_0),
- new(OpCodes.Isinst, typeof(Scp079Camera)),
- new(OpCodes.Dup),
- new(OpCodes.Stloc_S, cameraBase.LocalIndex),
- new(OpCodes.Brfalse_S, ret),
- new(OpCodes.Ldsfld, Field(typeof(Room), nameof(Room.RoomIdentifierToRoom))),
- new(OpCodes.Ldarg_0),
- new(OpCodes.Callvirt, PropertyGetter(typeof(Scp079Camera), nameof(Scp079Camera.Room))),
- new(OpCodes.Callvirt, Method(typeof(Dictionary), "get_Item")),
- new(OpCodes.Callvirt, PropertyGetter(typeof(Room), nameof(Room.CamerasValue))),
- new(OpCodes.Ldloc_S, cameraBase.LocalIndex),
- new(OpCodes.Newobj, GetDeclaredConstructors(typeof(Camera))[0]),
- new(OpCodes.Callvirt, Method(typeof(List), nameof(List.Add), new[] { typeof(Camera) })),
- });
-
- newInstructions[newInstructions.Count - 1].labels.Add(ret);
-
- for (int z = 0; z < newInstructions.Count; z++)
- yield return newInstructions[z];
-
- ListPool.Pool.Return(newInstructions);
+ if (__instance is Scp079Camera camera)
+ Room.RoomIdentifierToRoom[__instance.Room].CamerasValue.Add(Camera.Get(camera));
}
}
@@ -73,36 +44,10 @@ private static IEnumerable Transpiler(IEnumerable Transpiler(IEnumerable codeInstructions, ILGenerator generator)
+ private static void Postfix(Scp079InteractableBase __instance)
{
- List newInstructions = ListPool.Pool.Get(codeInstructions);
-
- LocalBuilder cameraBase = generator.DeclareLocal(typeof(Scp079Camera));
- Label ret = generator.DefineLabel();
-
- // if (__instance is Scp079Camera cameraBase)
- // Camera.Camera079ToCamera.Remove(cameraBase);
- newInstructions.InsertRange(
- newInstructions.Count - 1,
- new CodeInstruction[]
- {
- new(OpCodes.Ldarg_0),
- new(OpCodes.Isinst, typeof(Scp079Camera)),
- new(OpCodes.Dup),
- new(OpCodes.Stloc_S, cameraBase.LocalIndex),
- new(OpCodes.Brfalse_S, ret),
- new(OpCodes.Ldsfld, Field(typeof(Camera), nameof(Camera.Camera079ToCamera))),
- new(OpCodes.Ldarg_0),
- new(OpCodes.Callvirt, Method(typeof(Dictionary), nameof(Dictionary.Remove), new[] { typeof(Scp079Camera) })),
- new(OpCodes.Pop),
- });
-
- newInstructions[newInstructions.Count - 1].labels.Add(ret);
-
- for (int z = 0; z < newInstructions.Count; z++)
- yield return newInstructions[z];
-
- ListPool.Pool.Return(newInstructions);
+ if (__instance is Scp079Camera cameraBase)
+ Camera.Camera079ToCamera.Remove(cameraBase);
}
}
}
\ No newline at end of file
diff --git a/Exiled.Events/Patches/Generic/DestroyRecontainerInstance.cs b/Exiled.Events/Patches/Generic/DestroyRecontainerInstance.cs
index c778933d13..065634f2f7 100644
--- a/Exiled.Events/Patches/Generic/DestroyRecontainerInstance.cs
+++ b/Exiled.Events/Patches/Generic/DestroyRecontainerInstance.cs
@@ -25,23 +25,6 @@ namespace Exiled.Events.Patches.Generic
[HarmonyPatch(typeof(Scp079Recontainer), nameof(Scp079Recontainer.OnDestroy))]
internal class DestroyRecontainerInstance
{
- private static IEnumerable Transpiler(IEnumerable instructions)
- {
- List newInstructions = ListPool.Pool.Get(instructions);
-
- // Recontainer.Base = null;
- newInstructions.InsertRange(
- 0,
- new CodeInstruction[]
- {
- new(OpCodes.Ldnull),
- new(OpCodes.Call, PropertySetter(typeof(Recontainer), nameof(Recontainer.Base))),
- });
-
- for (int z = 0; z < newInstructions.Count; z++)
- yield return newInstructions[z];
-
- ListPool.Pool.Return(newInstructions);
- }
+ private static void Postfix() => Recontainer.Base = null;
}
}
\ No newline at end of file
diff --git a/Exiled.Events/Patches/Generic/HazardList.cs b/Exiled.Events/Patches/Generic/HazardList.cs
index 6ee854655d..f0adecdbc2 100644
--- a/Exiled.Events/Patches/Generic/HazardList.cs
+++ b/Exiled.Events/Patches/Generic/HazardList.cs
@@ -1,4 +1,4 @@
-// -----------------------------------------------------------------------
+// -----------------------------------------------------------------------
//
// Copyright (c) Exiled Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
@@ -21,7 +21,7 @@ internal class HazardList
{
[HarmonyPatch(typeof(EnvironmentalHazard), nameof(EnvironmentalHazard.Start))]
[HarmonyPostfix]
- private static void Adding(EnvironmentalHazard __instance) => _ = Hazard.Get(__instance);
+ private static void Adding(EnvironmentalHazard __instance) => Hazard.Get(__instance);
[HarmonyPatch(typeof(EnvironmentalHazard), nameof(EnvironmentalHazard.OnDestroy))]
[HarmonyPostfix]
diff --git a/Exiled.Events/Patches/Generic/InitRecontainerInstance.cs b/Exiled.Events/Patches/Generic/InitRecontainerInstance.cs
index 6e32ca1393..2b3561515f 100644
--- a/Exiled.Events/Patches/Generic/InitRecontainerInstance.cs
+++ b/Exiled.Events/Patches/Generic/InitRecontainerInstance.cs
@@ -7,41 +7,19 @@
namespace Exiled.Events.Patches.Generic
{
- using System.Collections.Generic;
- using System.Reflection.Emit;
-
+#pragma warning disable SA1313 // Parameter names should begin with lower-case letter
using API.Features;
- using API.Features.Core.Generic.Pools;
using HarmonyLib;
using PlayerRoles.PlayableScps.Scp079;
- using static HarmonyLib.AccessTools;
-
///
/// Patches .
///
[HarmonyPatch(typeof(Scp079Recontainer), nameof(Scp079Recontainer.Start))]
internal class InitRecontainerInstance
{
- private static IEnumerable Transpiler(IEnumerable instructions)
- {
- List newInstructions = ListPool.Pool.Get(instructions);
-
- // Recontainer.Base = this;
- newInstructions.InsertRange(
- 0,
- new CodeInstruction[]
- {
- new(OpCodes.Ldarg_0),
- new(OpCodes.Call, PropertySetter(typeof(Recontainer), nameof(Recontainer.Base))),
- });
-
- for (int z = 0; z < newInstructions.Count; z++)
- yield return newInstructions[z];
-
- ListPool.Pool.Return(newInstructions);
- }
+ private static void Postfix(Scp079Recontainer __instance) => Recontainer.Base = __instance;
}
}
\ No newline at end of file
diff --git a/Exiled.Events/Patches/Generic/LiftList.cs b/Exiled.Events/Patches/Generic/LiftList.cs
index f1f9a058b9..397a305c40 100644
--- a/Exiled.Events/Patches/Generic/LiftList.cs
+++ b/Exiled.Events/Patches/Generic/LiftList.cs
@@ -26,7 +26,7 @@ private static void Postfix()
foreach (KeyValuePair lift in ElevatorManager.SpawnedChambers)
{
- _ = new Lift(lift.Value);
+ Lift.Get(lift.Value);
}
}
}
diff --git a/Exiled.Events/Patches/Generic/RoomList.cs b/Exiled.Events/Patches/Generic/RoomList.cs
index 0b8b9632cd..147cb53349 100644
--- a/Exiled.Events/Patches/Generic/RoomList.cs
+++ b/Exiled.Events/Patches/Generic/RoomList.cs
@@ -30,29 +30,7 @@ namespace Exiled.Events.Patches.Generic
[HarmonyPatch(typeof(RoomIdentifier), nameof(RoomIdentifier.TryAssignId))]
internal class RoomList
{
- private static IEnumerable Transpiler(IEnumerable codeInstructions)
- {
- List newInstructions = ListPool.Pool.Get(codeInstructions);
-
- int offset = -3;
- int index = newInstructions.FindIndex(i => i.Calls(Method(typeof(RoomIdUtils), nameof(RoomIdUtils.PositionToCoords)))) + offset;
-
- // new Room(gameObject)
- newInstructions.InsertRange(
- index,
- new CodeInstruction[]
- {
- new CodeInstruction(OpCodes.Ldarg_0).MoveLabelsFrom(newInstructions[index]),
- new(OpCodes.Callvirt, PropertyGetter(typeof(Component), nameof(Component.gameObject))),
- new(OpCodes.Newobj, GetDeclaredConstructors(typeof(Room))[0]),
- new(OpCodes.Pop),
- });
-
- for (int z = 0; z < newInstructions.Count; z++)
- yield return newInstructions[z];
-
- ListPool.Pool.Return(newInstructions);
- }
+ private static void Postfix(RoomIdentifier __instance) => Room.Get(__instance);
}
///
diff --git a/Exiled.Events/Patches/Generic/SpeakerInRoom.cs b/Exiled.Events/Patches/Generic/SpeakerInRoom.cs
index d9febe29bd..d91c290157 100644
--- a/Exiled.Events/Patches/Generic/SpeakerInRoom.cs
+++ b/Exiled.Events/Patches/Generic/SpeakerInRoom.cs
@@ -20,9 +20,6 @@ namespace Exiled.Events.Patches.Generic
[HarmonyPatch(typeof(Scp079Speaker), nameof(Scp079Speaker.OnRegistered))]
internal class SpeakerInRoom
{
- private static void Postfix(Scp079Speaker __instance)
- {
- Room.RoomIdentifierToRoom[__instance.Room].SpeakersValue.Add(__instance);
- }
+ private static void Postfix(Scp079Speaker __instance) => Room.RoomIdentifierToRoom[__instance.Room].SpeakersValue.Add(__instance);
}
}
\ No newline at end of file
diff --git a/Exiled.Events/Patches/Generic/StaminaRegen.cs b/Exiled.Events/Patches/Generic/StaminaRegen.cs
index d1c7801d46..acc1835dcb 100644
--- a/Exiled.Events/Patches/Generic/StaminaRegen.cs
+++ b/Exiled.Events/Patches/Generic/StaminaRegen.cs
@@ -8,6 +8,7 @@
namespace Exiled.Events.Patches.Generic
{
#pragma warning disable SA1313
+#pragma warning disable IDE0051
using Exiled.API.Features;
using Exiled.API.Features.Roles;
diff --git a/Exiled.Events/Patches/Generic/StaminaUsage.cs b/Exiled.Events/Patches/Generic/StaminaUsage.cs
index 554cd0dbd6..6236dca92b 100644
--- a/Exiled.Events/Patches/Generic/StaminaUsage.cs
+++ b/Exiled.Events/Patches/Generic/StaminaUsage.cs
@@ -8,6 +8,7 @@
namespace Exiled.Events.Patches.Generic
{
#pragma warning disable SA1313
+#pragma warning disable IDE0051
using Exiled.API.Features;
using Exiled.API.Features.Roles;
diff --git a/Exiled.Events/Patches/Generic/TeleportList.cs b/Exiled.Events/Patches/Generic/TeleportList.cs
index 3b1627f1cf..a84206f292 100644
--- a/Exiled.Events/Patches/Generic/TeleportList.cs
+++ b/Exiled.Events/Patches/Generic/TeleportList.cs
@@ -7,21 +7,58 @@
namespace Exiled.Events.Patches.Generic
{
-#pragma warning disable SA1313
- using API.Features;
+ using System;
+#pragma warning disable SA1402 // File may only contain a single type
+ using System.Collections.Generic;
+ using System.Collections.ObjectModel;
+ using System.Linq;
+ using System.Reflection.Emit;
+ using API.Features;
+ using Exiled.API.Features.Core.Generic.Pools;
using HarmonyLib;
+ using UnityEngine;
+
+ using static HarmonyLib.AccessTools;
+
///
- /// Patches .
+ /// Patches .
///
- [HarmonyPatch(typeof(PocketDimensionGenerator), nameof(PocketDimensionGenerator.PrepTeleports))]
+ [HarmonyPatch(typeof(PocketDimensionGenerator), nameof(PocketDimensionGenerator.GenerateMap))]
internal class TeleportList
{
- private static void Postfix(ref PocketDimensionTeleport[] __result)
+ private static void Postfix()
{
Map.TeleportsValue.Clear();
- Map.TeleportsValue.AddRange(__result);
+ Map.TeleportsValue.AddRange(UnityEngine.Object.FindObjectsOfType());
+ }
+ }
+
+ ///
+ /// Patches .
+ ///
+ [HarmonyPatch(typeof(PocketDimensionGenerator), nameof(PocketDimensionGenerator.PrepTeleports))]
+ internal class OptimiseNWPocketDimensionGenerator
+ {
+ private static IEnumerable Transpiler(IEnumerable instructions, ILGenerator generator)
+ {
+ List newInstructions = ListPool.Pool.Get(instructions);
+
+ // replace "PocketDimensionTeleport[] array = UnityEngine.Object.FindObjectsOfType();"
+ // with
+ // replace "PocketDimensionTeleport[] array = Exiled.API.Features.Map.TeleportsValue.ToArray()"
+ newInstructions.RemoveAt(0);
+ newInstructions.InsertRange(0, new CodeInstruction[]
+ {
+ new(OpCodes.Call, PropertyGetter(typeof(Map), nameof(Map.PocketDimensionTeleports))),
+ new(OpCodes.Call, Method(typeof(Enumerable), nameof(Enumerable.ToArray)).MakeGenericMethod(typeof(PocketDimensionGenerator))),
+ });
+
+ for (int z = 0; z < newInstructions.Count; z++)
+ yield return newInstructions[z];
+
+ ListPool.Pool.Return(newInstructions);
}
}
}
\ No newline at end of file
diff --git a/Exiled.Events/Patches/Generic/TeslaList.cs b/Exiled.Events/Patches/Generic/TeslaList.cs
index 106ab1d4ad..0e61fc9d9f 100644
--- a/Exiled.Events/Patches/Generic/TeslaList.cs
+++ b/Exiled.Events/Patches/Generic/TeslaList.cs
@@ -12,14 +12,11 @@ namespace Exiled.Events.Patches.Generic
using HarmonyLib;
///
- /// Patches .
+ /// Patches .
///
- [HarmonyPatch(typeof(TeslaGateController), nameof(TeslaGateController.Start))]
+ [HarmonyPatch(typeof(TeslaGateController), nameof(TeslaGateController.Awake))]
internal class TeslaList
{
- private static void Postfix()
- {
- TeslaGate.BaseTeslaGateToTeslaGate.Clear();
- }
+ private static void Postfix() => TeslaGate.BaseTeslaGateToTeslaGate.Clear();
}
}
\ No newline at end of file
From 516596d633435afa473a4e55be42ef13a3df270a Mon Sep 17 00:00:00 2001
From: Nameless <85962933+Misfiy@users.noreply.github.com>
Date: Tue, 9 Apr 2024 23:27:09 +0200
Subject: [PATCH 3/3] [Exiled.API] [Addition] Map::PlaceDecal (#2506)
* afafsa
* Revert "afafsa"
This reverts commit cb1ceb5dd3761bbb7047852f35cea304373bdd1d.
* commit
---
Exiled.API/Features/Map.cs | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/Exiled.API/Features/Map.cs b/Exiled.API/Features/Map.cs
index c8e4215dd4..ba69d4d4fd 100644
--- a/Exiled.API/Features/Map.cs
+++ b/Exiled.API/Features/Map.cs
@@ -347,12 +347,20 @@ public static void CleanAllRagdolls(IEnumerable ragDolls)
ragDoll.Destroy();
}
+ ///
+ /// Places a decal.
+ ///
+ /// The position of the blood decal.
+ /// The direction of the blood decal.
+ /// The type of decal to place.
+ public static void PlaceDecal(Vector3 position, Vector3 direction, DecalPoolType type) => new GunDecalMessage(position, direction, type).SendToAuthenticated(0);
+
///
/// Places a blood decal.
///
/// The position of the blood decal.
/// The direction of the blood decal.
- public static void PlaceBlood(Vector3 position, Vector3 direction) => new GunDecalMessage(position, direction, DecalPoolType.Blood).SendToAuthenticated(0);
+ public static void PlaceBlood(Vector3 position, Vector3 direction) => PlaceDecal(position, direction, DecalPoolType.Blood);
///
/// Gets all the near cameras.