ProtocolLib

3M Downloads

Field index out of bounds

JHarris12345 opened this issue · 4 comments

commented
  • This issue is not solved in a development build

Describe the bug
When I try to create a packet container for the client custom payload, I cannot write to the byte array field.

To Reproduce
Steps to reproduce the behavior:

  1. I am using the latest 5.0.0-SNAPSHOT API

  2. Here is my code:

         PacketContainer packetContainer = new PacketContainer(PacketType.Play.Client.CUSTOM_PAYLOAD);
         packetContainer.getByteArrays().write(0, bytes);
    
  3. I get the error Field index 0 is out of bounds for length 0

Expected behavior
It should allow me to get that field

Screenshots
If applicable, add screenshots to help explain your problem.

Version Info
Provide your ProtocolLib install info with /protocol dump through pastebin.
http://dump-2022-12-21_12.13.31.txt

Additional context
Add any other context about the problem here.

commented

Hi,

I'm using the latest version (build 608 version 5.0.0-SNAPSHOT and Paper 1.19.3 build 350) and still have the same problem. Here is the code I am using. (I specify that everything worked very well in 1.19.2).

image

image

commented

@JHarris12345 your problem is that the field type is not a byte array but a packet data serializer. You can access that field with packetContainer.getModifier().withType(ByteBuf.class) and create a buffer from your byte array with:

      ByteBuf buffer = Unpooled.copiedBuffer(<the byte array>);
      Object wrappedSerializableBuffer = MinecraftReflection.getPacketDataSerializer(buffer);
      container.getModifier().withType(ByteBuf.class).write(0, wrappedSerializableBuffer);

@TheCalypso your issue is that the info action field changed from a single action to an enum set of actions. Use getPlayerInfoActions() to access that field. Note that REMOVE_PLAYER was moved to a separate packet (PacketType.Play.Server.PLAYER_INFO_REMOVE) and you just need to write the uuid of the player into the packet to remove him.

commented

@JHarris12345votre problème est que le type de champ n'est pas un tableau d'octets mais un sĂ©rialiseur de donnĂ©es par paquets. Vous pouvez accĂ©der Ă  ce champ avec packetContainer.getModifier().withType(ByteBuf.class)et crĂ©er un tampon Ă  partir de votre tableau d'octets avec :

      ByteBuf buffer = Unpooled.copiedBuffer(<the byte array>);
      Object wrappedSerializableBuffer = MinecraftReflection.getPacketDataSerializer(buffer);
      container.getModifier().withType(ByteBuf.class).write(0, wrappedSerializableBuffer);

@TheCalypsovotre problème est que le champ d'action d'information est passé d'une action unique à un ensemble d'actions enum. Utilisez getPlayerInfoActions()pour accéder à ce champ. Notez que REMOVE_PLAYER a été déplacé vers un paquet séparé ( PacketType.Play.Server.PLAYER_INFO_REMOVE) et il vous suffit d'écrire l'uuid du joueur dans le paquet pour le supprimer.

image

Hello, thank you for your reply. Could you give me an example? Currently I use these methods so that the fakeplayer is not sent to the player in the TABlist. However I can see that PLAYER_INFO_REMOVE has been moved. But I don't see how I can use it.

Can you tell me more ?

commented

I tried this it seems to work.
image

On the other hand I have a new error with ADD_PLAYER.
Did anything change in 1.19.3 about this?
image