From ff37e69c0a71d2a13d8334bf6659d752bf6a7e9e Mon Sep 17 00:00:00 2001 From: Leon Friedrich <60421075+ElectroJr@users.noreply.github.com> Date: Mon, 22 Aug 2022 12:44:37 +1200 Subject: [PATCH] Fix some buckling bugs (#10759) --- Content.Server/Buckle/Systems/BuckleSystem.cs | 3 +++ Content.Shared/Buckle/SharedBuckleSystem.cs | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/Content.Server/Buckle/Systems/BuckleSystem.cs b/Content.Server/Buckle/Systems/BuckleSystem.cs index 48d502332b..470583b665 100644 --- a/Content.Server/Buckle/Systems/BuckleSystem.cs +++ b/Content.Server/Buckle/Systems/BuckleSystem.cs @@ -85,6 +85,9 @@ namespace Content.Server.Buckle.Systems private void ContainerModifiedStrap(EntityUid uid, StrapComponent strap, ContainerModifiedMessage message) { + if (GameTiming.ApplyingState) + return; + foreach (var buckledEntity in strap.BuckledEntities) { if (!EntityManager.TryGetComponent(buckledEntity, out BuckleComponent? buckled)) diff --git a/Content.Shared/Buckle/SharedBuckleSystem.cs b/Content.Shared/Buckle/SharedBuckleSystem.cs index f39a6f83c5..8d8714d99b 100644 --- a/Content.Shared/Buckle/SharedBuckleSystem.cs +++ b/Content.Shared/Buckle/SharedBuckleSystem.cs @@ -5,11 +5,14 @@ using Content.Shared.Movement.Events; using Content.Shared.Standing; using Content.Shared.Throwing; using Robust.Shared.Physics.Dynamics; +using Robust.Shared.Timing; namespace Content.Shared.Buckle { public abstract class SharedBuckleSystem : EntitySystem { + [Dependency] protected readonly IGameTiming GameTiming = default!; + public override void Initialize() { base.Initialize(); @@ -28,6 +31,20 @@ namespace Content.Shared.Buckle // TODO: This looks dirty af. // On rotation of a strap, reattach all buckled entities. // This fixes buckle offsets and draw depths. + // This is mega cursed. Please somebody save me from Mr Buckle's wild ride. + + // Consider a chair that has a player strapped to it. Then the client receives a new server state, showing + // that the player entity has moved elsewhere, and the chair has rotated. If the client applies the player + // state, then the chairs transform comp state, and then the buckle state. The transform state will + // forcefully teleport the player back to the chair (client-side only). This causes even more issues if the + // chair was teleporting in from nullspace after having left PVS. + // + // One option is to just never trigger re-buckles during state application. + // another is to.. just not do this? Like wtf is this code. But I CBF with buckle atm. + + if (GameTiming.ApplyingState) + return; + foreach (var buckledEntity in component.BuckledEntities) { if (!EntityManager.TryGetComponent(buckledEntity, out SharedBuckleComponent? buckled)) @@ -35,6 +52,12 @@ namespace Content.Shared.Buckle continue; } + if (!buckled.Buckled || buckled.LastEntityBuckledTo != uid) + { + Logger.Error($"A moving strap entity {ToPrettyString(uid)} attempted to re-parent an entity that does not 'belong' to it {ToPrettyString(buckledEntity)}"); + continue; + } + buckled.ReAttach(component); Dirty(buckled); }