Solved Packets errors without full stacktrace

Discussion in 'Spigot Plugin Development' started by MathWellan, Jun 15, 2021.

  1. Hello everyone,

    I have some errors but the full stacktrace is not sent because it's the type of error that disconnect the player.
    Code (Text):
    [16:24:51] [User Authenticator #2/INFO]: UUID of player MathWellan is 77a438d9-fa9f-45a6-ac51-8fbba503b35e
    [16:24:51] [Server thread/INFO]: MathWellan[/<redacted>] logged in with entity id 3 at ([world]19.5, 137.0, 92.4)
    [16:24:51] [Server thread/INFO]: MathWellan lost connection: Internal Exception: java.lang.IllegalArgumentException: Can not set int field net.minecraft.server.v1_12_R1.PacketPlayOutEntityVelocity.a to net.minecraft.server.v1_12_R1.PacketPlayOutSetSlot

    [16:24:58] [User Authenticator #3/INFO]: UUID of player MathWellan is 77a438d9-fa9f-45a6-ac51-8fbba503b35e
    [16:24:58] [Server thread/INFO]: MathWellan[/<redacted>] logged in with entity id 4 at ([world]19.5, 137.0, 92.4)
    [16:24:58] [Server thread/INFO]: MathWellan lost connection: Internal Exception: java.lang.IllegalArgumentException: Can not set int field net.minecraft.server.v1_12_R1.PacketPlayOutEntityVelocity.a to net.minecraft.server.v1_12_R1.PacketPlayOutMapChunk
    I use this code to begin with, and it disconnect the player with NullPointerException. The Packet classes are custom classes.
    Code (Java):
          for(PacketType pt : PacketType.values())
                {
                    if(pt.getClassName().equals("PacketPlayInFlying"))
                    {
                        PacketPlayInFlying packetPlayInFlying = new PacketPlayInFlying(packet);
                        if (packetPlayInFlying.isHasPos()) {
                            player.setLocation(new Vector3D(packetPlayInFlying.getX(), packetPlayInFlying.getY(), packetPlayInFlying.getZ()));
                        }
                        player.update(packetPlayInFlying);
                    }
                    if(pt.getClassName().equals("PacketPlayOutPosition"))
                    {
                        player.setTeleported(player, true);
                        player.reset();
                    }
             
                    if(pt.getClassName().equals("PacketPlayInAbilities"))
                       player.setFlying(new PacketPlayInAbilities(packet).isFlying());
                    if(pt.getClassName().equals("PacketPlayOutEntityVelocity"))
                    {
                        PacketPlayOutEntityVelocity packetPlayOutEntityVelocity = new PacketPlayOutEntityVelocity(player, packet);
                        if (packetPlayOutEntityVelocity.isPlayer()) {
                            player.setVelocity(new Vector3D(packetPlayOutEntityVelocity.getX(), packetPlayOutEntityVelocity.getY() + player.getPhysics().getClientVelocity().getY(), packetPlayOutEntityVelocity.getZ()));
                            player.getLastVelocity().update();
                        }
                    }
                }

    But to locate the error best I removed some of it :
    Code (Java):
          for(PacketType pt : PacketType.values())
                {
                  if(pt.getClassName().equals("PacketPlayInAbilities"))
                       player.setFlying(new PacketPlayInAbilities(packet).isFlying());
                    if(pt.getClassName().equals("PacketPlayOutEntityVelocity"))
                    {
                        PacketPlayOutEntityVelocity packetPlayOutEntityVelocity = new PacketPlayOutEntityVelocity(player, packet);
                        if (packetPlayOutEntityVelocity.isPlayer()) {
                            player.setServerVelocity(new Vector3D(packetPlayOutEntityVelocity.getX(), packetPlayOutEntityVelocity.getY() + player.getPhysics().getClientVelocity().getY(), packetPlayOutEntityVelocity.getZ()));
                            player.getLastVelocity().update();
                        }
                    }
                }
    and now the error is more precise but also kind of random as the Packet named last is not used anywhere in my code
    Code (Text):
    [16:24:51] [User Authenticator #2/INFO]: UUID of player MathWellan is 77a438d9-fa9f-45a6-ac51-8fbba503b35e
    [16:24:51] [Server thread/INFO]: MathWellan[/<redacted>] logged in with entity id 3 at ([world]19.5, 137.0, 92.4)
    [16:24:51] [Server thread/INFO]: MathWellan lost connection: Internal Exception: java.lang.IllegalArgumentException: Can not set int field net.minecraft.server.v1_12_R1.PacketPlayOutEntityVelocity.a to net.minecraft.server.v1_12_R1.PacketPlayOutSetSlot

    [16:24:58] [User Authenticator #3/INFO]: UUID of player MathWellan is 77a438d9-fa9f-45a6-ac51-8fbba503b35e
    [16:24:58] [Server thread/INFO]: MathWellan[/<redacted>] logged in with entity id 4 at ([world]19.5, 137.0, 92.4)
    [16:24:58] [Server thread/INFO]: MathWellan lost connection: Internal Exception: java.lang.IllegalArgumentException: Can not set int field net.minecraft.server.v1_12_R1.PacketPlayOutEntityVelocity.a to net.minecraft.server.v1_12_R1.PacketPlayOutMapChunk
    It seems to be an issue with the field "a" so I looked here to find the right name even though I found the custom classes in a 1.12 compatible project
    so I changed it to "e" but it does the NullPointerException again..
    Code (Java):
            Class packetPlayOutEntityVelocity = Reflections.getNMSClass("PacketPlayOutEntityVelocity");
            // one of these fields, or maybe all of them are a problem
            idField = packetPlayOutEntityVelocity.getFieldByName("e");
            xField = packetPlayOutEntityVelocity.getFieldByName("b");
            yField = packetPlayOutEntityVelocity.getFieldByName("c");
            zField = packetPlayOutEntityVelocity.getFieldByName("d");
    I know it's a huge post, so I will very much appreciate any help, even small leads :)
     
    #1 MathWellan, Jun 15, 2021
    Last edited: Jun 15, 2021
  2. I don’t completely understand this but I don’t think that you need to read from e field, that is the packet ID and I don’t think it has anything to do with the a field. Since you only see errors with that a field try getting rid of it and only accessing the x, y, and z to see if we can narrow down which, if not all of them, field is causing the problem.
     
  3. the "a" field was also supposed to be the ID

    Ok so I got rid of the id first, still the NullPointerException, then x, y, z and it gets me back to the random errors every login
    Code (Text):
    [18:57:07] [User Authenticator #3/INFO]: UUID of player MathWellan is 77a438d9-fa9f-45a6-ac51-8fbba503b35e
    [18:57:07] [Server thread/INFO]: MathWellan[/91.162.194.105:55801] logged in with entity id 15 at ([world]19.5, 137.0, 92.4)
    [18:57:07] [Server thread/INFO]: MathWellan lost connection: Internal Exception: java.lang.IllegalArgumentException: Can not set int field net.minecraft.server.v1_12_R1.PacketPlayOutEntityVelocity.b to net.minecraft.server.v1_12_R1.PacketPlayOutSetSlot

    [18:57:12] [User Authenticator #4/INFO]: UUID of player MathWellan is 77a438d9-fa9f-45a6-ac51-8fbba503b35e
    [18:57:12] [Server thread/INFO]: MathWellan[/91.162.194.105:39661] logged in with entity id 26 at ([world]19.5, 137.0, 92.4)
    [18:57:12] [Server thread/INFO]: MathWellan lost connection: Internal Exception: java.lang.IllegalArgumentException: Can not set int field net.minecraft.server.v1_12_R1.PacketPlayOutEntityVelocity.b to net.minecraft.server.v1_12_R1.PacketPlayOutMapChunk
    For the record I found the custom Packet classes here : https://github.com/heirteir/AutoEye/tree/master/src/main/java/com/heirteir/autoeye/packets/wrappers
    @Heretere
     
    #3 MathWellan, Jun 15, 2021
    Last edited: Jun 15, 2021
  4. Moving on and getting rid of the PacketPlayOutEntityVelocity, I looked again on this page for the PacketPlayInAbilities it says the 1.12 flying field name is "c". I tried changing it and it also does the random errors (not because of PacketPlayOutEntityVelocity this time)

    Any thought about using this website ?
     
  5. Try wrapping the whole thing with try-catch throwable.

    Code (Text):
    try {
      // everything
    } catch (Throwable e) {
      e.printStackTrace();
    }
     
    • Useful Useful x 1
  6. The Link is not really wrong, its sends you to the newest version of the protocol. For 1.12 here.

    And
    Thats not a nice way to fix something. You just ignoring the problem but dont fix it
     
    • Agree Agree x 1
  7. Thanks @NascentNova I have the stacktrace now, the NullPointerException seems to come from the field#get(Object) in the Packet classes

    Thank you, I can't find the PacketPlayInFlying tho and in the Entity Velocity packet for x,y,z it just indicates the names are x,y,z which can't be
     
  8. You need to include the spigot.jar and check how the names of the field are. If you using intellij, you can search for the packet name and open the class, intellij decompiles it, so you see everything.
     
  9. The code was intended to address OP's issue that the full stacktrace wasn't properly provided.
     
    • Like Like x 2
  10. [​IMG]

    So it shouldn't be null, it's definitely the field#get(Object) but it's basically a java method how is that possible
     
  11. You might want to set those fields to accessible first.
     
  12. Actually, what if you just use these methods to get your values since they’re public? upload_2021-6-16_11-25-24.jpeg
     
  13. I could but I also need hasPos and it is protected, no public method to get it
    [​IMG]
     
  14. Two things:
    Have you at least tried those public methods.

    Second:
    Have you set those fields to accessible like I said in my message before the last?
     
  15. I use an util for the reflection and it does set accessible

    No and I don't doubt it works but I will need hasPos at some point and this thread received an answer that indicates using reflection is the only way
     
  16. Hey, you referenced an old thread of mine.

    Anyways, if reflection is not needed, you don't need to use it. You can listen for the packet directly using a ChannelDuplexHandler. In the situation that you do need reflection, it changes up a bit in 1.9+ due to the need of PacketPlayInFlying values needing a fall back. In this case, you can just set it to 0.0 (This happens primarily if they haven't rotated their head, or changed foot positions).

    An example in 1.9+ if you use NMS directly is as following:
    Code (Text):

    double x = flyingPacket.a(0.0D);
    double y = flyingPacket.b(0.0D);
    double z = flyingPacket.c(0.0D);

    float yaw = flyingPacket.a(0.0F);
    float pitch = flyingPacket.b(0.0F);
     
    If you do have to use reflections, you'll have to invoke it.

    Why not use ProtocolLib though?
     
    #16 ToonBasic, Jun 17, 2021
    Last edited: Jun 17, 2021
  17. Also to put PacketPlayOutEntityVelocity on the table again, this one has no public methods so even if hasPos in PacketPlayInFlying didn't exist I have many reasons to use reflection. Anyway for now it's 4am and those fields, cast, obfuscated methods are driving me crazy. Will continue reading your answers and searching tomorrow guys thank you for your implication and help
     
  18. PacketPlayOutEntityVelocity is for entity velocity (Such as knockback). It will not function as regular movement if that's what you're aiming for.

    PacketPlayInFlying is what you're looking for and I answered how to use it above.
     
  19. You mention you have custom packet classes? I was bored and decided to do this myself and was able to read all values of both packets using some simple reflection. Could we see the custom classes and any other code involved so we can further help troubleshoot?

    Also, I actually have a sort of hacky workaround to solve this issue with hasPos not having a method that I just thought up which should work...

    Code (Java):
    if(flyingPacket.a(0.0F) == flyingPacket.a(0.1F)) {
    //hasPost = true;
    }
     
    • Useful Useful x 1
  20. Or just check if it's greater than 0.0? No need to do any of that.