Skip to content

[FEAT] The PDC Filter #79

Description

@iceBear67

To reduce meaningless bandwidth overheads caused by #42 (with PDC), PDC Filter is set.

Patch

By redefine.

At FriendlyByteBuf (Paper, called PacketDataSerializer in spigot)

    public FriendlyByteBuf writeItem(ItemStack stack) {
        if (stack.isEmpty() || stack.getItem() == null) { // CraftBukkit - NPE fix itemstack.getItem()
            this.writeBoolean(false);
        } else {
            this.writeBoolean(true);
            Item item = stack.getItem();

            this.writeVarInt(Item.getId(item));
            this.writeByte(stack.getCount());
            CompoundTag nbttagcompound = null;

            if (item.canBeDepleted() || item.shouldOverrideMultiplayerNbt()) {
                // Spigot start - filter
                stack = stack.copy();
                // CraftItemStack.setItemMeta(stack, CraftItemStack.getItemMeta(stack)); // Paper - This is no longer needed due to NBT being supported
                // Spigot end
                nbttagcompound = stack.getTag();
                // Paper start
                if (nbttagcompound != null && nbttagcompound.contains("SkullOwner", 10)) {
                    CompoundTag owner = nbttagcompound.getCompound("SkullOwner");
                    if (owner.hasUUID("Id")) {
                        nbttagcompound.putUUID("SkullOwnerOrig", owner.getUUID("Id"));
                        net.minecraft.world.level.block.entity.SkullBlockEntity.sanitizeUUID(owner);
                    }
                }
                // Paper end
            }

            this.writeNbt(nbttagcompound);
        }

        return this;
    }

Inserting hooks before this.writeNbt(nbttagcompound) would work, however it is leading to full of asm codes.

Tasks

So here're our tasks:

  1. Find CompoundTag in obfuscated environments. (including 1.18+, treat them as obfuscated)
  2. Find FriendlyByteBuf / PacketDataSerializer in obfuscated environments.
  3. Determine injector solution. Predefine or redefine or server patching? I prefer redefine with mixin but there're no projects has implemented mixin injection for bukkit ( or poor API )

Other

This feature is an option and disabled by default.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions