meteor-client icon indicating copy to clipboard operation
meteor-client copied to clipboard

Some events should not be instanced

Open 0x000006 opened this issue 1 year ago • 0 comments

Describe the bug

An instanced event's fields can change mid processing because of async tasks (example: processing something on main thread while network thread is sending packets) or the event itself. This affects all events that are instantiated and have fields.

This can lead to weird things like the event not being cancelled or in this case event.packet getting changed.

Steps to reproduce

private boolean recursionFix = false;

@EventHandler
private void onPacketSend(PacketEvent.Send event) {
    if (recursionFix) return;

    recursionFix = true;

    Packet<?> packet = event.packet;
    event.setCancelled(true);

    // can be any packet
    mc.getNetworkHandler().sendPacket(new HandSwingC2SPacket(Hand.MAIN_HAND));

    System.out.println(event.packet.getClass());
    if (event.packet != packet || !event.isCancelled()) {
        throw new RuntimeException();
    }

    recursionFix = false;
}

Meteor Version

0.5.8-2156

Minecraft Version

1.21.1

Operating System

Windows

Before submitting a bug report

  • [X] This bug wasn't already reported (I have searched bug reports on GitHub).

  • [X] This is a valid bug (I am able to reproduce this on the latest dev build).

0x000006 avatar Aug 31 '24 20:08 0x000006