From 8730f1e93f289bf1c12702cb62a5347337b1b499 Mon Sep 17 00:00:00 2001 From: Dvir <39403717+dvir001@users.noreply.github.com> Date: Wed, 8 Nov 2023 00:13:20 +0200 Subject: [PATCH] APC Abuse Fix (#526) * Update ApcSystem.cs * APC + Shuttle * ShuttleEMP Fix * Update ShuttleConsoleSystem.cs * Update ShuttleConsoleSystem.cs * Update ShuttleConsoleSystem.cs * Added Comp EMP test --- Content.Server/Emp/EmpSystem.cs | 7 ++++ .../Power/EntitySystems/ApcSystem.cs | 16 ++++++- .../Components/ShuttleConsoleComponent.cs | 16 +++++++ .../Shuttles/Systems/ShuttleConsoleSystem.cs | 42 +++++++++++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) diff --git a/Content.Server/Emp/EmpSystem.cs b/Content.Server/Emp/EmpSystem.cs index b669d076d2a..b6da2c00aa7 100644 --- a/Content.Server/Emp/EmpSystem.cs +++ b/Content.Server/Emp/EmpSystem.cs @@ -7,6 +7,7 @@ using Content.Shared.Emp; using Content.Shared.Examine; using Robust.Shared.Map; +using static Content.Server.Shuttles.Systems.ShuttleConsoleSystem; using static Content.Server.Shuttles.Systems.ThrusterSystem; namespace Content.Server.Emp; @@ -29,6 +30,7 @@ public override void Initialize() SubscribeLocalEvent(OnApcToggleMainBreaker); SubscribeLocalEvent(OnCameraSetActive); SubscribeLocalEvent(OnThrusterToggle); + SubscribeLocalEvent(OnShuttleConsoleToggle); } /// @@ -147,6 +149,11 @@ private void OnThrusterToggle(EntityUid uid, EmpDisabledComponent component, ref { args.Cancelled = true; } + + private void OnShuttleConsoleToggle(EntityUid uid, EmpDisabledComponent component, ref ShuttleToggleAttemptEvent args) + { + args.Cancelled = true; + } } /// diff --git a/Content.Server/Power/EntitySystems/ApcSystem.cs b/Content.Server/Power/EntitySystems/ApcSystem.cs index 5a973aba36e..dbeb69910a2 100644 --- a/Content.Server/Power/EntitySystems/ApcSystem.cs +++ b/Content.Server/Power/EntitySystems/ApcSystem.cs @@ -11,6 +11,8 @@ using Robust.Server.GameObjects; using Robust.Shared.Audio; using Robust.Shared.Timing; +using Content.Shared.Tools.Components; +using Content.Shared.Emp; namespace Content.Server.Power.EntitySystems; @@ -36,6 +38,7 @@ public override void Initialize() SubscribeLocalEvent(OnEmagged); SubscribeLocalEvent(OnEmpPulse); + SubscribeLocalEvent(OnToolUseAttempt); } public override void Update(float deltaTime) @@ -117,7 +120,7 @@ private void OnEmagged(EntityUid uid, ApcComponent comp, ref GotEmaggedEvent arg } public void UpdateApcState(EntityUid uid, - ApcComponent? apc=null, + ApcComponent? apc = null, PowerNetworkBatteryComponent? battery = null) { if (!Resolve(uid, ref apc, ref battery, false)) @@ -189,6 +192,7 @@ private ApcExternalPowerState CalcExtPowerState(EntityUid uid, PowerState.Batter return ApcExternalPowerState.Good; } + private void OnEmpPulse(EntityUid uid, ApcComponent component, ref EmpPulseEvent args) { if (component.MainBreakerEnabled) @@ -198,6 +202,16 @@ private void OnEmpPulse(EntityUid uid, ApcComponent component, ref EmpPulseEvent ApcToggleBreaker(uid, component); } } + + private void OnToolUseAttempt(EntityUid uid, ApcComponent component, ToolUseAttemptEvent args) + { + if (!HasComp(uid)) + return; + + // prevent reconstruct exploit to skip cooldowns + if (!component.MainBreakerEnabled) + args.Cancel(); + } } [ByRefEvent] diff --git a/Content.Server/Shuttles/Components/ShuttleConsoleComponent.cs b/Content.Server/Shuttles/Components/ShuttleConsoleComponent.cs index 91cecde0445..01766e1c019 100644 --- a/Content.Server/Shuttles/Components/ShuttleConsoleComponent.cs +++ b/Content.Server/Shuttles/Components/ShuttleConsoleComponent.cs @@ -1,5 +1,6 @@ using System.Numerics; using Content.Shared.Shuttles.Components; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; namespace Content.Server.Shuttles.Components { @@ -14,5 +15,20 @@ public sealed partial class ShuttleConsoleComponent : SharedShuttleConsoleCompon /// [DataField("zoom")] public Vector2 Zoom = new(1.5f, 1.5f); + + /// + /// For EMP to allow keeping the shuttle off + /// + [DataField("enabled")] + public bool MainBreakerEnabled = true; + + /// + /// While disabled by EMP + /// + [DataField("timeoutFromEmp", customTypeSerializer: typeof(TimeOffsetSerializer))] + public TimeSpan TimeoutFromEmp = TimeSpan.Zero; + + [DataField("disableDuration"), ViewVariables(VVAccess.ReadWrite)] + public float DisableDuration = 60f; } } diff --git a/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs b/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs index 72575be9419..9741010f054 100644 --- a/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs +++ b/Content.Server/Shuttles/Systems/ShuttleConsoleSystem.cs @@ -21,6 +21,9 @@ using Robust.Shared.Physics.Components; using Robust.Shared.Timing; using Robust.Shared.Utility; +using Content.Server.Emp; +using Content.Shared.Tools.Components; +using Content.Shared.Emp; namespace Content.Server.Shuttles.Systems; @@ -59,6 +62,9 @@ public override void Initialize() SubscribeLocalEvent(OnFtlDestStartup); SubscribeLocalEvent(OnFtlDestShutdown); + + SubscribeLocalEvent(OnEmpPulse); + SubscribeLocalEvent(OnToolUseAttempt); } private void OnFtlDestStartup(EntityUid uid, FTLDestinationComponent component, ComponentStartup args) @@ -369,6 +375,22 @@ public override void Update(float frameTime) { RemovePilot(uid, comp); } + + /// + /// This makes the Shuttle Console kick pilots like its removed, to make sure EMP in effect. + /// + var disabled = EntityQueryEnumerator(); + while (disabled.MoveNext(out var uid, out _, out var comp)) + { + if (comp.TimeoutFromEmp <= _timing.CurTime) + { + ClearPilots(comp); + comp.TimeoutFromEmp += TimeSpan.FromSeconds(0.1); + comp.MainBreakerEnabled = false; + } + else + comp.MainBreakerEnabled = true; + } } /// @@ -462,4 +484,24 @@ public void ClearPilots(ShuttleConsoleComponent component) RemovePilot(pilot, pilotComponent); } } + + private void OnEmpPulse(EntityUid uid, ShuttleConsoleComponent component, ref EmpPulseEvent args) + { + args.Affected = true; + args.Disabled = true; + component.TimeoutFromEmp = _timing.CurTime; + } + + private void OnToolUseAttempt(EntityUid uid, ShuttleConsoleComponent component, ToolUseAttemptEvent args) + { + if (!HasComp(uid)) + return; + + // prevent reconstruct exploit to skip cooldowns + if (!component.MainBreakerEnabled) + args.Cancel(); + } + + [ByRefEvent] + public record struct ShuttleToggleAttemptEvent(bool Cancelled); }