Skip to content

Commit

Permalink
Merge branch 'GrimAnticheat:2.0' into merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Axionize authored Oct 8, 2024
2 parents be56e28 + 3cab3fe commit c26afbc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ac.grim.grimac.checks.CheckData;
import ac.grim.grimac.checks.type.PacketCheck;
import ac.grim.grimac.player.GrimPlayer;
import ac.grim.grimac.utils.anticheat.MessageUtil;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
Expand Down Expand Up @@ -39,10 +40,6 @@ private boolean shouldExempt(final Vector3i pos) {
return player.getClientVersion().isOlderThan(ClientVersion.V_1_14_4) || getBlockDamage(player, pos) < 1;
}

private String formatted(Vector3i vec) {
return vec == null ? "null" : vec.x + ", " + vec.y + ", " + vec.z;
}

public void handle(PacketReceiveEvent event, WrapperPlayClientPlayerDigging dig) {
if (dig.getAction() == DiggingAction.START_DIGGING) {
final Vector3i pos = dig.getBlockPosition();
Expand All @@ -57,7 +54,7 @@ public void handle(PacketReceiveEvent event, WrapperPlayClientPlayerDigging dig)
final Vector3i pos = dig.getBlockPosition();

if (shouldExempt(pos)) {
lastCancelledBlock = null;
lastCancelledBlock = pos;
lastLastBlock = null;
lastBlock = null;
return;
Expand All @@ -66,7 +63,7 @@ public void handle(PacketReceiveEvent event, WrapperPlayClientPlayerDigging dig)
if (!pos.equals(lastBlock)) {
// https://github.com/GrimAnticheat/Grim/issues/1512
if (player.getClientVersion().isOlderThan(ClientVersion.V_1_14_4) || (!lastBlockWasInstantBreak && pos.equals(lastCancelledBlock))) {
if (flagAndAlert("action=CANCELLED_DIGGING" + ", last=" + formatted(lastBlock) + ", pos=" + formatted(pos))) {
if (flagAndAlert("action=CANCELLED_DIGGING" + ", last=" + MessageUtil.toUnlabledString(lastBlock) + ", pos=" + MessageUtil.toUnlabledString(pos))) {
if (shouldModifyPackets()) {
event.setCancelled(true);
player.onPacketCancel();
Expand All @@ -87,7 +84,7 @@ public void handle(PacketReceiveEvent event, WrapperPlayClientPlayerDigging dig)

// when a player looks away from the mined block, they send a cancel, and if they look at it again, they don't send another start. (thanks mojang!)
if (!pos.equals(lastCancelledBlock) && (!lastBlockWasInstantBreak || player.getClientVersion().isOlderThan(ClientVersion.V_1_14_4)) && !pos.equals(lastBlock)) {
if (flagAndAlert("action=FINISHED_DIGGING" + ", last=" + formatted(lastBlock) + ", pos=" + formatted(pos))) {
if (flagAndAlert("action=FINISHED_DIGGING" + ", last=" + MessageUtil.toUnlabledString(lastBlock) + ", pos=" + MessageUtil.toUnlabledString(pos))) {
if (shouldModifyPackets()) {
event.setCancelled(true);
player.onPacketCancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void onPacketReceive(PacketReceiveEvent event) {

@Override
public void onPredictionComplete(PredictionComplete predictionComplete) {
if (player.getClientVersion().isNewerThan(ClientVersion.V_1_8) && !player.skippedTickInActualMovement) {
if (player.getClientVersion().isNewerThan(ClientVersion.V_1_8) && !player.skippedTickInActualMovement && predictionComplete.isChecked()) {
for (String verbose : flags) {
flagAndAlert(verbose);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,29 @@ public void recalculate() {
}

public double with(WrapperPlayServerUpdateAttributes.Property property) {
double d0 = property.getValue();
double baseValue = property.getValue();
double additionSum = 0;
double multiplyBaseSum = 0;
double multiplyTotalProduct = 1.0;

List<WrapperPlayServerUpdateAttributes.PropertyModifier> modifiers = property.getModifiers();
modifiers.removeIf(modifier -> modifier.getUUID().equals(SPRINTING_MODIFIER_UUID) || modifier.getName().getKey().equals("sprinting"));

for (WrapperPlayServerUpdateAttributes.PropertyModifier attributemodifier : modifiers) {
if (attributemodifier.getOperation() == WrapperPlayServerUpdateAttributes.PropertyModifier.Operation.ADDITION)
d0 += attributemodifier.getAmount();
}

double d1 = d0;

for (WrapperPlayServerUpdateAttributes.PropertyModifier attributemodifier : modifiers) {
if (attributemodifier.getOperation() == WrapperPlayServerUpdateAttributes.PropertyModifier.Operation.MULTIPLY_BASE)
d1 += d0 * attributemodifier.getAmount();
}

for (WrapperPlayServerUpdateAttributes.PropertyModifier attributemodifier : modifiers) {
if (attributemodifier.getOperation() == WrapperPlayServerUpdateAttributes.PropertyModifier.Operation.MULTIPLY_TOTAL)
d1 *= 1.0D + attributemodifier.getAmount();
for (WrapperPlayServerUpdateAttributes.PropertyModifier modifier : modifiers) {
switch (modifier.getOperation()) {
case ADDITION:
additionSum += modifier.getAmount();
break;
case MULTIPLY_BASE:
multiplyBaseSum += modifier.getAmount();
break;
case MULTIPLY_TOTAL:
multiplyTotalProduct *= (1.0 + modifier.getAmount());
break;
}
}

double newValue = GrimMath.clamp(d1, min, max);
double newValue = GrimMath.clamp((baseValue + additionSum) * (1 + multiplyBaseSum) * multiplyTotalProduct, min, max);
if (setRewriter != null) {
newValue = setRewriter.apply(this.value, newValue);
}
Expand Down

0 comments on commit c26afbc

Please sign in to comment.