From 183f6099604058270bbf269f188bdc0a0a886377 Mon Sep 17 00:00:00 2001 From: Allink <44676012+allinkdev@users.noreply.github.com> Date: Tue, 12 Jul 2022 17:19:31 +0100 Subject: [PATCH] Fix container click patch (#47) --- ...033-Prevent-invalid-container-events.patch | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/patches/server/0033-Prevent-invalid-container-events.patch b/patches/server/0033-Prevent-invalid-container-events.patch index 5eefc0e..ceed382 100644 --- a/patches/server/0033-Prevent-invalid-container-events.patch +++ b/patches/server/0033-Prevent-invalid-container-events.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Prevent invalid container events diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java -index 7c6fceb410f6b8683795a0a967dfe3305a689e26..5a8d4421c2de0680a3f4880451badcf5c4b46597 100644 +index 7c6fceb410f6b8683795a0a967dfe3305a689e26..1851a9eaf0ea56434d9b96c7c829ee5411f666fe 100644 --- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java @@ -31,6 +31,8 @@ import java.util.function.UnaryOperator; @@ -17,23 +17,30 @@ index 7c6fceb410f6b8683795a0a967dfe3305a689e26..5a8d4421c2de0680a3f4880451badcf5 import net.minecraft.ChatFormatting; import net.minecraft.CrashReport; import net.minecraft.CrashReportCategory; -@@ -2840,6 +2842,19 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser +@@ -2840,6 +2842,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser public void handleContainerClick(ServerboundContainerClickPacket packet) { PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel()); if (this.player.isImmobile()) return; // CraftBukkit -+ -+ // Scissors start - Do not call events when the slot/button number is invalid -+ final int sentSlotNum = packet.getSlotNum(); -+ if(Mth.clamp(sentSlotNum, 0, 45) != sentSlotNum) -+ { -+ this.getCraftPlayer().kick( -+ net.kyori.adventure.text.Component.text("Invalid container click slot (Hacking?)") -+ .color(NamedTextColor.RED) -+ ); -+ return; -+ } -+ // Scissors end + this.player.resetLastActionTime(); if (this.player.containerMenu.containerId == packet.getContainerId() && this.player.containerMenu.stillValid(this.player)) { // CraftBukkit boolean cancelled = this.player.isSpectator(); // CraftBukkit - see below if +@@ -2859,6 +2862,18 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser + return; + } + ++ // Scissors start - Do not call events when the slot/button number is invalid ++ final int sentSlotNum = packet.getSlotNum(); ++ if((Mth.clamp(sentSlotNum, -1, this.player.containerMenu.slots.size() - 1) != sentSlotNum) && sentSlotNum != -999) ++ { ++ this.getCraftPlayer().kick( ++ net.kyori.adventure.text.Component.text("Invalid container click slot (Hacking?)") ++ .color(NamedTextColor.RED) ++ ); ++ return; ++ } ++ // Scissors end ++ + InventoryView inventory = this.player.containerMenu.getBukkitView(); + SlotType type = inventory.getSlotType(packet.getSlotNum()); +