Skip to content

Commit

Permalink
more PacketOrderC stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ManInMyVan committed Oct 16, 2024
1 parent 8f38d4c commit f9aadca
Showing 1 changed file with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.protocol.player.InteractionHand;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerFlying;

Expand All @@ -22,6 +23,8 @@ public PacketOrderC(final GrimPlayer player) {
private final boolean exempt = player.getClientVersion().isOlderThanOrEquals(ClientVersion.V_1_7_10);
private boolean sentInteractAt = false;
private int requiredEntity;
private InteractionHand requiredHand;
private boolean requiredSneaking;

@Override
public void onPacketReceive(PacketReceiveEvent event) {
Expand All @@ -30,53 +33,61 @@ public void onPacketReceive(PacketReceiveEvent event) {
}

if (event.getPacketType() == PacketType.Play.Client.INTERACT_ENTITY) {
final WrapperPlayClientInteractEntity packet = new WrapperPlayClientInteractEntity(event);

final WrapperPlayClientInteractEntity wrapper = new WrapperPlayClientInteractEntity(event);

final PacketEntity entity = player.compensatedEntities.entityMap.get(wrapper.getEntityId());
final PacketEntity entity = player.compensatedEntities.entityMap.get(packet.getEntityId());

// For armor stands, vanilla clients send:
// - when renaming the armor stand or in spectator mode: INTERACT_AT + INTERACT
// - in all other cases: only INTERACT
// Just exempt armor stands to be safe
if (entity != null && entity.getType() == EntityTypes.ARMOR_STAND) return;

switch (wrapper.getAction()) {
final boolean sneaking = packet.isSneaking().orElse(false);

switch (packet.getAction()) {
// INTERACT_AT then INTERACT
case INTERACT:
if (!sentInteractAt) {
if (flagAndAlert("Missed Interact-At") && shouldModifyPackets()) {
if (flagAndAlert("Skipped Interact-At") && shouldModifyPackets()) {
event.setCancelled(true);
player.onPacketCancel();
}
} else if (wrapper.getEntityId() != requiredEntity) {
if (flagAndAlert("Wrong Entity, required=" + requiredEntity + ", entity=" + wrapper.getEntityId()) && shouldModifyPackets()) {
} else if (packet.getEntityId() != requiredEntity || packet.getHand() != requiredHand || sneaking != requiredSneaking) {
String verbose = "requiredEntity=" + requiredEntity + ", entity=" + packet.getEntityId()
+ ", requiredHand=" + requiredHand + ", hand=" + packet.getHand()
+ ", requiredSneaking=" + requiredSneaking + ", sneaking=" + sneaking;
if (flagAndAlert(verbose) && shouldModifyPackets()) {
event.setCancelled(true);
player.onPacketCancel();
}
}

sentInteractAt = false;
break;
case INTERACT_AT:
if (sentInteractAt) {
if (flagAndAlert("Missed Interact") && shouldModifyPackets()) {
if (flagAndAlert("Skipped Interact") && shouldModifyPackets()) {
event.setCancelled(true);
player.onPacketCancel();
}
}
requiredEntity = wrapper.getEntityId();

requiredHand = packet.getHand();
requiredEntity = packet.getEntityId();
requiredSneaking = sneaking;
sentInteractAt = true;
break;
}
}

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

0 comments on commit f9aadca

Please sign in to comment.