feat(server/state): expose attachment offset, bone and flags - #4094
Open
Github-Samuel wants to merge 1 commit into
Open
feat(server/state): expose attachment offset, bone and flags#4094Github-Samuel wants to merge 1 commit into
Github-Samuel wants to merge 1 commit into
Conversation
GET_ENTITY_ATTACHED_TO only reads attachedTo out of CBaseAttachNodeData, even though the attach nodes parse the rest of it. Add getters for the fields that describe how the entity is attached: - GET_ENTITY_ATTACHMENT_OFFSET - GET_ENTITY_ATTACHMENT_BONE_INDEX - GET_ENTITY_ATTACHMENT_FLAGS The offset is gated on hasOffset because CPhysicalAttachDataNode leaves x/y/z alone when that bit is clear, and the bone index maps the 0xFFFF sentinel that node writes for "no bone" onto -1. Signed-off-by: Samuel Nicol <99494967+Github-Samuel@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal of this PR
Let a server see how an entity is attached, not just what it is attached to.
GET_ENTITY_ATTACHED_TOgives you the parent entity, but the offset, bone and flags are already parsed and there is currently no way to read them.How is this PR achieving the goal
CBaseAttachNodeDataalready carries all of it, and both attach nodes fill it in.CPhysicalAttachDataNode::Parse:with
CPedAttachDataNode::Serializewriting the same base fields for peds and players.GetAttachment()already resolves whichever of the two the tree has, so this only adds the three getters on top:GET_ENTITY_ATTACHMENT_OFFSETx,y,zGET_ENTITY_ATTACHMENT_BONE_INDEXattachBoneGET_ENTITY_ATTACHMENT_FLAGSattachmentFlagsTwo details worth calling out, since the two parsers don't behave identically:
hasOffset.CPedAttachDataNodezeroesx/y/zin its else branch butCPhysicalAttachDataNodeleaves them untouched, so reading them unconditionally would hand back whatever was last there.attachBoneis returned as-1when it is0xFFFF, which is whatCPhysicalAttachDataNodewrites when there are no attach bones.The flags are the same value the server already relies on for the parachute check in
ServerGameState.cpp:so this is not new data being trusted, just data that scripts couldn't see.
I left the orientation out. It is stored as a quaternion (
qx/qy/qz/qw) and there is no four component return type here, so it would mean picking a euler convention and converting, which felt like it deserved its own change rather than being guessed at in this one.Marked
game: gta5in the declarations: the natives are registered for both, butSyncTrees_RDR3.hreturnsnullptrfromGetAttachment()and its attach nodes are empty stubs, so on RedM they would only ever return the defaults.GetEntityAttachedTo.mdhas nogameline today even though it has the same limitation, so say the word if you would rather these matched it.This PR applies to the following area(s)
FXServer, OneSync, Natives
Successfully tested on
Game builds: n/a, none of these fields are build gated
Platforms: Windows, Linux
Checklist
I could not do a full server build locally so I left the first box unchecked. What I did check is that both attach parsers actually write these fields, which of them zero their outputs and which don't, that
GetAttachment()resolves both node types, that RedM returnsnullptrthere so the null checks cover it, and that none of the three names collide with an existing native.