Skip to content

Commit

Permalink
Check entity in PacketOrderC
Browse files Browse the repository at this point in the history
  • Loading branch information
ManInMyVan committed Sep 1, 2024
1 parent 1acb3f1 commit c3e04e0
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerFlying;

@CheckData(name = "PacketOrderC", experimental = true)
public class PacketOrderC extends Check implements PacketCheck {
Expand All @@ -20,10 +21,15 @@ public PacketOrderC(final GrimPlayer player) {
// 1.7 players do not send INTERACT_AT, so we cannot check them
private final boolean exempt = player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_7_10);
private boolean sentInteractAt = false;
private int requiredEntity;

@Override
public void onPacketReceive(PacketReceiveEvent event) {
if (event.getPacketType() == PacketType.Play.Client.INTERACT_ENTITY && !exempt) {
if (exempt) {
return;
}

if (event.getPacketType() == PacketType.Play.Client.INTERACT_ENTITY) {

final WrapperPlayClientInteractEntity wrapper = new WrapperPlayClientInteractEntity(event);

Expand All @@ -43,6 +49,11 @@ public void onPacketReceive(PacketReceiveEvent event) {
event.setCancelled(true);
player.onPacketCancel();
}
} else if (wrapper.getEntityId() != requiredEntity) {
if (flagAndAlert("Wrong Entity, required=" + requiredEntity + ", entity=" + wrapper.getEntityId()) && shouldModifyPackets()) {
event.setCancelled(true);
player.onPacketCancel();
}
}
sentInteractAt = false;
break;
Expand All @@ -53,9 +64,19 @@ public void onPacketReceive(PacketReceiveEvent event) {
player.onPacketCancel();
}
}
requiredEntity = wrapper.getEntityId();
sentInteractAt = true;
break;
}
}

if (WrapperPlayClientPlayerFlying.isFlying(event.getPacketType())) {
if (sentInteractAt) {
if (flagAndAlert("Missed Interact (Tick)") && shouldModifyPackets()) {
event.setCancelled(true);
player.onPacketCancel();
}
}
}
}
}

0 comments on commit c3e04e0

Please sign in to comment.