forked from GrimAnticheat/Grim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
277 additions
and
23 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/main/java/ac/grim/grimac/checks/impl/badpackets/BadPacketsU.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package ac.grim.grimac.checks.impl.badpackets; | ||
|
||
import ac.grim.grimac.checks.Check; | ||
import ac.grim.grimac.checks.CheckData; | ||
import ac.grim.grimac.checks.type.PacketCheck; | ||
import ac.grim.grimac.player.GrimPlayer; | ||
import ac.grim.grimac.utils.data.packetentity.PacketEntity; | ||
import com.github.retrooper.packetevents.event.PacketReceiveEvent; | ||
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes; | ||
import com.github.retrooper.packetevents.protocol.packettype.PacketType; | ||
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientInteractEntity; | ||
|
||
@CheckData(name = "BadPacketsU") | ||
public class BadPacketsU extends Check implements PacketCheck { | ||
|
||
public BadPacketsU(final GrimPlayer player) { | ||
super(player); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/java/ac/grim/grimac/events/packets/patch/EnforceUseItemStupidity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package ac.grim.grimac.events.packets.patch; | ||
|
||
import ac.grim.grimac.GrimAPI; | ||
import ac.grim.grimac.checks.impl.badpackets.BadPacketsU; | ||
import ac.grim.grimac.player.GrimPlayer; | ||
import com.github.retrooper.packetevents.PacketEvents; | ||
import com.github.retrooper.packetevents.event.PacketListenerAbstract; | ||
import com.github.retrooper.packetevents.event.PacketListenerPriority; | ||
import com.github.retrooper.packetevents.event.PacketReceiveEvent; | ||
import com.github.retrooper.packetevents.manager.server.ServerVersion; | ||
import com.github.retrooper.packetevents.protocol.packettype.PacketType; | ||
import com.github.retrooper.packetevents.protocol.player.ClientVersion; | ||
import com.github.retrooper.packetevents.protocol.world.BlockFace; | ||
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerBlockPlacement; | ||
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerFlying; | ||
|
||
// This runs before anything else, so this way we can simulate receiving flying. | ||
public class EnforceUseItemStupidity extends PacketListenerAbstract { | ||
|
||
public EnforceUseItemStupidity() { | ||
super(PacketListenerPriority.LOWEST); | ||
} | ||
|
||
@Override | ||
public void onPacketReceive(PacketReceiveEvent event) { | ||
GrimPlayer player = GrimAPI.INSTANCE.getPlayerDataManager().getPlayer(event.getUser()); | ||
if (player == null) return; | ||
|
||
// Stupidity packet only exists on 1.17+ | ||
if (player.getClientVersion().isOlderThan(ClientVersion.V_1_17)) return; | ||
|
||
final boolean wasPotentiallyOnePointSeventeenDuplicate = player.packetStateData.lastTeleportWasPotentiallyOnePointSeventeenDuplicate; | ||
if (isUseItem(event)) { | ||
player.packetStateData.lastTeleportWasPotentiallyOnePointSeventeenDuplicate = false; | ||
if (!player.packetStateData.detectedStupidity && !wasPotentiallyOnePointSeventeenDuplicate) { | ||
// The player MUST send a stupidity packet before use item | ||
player.checkManager.getPacketCheck(BadPacketsU.class).flagAndAlert("type=skipped_stupid"); | ||
return; | ||
} | ||
} | ||
|
||
player.packetStateData.lastTeleportWasPotentiallyOnePointSeventeenDuplicate = false; | ||
|
||
// If we received a believed stupidity packet, the next packet MUST be USE_ITEM. | ||
// If not, we were wrong or the client is attempting to fake stupidity. | ||
if (player.packetStateData.detectedStupidity || wasPotentiallyOnePointSeventeenDuplicate) { | ||
if (isUseItem(event)) { | ||
// Valid stupidity packet. | ||
player.packetStateData.detectedStupidity = false; | ||
|
||
// Possibly delay this USE_ITEM packet. | ||
player.checkManager.getPacketCheck(UseItemDelayer.class).addDelayed(event); | ||
|
||
player.packetStateData.lastLastStupidity = player.packetStateData.lastStupidity; | ||
player.packetStateData.lastStupidity = null; | ||
player.packetStateData.lastMovementWasDefinitelyOnePointSeventeenDuplicate = true; | ||
// Bukkit.broadcastMessage("valid stupidity packet"); | ||
return; | ||
} | ||
|
||
// Reset | ||
player.packetStateData.detectedStupidity = false; | ||
player.packetStateData.lastMovementWasDefinitelyOnePointSeventeenDuplicate = false; | ||
|
||
// Let's ignore teleports | ||
if (player.packetStateData.lastStupidity == null || wasPotentiallyOnePointSeventeenDuplicate) return; // Probably a teleport | ||
|
||
// We were wrong about it being stupidity, or the client is attempting to fake stupidity, reprocess this packet as non-stupidity | ||
player.packetStateData.ignoreDuplicatePacket = true; | ||
|
||
PacketEvents.getAPI().getPlayerManager().receivePacket(player.bukkitPlayer, new WrapperPlayClientPlayerFlying(true, true, player.packetStateData.packetPlayerOnGround, player.packetStateData.lastStupidity)); | ||
// Bukkit.broadcastMessage("not stupidity"); | ||
} | ||
} | ||
|
||
private boolean isUseItem(PacketReceiveEvent event) { | ||
// This is USE_ITEM but translated by via | ||
if (PacketEvents.getAPI().getServerManager().getVersion().isOlderThan(ServerVersion.V_1_9) && event.getPacketType() == PacketType.Play.Client.PLAYER_BLOCK_PLACEMENT) { | ||
return new WrapperPlayClientPlayerBlockPlacement(event).getFace() == BlockFace.OTHER; | ||
} | ||
return event.getPacketType() == PacketType.Play.Client.USE_ITEM; | ||
} | ||
} |
Oops, something went wrong.