Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bedrock: Incorrect NPC packet serialization #644

Open
Bluebotlabz opened this issue Oct 20, 2022 · 10 comments
Open

bedrock: Incorrect NPC packet serialization #644

Bluebotlabz opened this issue Oct 20, 2022 · 10 comments
Labels
bedrock Bedrock edition

Comments

@Bluebotlabz
Copy link

Bluebotlabz commented Oct 20, 2022

These packets and information were taken from version 1.19.31
It is possible, yet unlikely, that this is specific to this version

There is a possible packet with request type of 6:

{"runtime_entity_id":"13","request_type":6,"command":"","action_type":"set_actions","scene_name":""}

It appears to be the opening equivalent of execute_closing_commands execute_opening_commands
As NPC are capable of executing commands when they are interacted with

Additionally,
NPC packets with request type of 1 (or "execute_action") are parsed incorrectly, according to the documentation action type is an enum, however, when request_type is 1 (or "execute_action") it is actually an integer referring to the button which was pressed, starting from 0, which corresponds to the leftmost button

note: despite being an int, the client limits the number of possible buttons you can add to 6 buttons, so action_type will never be higher than 5 if the request_type is 1

Similar behaviour is observed when request_type equals 4 (or set_skin) in which the action_type actuall corresponds to the NPC's set skin (again, counting from 0, left to right) the highest action_type for setting the NPC's skin is 34 in the current update, however, this may change in the future

Lastly, I believe that the notes for the Command field name are somewhat misleading as it isn't necessarily a command
ie: when setting dialogue, it is equal to what is being typed and in set_actions it is equal to a JSON object containing all the possible NPC actions (it effectively override the action related entity data)

NOTE: All of this data is from the Bedrock edition of the game, while the Education Edition may behave in the same way, I have no way of confirming this, however, it is likely that it does

@Bluebotlabz
Copy link
Author

Interestingly enough, in

6: execute_openining_commands

You can see that action_type of 6 is valid in the enum, but not request_type of 6

@Bluebotlabz
Copy link
Author

Bluebotlabz commented Oct 20, 2022

Also, there is an action_type 2 for packet_npc_dialogue

I don't know what it does though It appears to close it

@extremeheat
Copy link
Member

extremeheat commented Oct 21, 2022

I don't see any problem here. If id 6 is returned by the server and we don't have a string mapping for it, it will (as intended) return the raw integer read from stream. There are no conditional fields in this packet so the reading of one field will not impact that of any other.

@Bluebotlabz
Copy link
Author

Bluebotlabz commented Oct 21, 2022

I believe that it should be mapped to a string called "execute_closing_commands" "execute_opening_commands"

@extremeheat
Copy link
Member

extremeheat commented Oct 21, 2022

Where are you sourcing that change ? Link to GitHub ?

@Bluebotlabz
Copy link
Author

Bluebotlabz commented Oct 21, 2022

I would create a pr with minecraft-data, however, I am unable to test it locally as I am having problems with npm installing it when I did clone it...

I'll send some packet data in a second that pretty much confirms that id 6 is closing commands

@extremeheat
Copy link
Member

Can you provide a buffer then ? I will test it when I get the free time. We have CI for basic checks but it's not exhaustive in checking individual packets. Posting a Github link to an external implementation doing it as you suggest would be helpful to base the changes from. Moving this to minecraft-data.

@extremeheat extremeheat transferred this issue from PrismarineJS/bedrock-protocol Oct 21, 2022
@extremeheat extremeheat changed the title NPC Request packet parsing of action_type is incorrect when request_type equals 1 (or execute_action) and also when request_type equals 4 (or set_skin) bedrock: Incorrect NPC packet serialization Oct 21, 2022
@Bluebotlabz
Copy link
Author

Bluebotlabz commented Oct 21, 2022

Ok, somehow I have made a typo all throughout this issue, id 6 is execute_opening_commands

I'm not sure how I didn't catch that, but I'll edit it now

I'm not too sure how to export a buffer, so I'll just send a JSON packet log with the required packets when I can

@extremeheat extremeheat added the bedrock Bedrock edition label Apr 8, 2023
@extremeheat
Copy link
Member

@Bluebotlabz
Copy link
Author

That looks like it fixes it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bedrock Bedrock edition
Projects
None yet
Development

No branches or pull requests

2 participants