Skip to content

Commit

Permalink
Disable no swing check for 1.8 clients on modern servers
Browse files Browse the repository at this point in the history
  • Loading branch information
SamB440 committed Jul 20, 2024
1 parent 4ebf752 commit ad8488d
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.player.GrimPlayer;
import com.github.retrooper.packetevents.PacketEvents;
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.wrapper.play.client.WrapperPlayClientInteractEntity;
import com.github.retrooper.packetevents.wrapper.play.client.WrapperPlayClientPlayerFlying;

@CheckData(name = "BadPacketsH")
public class BadPacketsH extends Check implements PacketCheck {

// 1.9 packet order: INTERACT -> ANIMATION
// 1.8 packet order: ANIMATION -> INTERACT
// I personally think 1.8 made much more sense. You swing and THEN you hit!
private boolean sentAnimation = player.getClientVersion().isNewerThan(ClientVersion.V_1_8);

public BadPacketsH(final GrimPlayer player) {
Expand All @@ -24,6 +31,19 @@ public void onPacketReceive(PacketReceiveEvent event) {
} else if (event.getPacketType() == PacketType.Play.Client.INTERACT_ENTITY) {
WrapperPlayClientInteractEntity packet = new WrapperPlayClientInteractEntity(event);
if (packet.getAction() != WrapperPlayClientInteractEntity.InteractAction.ATTACK) return;

// There is a "bug" in ViaRewind
// 1.8 packet order: ANIMATION -> INTERACT
// 1.9 packet order: INTERACT -> ANIMATION
// ViaRewind, on 1.9+ servers, delays a 1.8 client's ANIMATION to be after INTERACT (but before flying).
// Which means we see 1.9 packet order for 1.8 clients
// Due to ViaRewind also delaying the swings, we then see packet order above 20CPS like:
// INTERACT -> INTERACT -> ANIMATION -> ANIMATION
// I will simply disable this check for 1.8- clients on 1.9+ servers as I can't be bothered to find a way around this.
// Stop supporting such old clients on modern servers!
if (player.getClientVersion().isOlderThan(ClientVersion.V_1_9)
&& PacketEvents.getAPI().getServerManager().getVersion().isNewerThan(ServerVersion.V_1_8)) return;

if (!sentAnimation && flagAndAlert()) {
event.setCancelled(true);
player.onPacketCancel();
Expand Down

0 comments on commit ad8488d

Please sign in to comment.