diff --git a/Content.Server/Salvage/SalvageSystem.cs b/Content.Server/Salvage/SalvageSystem.cs index 4acf663358..1065f7426e 100644 --- a/Content.Server/Salvage/SalvageSystem.cs +++ b/Content.Server/Salvage/SalvageSystem.cs @@ -25,6 +25,7 @@ using Content.Shared.CCVar; using Content.Shared.Construction.EntitySystems; using Content.Shared.Random; using Content.Shared.Random.Helpers; +using Content.Shared.Tools.Components; using Robust.Server.Maps; using Robust.Shared.Map.Components; using Robust.Shared.Timing; @@ -68,6 +69,7 @@ namespace Content.Server.Salvage SubscribeLocalEvent(OnRefreshParts); SubscribeLocalEvent(OnUpgradeExamine); SubscribeLocalEvent(OnExamined); + SubscribeLocalEvent(OnToolUseAttempt); SubscribeLocalEvent(OnMagnetRemoval); SubscribeLocalEvent(OnGridRemoval); @@ -232,6 +234,15 @@ namespace Content.Server.Salvage } } + private void OnToolUseAttempt(EntityUid uid, SalvageMagnetComponent comp, ToolUseAttemptEvent args) + { + // prevent reconstruct exploit to "leak" wrecks or skip cooldowns + if (comp.MagnetState != MagnetState.Inactive) + { + args.Cancel(); + } + } + private void OnInteractHand(EntityUid uid, SalvageMagnetComponent component, InteractHandEvent args) { if (args.Handled) diff --git a/Content.Shared/Tools/Components/ToolComponent.cs b/Content.Shared/Tools/Components/ToolComponent.cs index 2f9d822f9a..92857ab905 100644 --- a/Content.Shared/Tools/Components/ToolComponent.cs +++ b/Content.Shared/Tools/Components/ToolComponent.cs @@ -22,7 +22,8 @@ namespace Content.Shared.Tools.Components } /// - /// Attempt event called *before* any do afters to see if the tool usage should succeed or not. + /// Attempt event called *before* any do afters to see if the tool usage should succeed or not. + /// Raised on both the tool and then target. /// public sealed class ToolUseAttemptEvent : CancellableEntityEventArgs { diff --git a/Content.Shared/Tools/Systems/SharedToolSystem.cs b/Content.Shared/Tools/Systems/SharedToolSystem.cs index f892531850..7073b10f9d 100644 --- a/Content.Shared/Tools/Systems/SharedToolSystem.cs +++ b/Content.Shared/Tools/Systems/SharedToolSystem.cs @@ -180,16 +180,27 @@ public abstract partial class SharedToolSystem : EntitySystem if (!Resolve(tool, ref toolComponent)) return false; + // check if the tool can do what's required + if (!toolComponent.Qualities.ContainsAll(toolQualitiesNeeded)) + return false; + + // check if the user allows using the tool var ev = new ToolUserAttemptUseEvent(target); RaiseLocalEvent(user, ref ev); if (ev.Cancelled) return false; - if (!toolComponent.Qualities.ContainsAll(toolQualitiesNeeded)) + // check if the tool allows being used + var beforeAttempt = new ToolUseAttemptEvent(user); + RaiseLocalEvent(tool, beforeAttempt); + if (beforeAttempt.Cancelled) return false; - var beforeAttempt = new ToolUseAttemptEvent(user); - RaiseLocalEvent(tool, beforeAttempt, false); + // check if the target allows using the tool + if (target != null && target != tool) + { + RaiseLocalEvent(target.Value, beforeAttempt); + } return !beforeAttempt.Cancelled; }