From bf24ad454747314e2e54dade344bc334cb2e20fb Mon Sep 17 00:00:00 2001 From: Personed Date: Tue, 24 Nov 2026 15:13:09 -0300 Subject: [PATCH] Fix dropped item placement and camera stability Keep the server transform for items dropped outside the inventory, update dropped items on remote clients, and keep local view/camera stable during movement and animation transitions. Also adds README stating that Steam and BattlEye must not be removed. --- README.md | 14 ++++++ lib/Inventory/inventory.hpp | 4 ++ lib/Network/networkClient.cpp | 10 +++++ lib/simul.cpp | 12 ++++++ lib/soldierOld.cpp | 81 ++++++++++++++++++++++++++++++----- lib/vehicle.hpp | 8 ++++ 6 files changed, 118 insertions(+), 11 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..c122b9b6 --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# SourceDayZ — DayZ Source + +Este repositório contém o código-fonte do SourceDayZ. + +## Aviso obrigatório: Steam e BattlEye + +**NÃO remova o Steam nem o BattlEye deste projeto.** + +- A integração com a **Steam** (`steam_api64`, Steamworks e arquivos relacionados) é obrigatória e não pode ser removida. +- O **BattlEye** e seus arquivos/serviços de proteção são obrigatórios e não podem ser removidos. +- Pull requests ou alterações que removam, desativem ou substituam a Steam ou o BattlEye **não serão aceitos**. +- Essa regra vale para o cliente, o servidor e qualquer script de build, instalação ou empacotamento. + +Mantenha a Steam e o BattlEye intactos em qualquer alteração. diff --git a/lib/Inventory/inventory.hpp b/lib/Inventory/inventory.hpp index 3ee5c3fe..c635f90a 100644 --- a/lib/Inventory/inventory.hpp +++ b/lib/Inventory/inventory.hpp @@ -211,6 +211,10 @@ class InventoryItem : public PoweredItem virtual float UpdateDistance() const override; + //! Items can be dropped from an inventory, so keep a valid position update + //! even when the item is not in the landscape on this client yet. + virtual bool AcceptPositionOutsideLandscape() const override {return true;} + virtual bool QIsManual() const override {return false;} virtual AnimationStyle IsAnimated(int level) const override; diff --git a/lib/Network/networkClient.cpp b/lib/Network/networkClient.cpp index 125c633e..9ab9f119 100644 --- a/lib/Network/networkClient.cpp +++ b/lib/Network/networkClient.cpp @@ -4510,6 +4510,16 @@ void NetworkClient::OnMessage(int from, NetworkMessage *msg, NetworkMessageType Vector3Val pos = owner->FutureVisualState().Position(); Vector3Val dir = owner->FutureVisualState().Direction(); item->ItemDrop(owner, pos, dir); + + // The item is now a world object. Remote clients need both: + // - a generic update, which carries the inLandscape flag and makes + // the client call ItemMoveIn() (add the item to the landscape); + // - a position update, because the generic item update does NOT + // carry the transform. Without it the client keeps the item at + // its old inventory position and it looks like it disappeared. + UpdateObject(item, NMCUpdateGeneric, NMFGuaranteed); + UpdateObject(item, NMCUpdatePosition, NMFGuaranteed); + if (owner) UpdateObject(owner, NMCUpdateGeneric, NMFGuaranteed); } } break; diff --git a/lib/simul.cpp b/lib/simul.cpp index 8fbd82f3..02023f38 100644 --- a/lib/simul.cpp +++ b/lib/simul.cpp @@ -5790,6 +5790,18 @@ TMError Entity::TransferMsg(NetworkMessageContext &ctx) { _remoteState.Free(); } + else if (positionValid && !IsInLandscape() && AcceptPositionOutsideLandscape()) + { + // The object is not in the landscape on this client yet. This + // happens when an item is dropped: the server sends the new + // transform while the client may still have the item stored in an + // inventory slot. Store the transform now, so ItemMoveIn() puts the + // item at the position chosen by the server instead of leaving it + // at the old inventory transform. + _remoteState.Free(); + Matrix4 trans = GetTransformFromRemoteState(remoteState.orient,remoteState.pos,FutureVisualState()); + SetTransform(trans); + } else if (positionValid && IsInLandscape()) // positionValid is IsInLandscape() on the sender side { VisualState &vs = FutureVisualState(); diff --git a/lib/soldierOld.cpp b/lib/soldierOld.cpp index 484ad4f1..e58e73fe 100644 --- a/lib/soldierOld.cpp +++ b/lib/soldierOld.cpp @@ -2443,6 +2443,7 @@ Matrix3 Man::HeadBobOrientation(const VisualStateAge vsa, CameraType camType, bo int animCount = headBlend._list.Size(); int gestCount = headBlend._masked.Size(); bool cutSceneMode = false; + float headBobWeight = 0.0f; for (int i = 0; i < animCount + gestCount; i++) { const AnimBlendInfo &animInfo = (i < animCount) ? headBlend._list.Get(i) : headBlend._masked.Get(i - animCount); @@ -2516,8 +2517,14 @@ Matrix3 Man::HeadBobOrientation(const VisualStateAge vsa, CameraType camType, bo partMatrix = partMatrix * headBobStrength + zeroStrengthMatrix * (1.0 - headBobStrength); } headBobMatrix += partMatrix * animFactor; + headBobWeight += fabs(animFactor); } - headBobMatrix.Orthogonalize(); + // Animation transitions can briefly have no weighted pose. Orthogonalizing + // a zero matrix produces an unstable view orientation in those frames. + if (headBobWeight > 1e-6f) + headBobMatrix.Orthogonalize(); + else + headBobMatrix = MIdentity; // final camera transformation Matrix3 pilotOrient; @@ -6472,7 +6479,7 @@ bool Man::CreatePotentialStateFreeFall(ManVisualState & moveTrans, Vector3& fric return true; } -const float SlideSlopeThreshold = 2.0f; //atan(sqrt(2))=cca=55� +const float SlideSlopeThreshold = 2.0f; //atan(sqrt(2))=cca=55� inline float SlideSpeedWanted(float gradFwd, float gradAside, float forceStand) { if (forceStand) return 0; @@ -6485,7 +6492,7 @@ inline float SlideSpeedWanted(float gradFwd, float gradAside, float forceStand) else return slope - 2*SlideSlopeThreshold; //brake is more efficient } -const float StandSlopeThreshold = 0.6f; //atan(sqrt(2))=cca=38� +const float StandSlopeThreshold = 0.6f; //atan(sqrt(2))=cca=38� inline bool ShouldStand(float gradFwd, float gradAside, bool forceStand) { //if (forceStand) return true; //NO! unable to prone on the road after such setting! @@ -6566,7 +6573,14 @@ bool Man::CreatePotentialState(ManVisualState & moveTrans, float& turn, float de if (QIsManual()) { //if (IsDead()) LandSlope(_forceStand, _landGradFwd, _landGradAside); - float slideSpeedWanted = SlideSpeedWanted(_landGradFwd, _landGradAside, _forceStand); + // The player's animation already supplies the requested displacement. + // Adding slope slide on top of a running step makes ground contact and the + // attached camera bounce as the terrain correction changes each frame. + // Keep automatic sliding only when there is no locomotion input. + bool playerMoving = fabs(_walkSpeedWantedX) > 0.1f || fabs(_walkSpeedWantedZ) > 0.1f; + if (playerMoving) + _slideSpeed = 0; + float slideSpeedWanted = playerMoving ? 0 : SlideSpeedWanted(_landGradFwd, _landGradAside, _forceStand); if (slideSpeedWanted>0 || _slideSpeed>0) //slide or brake slide { const float timeToReachTheSpeed = 2.0f; //from zero speed 2 seconds needed to reach the speed @@ -15627,11 +15641,20 @@ void Soldier::KeyboardPilot(float deltaT, SimulationImportance prec) { float lookX = input->GetActionWithCurveExclusive(InputInterface::CurveFovMouse, UAAimHeadRight, UAAimHeadLeft); float lookY = input->GetActionWithCurveExclusive(InputInterface::CurveFovMouse, UAAimHeadUp, UAAimHeadDown); - // Some 0.45 input profiles only bind the horizontal mouse to UAAimRight/ - // UAAimLeft. Preserve free-look yaw in those profiles when the dedicated - // head-yaw pair has no binding or was already consumed by another view. - if (fabs(lookX) < 1e-6f) - lookX = input->GetActionWithCurve(InputInterface::CurveFovMouse, UAAimRight, UAAimLeft); + // Older profiles may bind horizontal mouse movement only to body aim. + // Select that fallback from the bindings, never from a zero input sample: + // zero samples also occur between mouse events and while sprinting, and + // switching input sources on those frames makes the camera stutter. + if (QIsManual() && + GInput.GetActionKeys("AimHeadRight").Size() == 0 && + GInput.GetActionKeys("AimHeadLeft").Size() == 0) + lookX = input->GetActionWithCurveExclusive(InputInterface::CurveFovMouse, UAAimRight, UAAimLeft); + + // Mouse look must follow the current input. The head smoothing above is + // for automatic recentering and discrete look actions; leaving it active + // while walking makes horizontal camera motion trail and oscillate. + if (QIsManual() && (fabs(lookX) > 1e-6f || fabs(lookY) > 1e-6f)) + _headSmoothMove = false; float rotXWanted = (ironSight ? _gunXRotWanted : _lookXRotWanted) + lookY*deltaT; float rotYWanted = (ironSight ? _gunYRotWanted : _lookYRotWanted) - lookX*deltaT; @@ -15682,6 +15705,8 @@ void Soldier::KeyboardPilot(float deltaT, SimulationImportance prec) float aimX = input->GetActionWithCurve(InputInterface::CurveFovMouse,UAAimRight,UAAimLeft); float aimY = input->GetActionWithCurve(InputInterface::CurveFovMouse,UAAimUp,UAAimDown); + if (QIsManual() && (fabs(aimX) > 1e-6f || fabs(aimY) > 1e-6f)) + _headSmoothMove = false; bool useAimingDeadzone = IsAimingDeadzoneEnabled(); @@ -15977,10 +16002,14 @@ void Soldier::KeyboardPilot(float deltaT, SimulationImportance prec) else { //GlobalShowMessage(100, "Slope %.2f",slope); - if (!_canMoveFast || !CanSprint(_landGradFwd, _landGradAside, dirFwd, dirAside)) + // Terrain gradients can jump between adjacent samples on a steep hill. + // For the local player, changing the gait every frame makes the running + // animation (and its camera transform) oscillate. Preserve the chosen + // gait while the regular stamina and movement limits still apply. + if (!_canMoveFast || (!QIsManual() && !CanSprint(_landGradFwd, _landGradAside, dirFwd, dirAside))) fastFlag = 0; fastFlag++; - if (wantSlow && fastFlag==1 || !CanRun(_landGradFwd, _landGradAside, dirFwd, dirAside)) + if (wantSlow && fastFlag==1 || (!QIsManual() && !CanRun(_landGradFwd, _landGradAside, dirFwd, dirAside))) fastFlag = 0; } switch (fastFlag) @@ -24112,6 +24141,22 @@ TMError Man::TransferMsg(NetworkMessageContext &ctx) int lastLadderIndex = _ladderIndex; PREPARE_TRANSFER(UpdatePositionMan) + // Position snapshots are authoritative for the body, but the local + // player's view angles are predicted from this frame's mouse input. + // Keep them before reading the server snapshot so an older look value + // cannot visibly pull the camera back after a local mouse movement. + const bool preserveLocalView = !ctx.IsSending() && GWorld && this == GWorld->GetRealPlayer(); + const float localGunXRotWanted = _gunXRotWanted; + const float localGunYRotWanted = _gunYRotWanted; + const float localHeadXRotWanted = _headXRotWanted; + const float localHeadYRotWanted = _headYRotWanted; + const float localHeadXRotWantedCont = _headXRotWantedCont; + const float localHeadYRotWantedCont = _headYRotWantedCont; + const float localHeadXRotWantedPan = _headXRotWantedPan; + const float localHeadYRotWantedPan = _headYRotWantedPan; + const float localLookXRotWanted = _lookXRotWanted; + const float localLookYRotWanted = _lookYRotWanted; + TRANSF(gunXRotWanted) TRANSF(gunYRotWanted) TRANSF(headXRotWanted) @@ -24124,6 +24169,20 @@ TMError Man::TransferMsg(NetworkMessageContext &ctx) TRANSF(headYRotWantedPan) TRANSF(leanZRotWanted) + if (preserveLocalView) + { + _gunXRotWanted = localGunXRotWanted; + _gunYRotWanted = localGunYRotWanted; + _headXRotWanted = localHeadXRotWanted; + _headYRotWanted = localHeadYRotWanted; + _headXRotWantedCont = localHeadXRotWantedCont; + _headYRotWantedCont = localHeadYRotWantedCont; + _headXRotWantedPan = localHeadXRotWantedPan; + _headYRotWantedPan = localHeadYRotWantedPan; + _lookXRotWanted = localLookXRotWanted; + _lookYRotWanted = localLookYRotWanted; + } + TRANSF_REF(ladderBuilding) TRANSF(ladderIndex) TRANSF(ladderPosition) diff --git a/lib/vehicle.hpp b/lib/vehicle.hpp index 4565f01c..b3686edf 100644 --- a/lib/vehicle.hpp +++ b/lib/vehicle.hpp @@ -1727,6 +1727,14 @@ class Entity: public ObjectTyped, public Animated virtual Vector3 WorldSpeed() const; virtual bool IsInLandscape() const; + //! Accept a valid position update even when this object is not in the landscape yet. + /*! + Used by items that can be moved between an inventory and the world. A + dropped item may receive the position update before the update which adds + it to the landscape, and the transform must not be lost in that case. + */ + virtual bool AcceptPositionOutsideLandscape() const {return false;} + void ResetDelete() {_delete = false;} void ResetMoveOut();