Skip to content

Commit

Permalink
Merge pull request #1860 from ManInMyVan/bpP
Browse files Browse the repository at this point in the history
show click type name and use enhanced switch statements in BadPacketsP
  • Loading branch information
ManInMyVan authored Dec 13, 2024
2 parents 4c21c11 + 7fe146d commit a620149
Showing 1 changed file with 12 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientClickWindow;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientClickWindow.WindowClickType;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerOpenWindow;

@CheckData(name = "BadPacketsP", experimental = true)
Expand All @@ -33,35 +34,21 @@ public void onPacketSend(final PacketSendEvent event) {
public void onPacketReceive(PacketReceiveEvent event) {
if (event.getPacketType() == PacketType.Play.Client.CLICK_WINDOW) {
WrapperPlayClientClickWindow wrapper = new WrapperPlayClientClickWindow(event);
int clickType = wrapper.getWindowClickType().ordinal();
WindowClickType clickType = wrapper.getWindowClickType();
int button = wrapper.getButton();

boolean flag = false;
// TODO: Adjust for containers
boolean flag = switch (clickType) {
case PICKUP, QUICK_MOVE, THROW -> button != 0 && button != 1;
case SWAP -> (button > 8 || button < 0) && button != 40;
case CLONE -> button != 2;
case QUICK_CRAFT -> button == 3 || button == 7 || button > 10 || button < 0;
case PICKUP_ALL -> button != 0;
};

//TODO: Adjust for containers
switch (clickType) {
case 0:
case 1:
case 4:
if (button != 0 && button != 1) flag = true;
break;
case 2:
if ((button > 8 || button < 0) && button != 40) flag = true;
break;
case 3:
if (button != 2) flag = true;
break;
case 5:
if (button == 3 || button == 7 || button > 10 || button < 0) flag = true;
break;
case 6:
if (button != 0) flag = true;
break;
}

//Allowing this to false flag to debug and find issues faster
// Allowing this to false flag to debug and find issues faster
if (flag) {
if (flagAndAlert("clickType=" + clickType + " button=" + button + (wrapper.getWindowId() == containerId ? " container=" + containerType : "")) && shouldModifyPackets()) {
if (flagAndAlert("clickType=" + clickType.toString().toLowerCase() + ", button=" + button + (wrapper.getWindowId() == containerId ? ", container=" + containerType : "")) && shouldModifyPackets()) {
event.setCancelled(true);
player.onPacketCancel();
}
Expand Down

0 comments on commit a620149

Please sign in to comment.