Skip to content

Commit

Permalink
Merge branch '2.0' of https://github.com/GrimAnticheat/Grim into 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AoElite committed Dec 27, 2023
2 parents edbb5b3 + 055e0d9 commit ab48248
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 18 deletions.
8 changes: 5 additions & 3 deletions src/main/java/ac/grim/grimac/checks/impl/misc/FastBreak.java
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ public void onPacketReceive(PacketReceiveEvent event) {
blockDelayBalance += 300 - breakDelay;
}

if (blockDelayBalance > 1000 && shouldModifyPackets()) { // If more than a second of advantage
event.setCancelled(true); // Cancelling start digging will cause server to reject block break
player.onPacketCancel();
if (blockDelayBalance > 1000) { // If more than a second of advantage
flagAndAlert("Delay=" + breakDelay);
if (shouldModifyPackets()) {
event.setCancelled(true); // Cancelling start digging will cause server to reject block break
player.onPacketCancel();
}
}

clampBalance();
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/ac/grim/grimac/player/GrimPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,9 @@ public void sendTransaction() {
}

public void sendTransaction(boolean async) {
// don't send transactions in configuration phase
if (user.getDecoderState() == ConnectionState.CONFIGURATION) return;
// don't send transactions outside PLAY phase
// Sending in non-play corrupts the pipeline, don't waste bandwidth when anticheat disabled
if (user.getConnectionState() != ConnectionState.PLAY) return;
if (user.getEncoderState() != ConnectionState.PLAY) return;

// Send a packet once every 15 seconds to avoid any memory leaks
if (disableGrim && (System.nanoTime() - getPlayerClockAtLeast()) > 15e9) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package ac.grim.grimac.utils.collisions.blocks.connecting;

import ac.grim.grimac.player.GrimPlayer;
import ac.grim.grimac.utils.collisions.datatypes.*;
import ac.grim.grimac.utils.collisions.datatypes.CollisionBox;
import ac.grim.grimac.utils.collisions.datatypes.ComplexCollisionBox;
import ac.grim.grimac.utils.collisions.datatypes.HexCollisionBox;
import ac.grim.grimac.utils.collisions.datatypes.NoCollisionBox;
import ac.grim.grimac.utils.collisions.datatypes.SimpleCollisionBox;
import ac.grim.grimac.utils.nmsutil.Materials;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
Expand Down Expand Up @@ -76,7 +80,7 @@ public boolean connectsTo(GrimPlayer player, ClientVersion v, int currX, int cur
} else {
if (fence == target) return true;

return checkCanConnect(player, targetBlock, target, fence);
return checkCanConnect(player, targetBlock, target, fence, direction);
}
}

Expand All @@ -85,7 +89,7 @@ boolean isBlacklisted(StateType m, StateType fence, ClientVersion clientVersion)
if (BlockTags.SHULKER_BOXES.contains(m)) return true;
if (BlockTags.TRAPDOORS.contains(m)) return true;

return m == StateTypes.CARVED_PUMPKIN || m == StateTypes.JACK_O_LANTERN || m == StateTypes.PUMPKIN || m == StateTypes.MELON ||
return m == StateTypes.ENCHANTING_TABLE || m == StateTypes.CARVED_PUMPKIN || m == StateTypes.JACK_O_LANTERN || m == StateTypes.PUMPKIN || m == StateTypes.MELON ||
m == StateTypes.BEACON || BlockTags.CAULDRONS.contains(m) || m == StateTypes.GLOWSTONE || m == StateTypes.SEA_LANTERN || m == StateTypes.ICE
|| m == StateTypes.PISTON || m == StateTypes.STICKY_PISTON || m == StateTypes.PISTON_HEAD || (!canConnectToGlassBlock()
&& BlockTags.GLASS_BLOCKS.contains(m));
Expand Down Expand Up @@ -113,7 +117,7 @@ protected int getAABBIndex(boolean north, boolean east, boolean south, boolean w
return i;
}

public boolean checkCanConnect(GrimPlayer player, WrappedBlockState state, StateType one, StateType two) {
public boolean checkCanConnect(GrimPlayer player, WrappedBlockState state, StateType one, StateType two, BlockFace direction) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class DynamicFence extends DynamicConnecting implements CollisionFactory

public static SimpleCollisionBox[] LEGACY_BOUNDING_BOXES = new SimpleCollisionBox[] {new SimpleCollisionBox(0.375D, 0.0D, 0.375D, 0.625D, 1.0D, 0.625D), new SimpleCollisionBox(0.375D, 0.0D, 0.375D, 0.625D, 1.0D, 1.0D), new SimpleCollisionBox(0.0D, 0.0D, 0.375D, 0.625D, 1.0D, 0.625D), new SimpleCollisionBox(0.0D, 0.0D, 0.375D, 0.625D, 1.0D, 1.0D), new SimpleCollisionBox(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 0.625D), new SimpleCollisionBox(0.375D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D), new SimpleCollisionBox(0.0D, 0.0D, 0.0D, 0.625D, 1.0D, 0.625D), new SimpleCollisionBox(0.0D, 0.0D, 0.0D, 0.625D, 1.0D, 1.0D), new SimpleCollisionBox(0.375D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D), new SimpleCollisionBox(0.375D, 0.0D, 0.375D, 1.0D, 1.0D, 1.0D), new SimpleCollisionBox(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 0.625D), new SimpleCollisionBox(0.0D, 0.0D, 0.375D, 1.0D, 1.0D, 1.0D), new SimpleCollisionBox(0.375D, 0.0D, 0.0D, 1.0D, 1.0D, 0.625D), new SimpleCollisionBox(0.375D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D), new SimpleCollisionBox(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.625D), new SimpleCollisionBox(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D)};


@Override
public CollisionBox fetch(GrimPlayer player, ClientVersion version, WrappedBlockState block, int x, int y, int z) {
boolean east;
Expand All @@ -49,10 +48,10 @@ public CollisionBox fetch(GrimPlayer player, ClientVersion version, WrappedBlock
}

@Override
public boolean checkCanConnect(GrimPlayer player, WrappedBlockState state, StateType one, StateType two) {
public boolean checkCanConnect(GrimPlayer player, WrappedBlockState state, StateType one, StateType two, BlockFace direction) {
if (BlockTags.FENCES.contains(one))
return !(one == StateTypes.NETHER_BRICK_FENCE) && !(two == StateTypes.NETHER_BRICK_FENCE);
else
return BlockTags.FENCES.contains(one) || CollisionData.getData(one).getMovementCollisionBox(player, player.getClientVersion(), state, 0, 0, 0).isFullBlock();
return BlockTags.FENCES.contains(one) || CollisionData.getData(one).getMovementCollisionBox(player, player.getClientVersion(), state, 0, 0, 0).isSideFullBlock(direction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,11 @@ public boolean canConnectToGlassBlock() {
return true;
}


@Override
public boolean checkCanConnect(GrimPlayer player, WrappedBlockState state, StateType one, StateType two) {
public boolean checkCanConnect(GrimPlayer player, WrappedBlockState state, StateType one, StateType two, BlockFace direction) {
if (BlockTags.GLASS_PANES.contains(one) || one == StateTypes.IRON_BARS)
return true;
else
return CollisionData.getData(one).getMovementCollisionBox(player, player.getClientVersion(), state, 0, 0, 0).isFullBlock();
return CollisionData.getData(one).getMovementCollisionBox(player, player.getClientVersion(), state, 0, 0, 0).isSideFullBlock(direction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.github.retrooper.packetevents.protocol.world.states.enums.South;
import com.github.retrooper.packetevents.protocol.world.states.enums.West;
import com.github.retrooper.packetevents.protocol.world.states.type.StateType;
import com.github.retrooper.packetevents.protocol.world.states.type.StateTypes;

public class DynamicWall extends DynamicConnecting implements CollisionFactory {
public static final CollisionBox[] BOXES = makeShapes(4.0F, 3.0F, 16.0F, 0.0F, 16.0F, false);
Expand Down Expand Up @@ -181,7 +182,7 @@ public CollisionBox fetch(GrimPlayer player, ClientVersion version, WrappedBlock
}

@Override
public boolean checkCanConnect(GrimPlayer player, WrappedBlockState state, StateType one, StateType two) {
return BlockTags.WALLS.contains(one) || CollisionData.getData(one).getMovementCollisionBox(player, player.getClientVersion(), state, 0, 0, 0).isFullBlock();
public boolean checkCanConnect(GrimPlayer player, WrappedBlockState state, StateType one, StateType two, BlockFace direction) {
return BlockTags.WALLS.contains(one) || CollisionData.getData(one).getMovementCollisionBox(player, player.getClientVersion(), state, 0, 0, 0).isSideFullBlock(direction);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ac.grim.grimac.utils.collisions.datatypes;

import com.github.retrooper.packetevents.protocol.world.BlockFace;

import java.util.List;

public interface CollisionBox {
Expand All @@ -16,4 +18,8 @@ public interface CollisionBox {
boolean isNull();

boolean isFullBlock();

default boolean isSideFullBlock(BlockFace axis) {
return isFullBlock();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ac.grim.grimac.utils.collisions.datatypes;

import ac.grim.grimac.utils.nmsutil.Ray;
import com.github.retrooper.packetevents.protocol.world.BlockFace;
import com.github.retrooper.packetevents.util.Vector3d;
import com.github.retrooper.packetevents.util.Vector3i;
import org.bukkit.Location;
Expand Down Expand Up @@ -240,6 +241,29 @@ public boolean isFullBlock() {
return isFullBlock;
}

@Override
public boolean isSideFullBlock(BlockFace axis) {
if (isFullBlock) {
return true;
}

// Get the direction of block we are trying to connect to -> towards the block that is trying to connect
final BlockFace faceToSourceConnector = axis.getOppositeFace();
switch (faceToSourceConnector) {
case EAST:
case WEST:
return this.minX == 0 && this.maxX == 1;
case UP:
case DOWN:
return this.minY == 0 && this.maxY == 1;
case NORTH:
case SOUTH:
return this.minZ == 0 && this.maxZ == 1;
}

return false;
}

public boolean isFullBlockNoCache() {
return minX == 0 && minY == 0 && minZ == 0 && maxX == 1 && maxY == 1 && maxZ == 1;
}
Expand Down

0 comments on commit ab48248

Please sign in to comment.