Skip to content

Fix aim pose desync when a weapon is given while the aim/fire button is held#4972

Open
TheCrazy17 wants to merge 1 commit into
multitheftauto:masterfrom
TheCrazy17:fix/aim-desync-on-weapon-change
Open

Fix aim pose desync when a weapon is given while the aim/fire button is held#4972
TheCrazy17 wants to merge 1 commit into
multitheftauto:masterfrom
TheCrazy17:fix/aim-desync-on-weapon-change

Conversation

@TheCrazy17

Copy link
Copy Markdown
Contributor

Summary

CNetAPI::WritePlayerPuresync now clears the aim/fire (RightShoulder1/ButtonCircle) keysync bits in the outgoing on-foot puresync packet when the local ped's secondary attack task isn't actually TASK_SIMPLE_USE_GUN, instead of blindly forwarding the raw button state.

Motivation

Fixes #518, an ancient bug open since 2018.

GTA:SA only starts TASK_SIMPLE_USE_GUN on a fresh button press, not while held. If a weapon is given while aim is already held from before, the local pose looks right but the puresync protocol has no explicit "is aiming" wire bit - every reader rederives it from the raw keysync bits, which were still "held", so everyone else saw the player stuck aiming/running-aiming.

Before mta-screen_2026-06-21_21-07-08 8a8517b7-65f8-4a7c-9880-fa9aec3147a4

Test plan

Reproduced locally with two clients:

  • Held aim with no weapon, then ran giveWeapon(player, 34, 30, true) (sniper) via a server-side bindKey test script while still holding aim.
  • Before the fix: the local client correctly showed no aim pose, but the second client watching remotely saw the player aiming and running in the aiming animation.
  • After the fix: both clients show the same (correct, non-aiming) pose.
  • Also confirmed the fix covers picking up a weapon from a ground pickup, since CPickup.cpp calls the same CStaticFunctionDefinitions::GiveWeapon path used by the scripted function.

Checklist

  • Your code should follow the coding guidelines.
  • Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.

…is already held

GTA:SA's TASK_SIMPLE_USE_GUN only starts on a fresh aim/fire button
press, not while the button is continuously held. If a ped receives a
weapon while already holding aim from before it had one, the local
engine never starts the use-gun task and the local pose looks right.

The on-foot puresync protocol has no explicit "is aiming" wire bit -
every reader independently rederives it from the raw RightShoulder1/
ButtonCircle keysync bits, which were still "held" from before the
weapon change. WritePlayerPuresync now clears those bits in the
outgoing copy when the local ped's actual secondary attack task isn't
TASK_SIMPLE_USE_GUN, keeping every downstream consumer's
independently-derived aim bit consistent with what the local client is
actually doing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Aiming before picking up a weapon causes desync

1 participant