Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ManInMyVan committed Jan 20, 2025
1 parent 856ec6c commit dcf0c73
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 32 deletions.
12 changes: 12 additions & 0 deletions src/main/java/ac/grim/grimac/checks/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ public final boolean flagWithSetback() {
return false;
}

public final boolean flagAndAlertWithSetback() {
return flagAndAlertWithSetback("");
}

public final boolean flagAndAlertWithSetback(String verbose) {
if (flagAndAlert(verbose)) {
setbackIfAboveSetbackVL();
return true;
}
return false;
}

public final void reward() {
violations = Math.max(0, violations - decay);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ public void onPredictionComplete(final PredictionComplete predictionComplete) {

if (player.isTickingReliablyFor(3)) {
for (; flags > 0; flags--) {
if (flagAndAlert()) {
setbackIfAboveSetbackVL();
}
flagAndAlertWithSetback();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void onPacketReceive(PacketReceiveEvent event) {
if (wrapper.isOnGround() && !hasPosition) {
if (!isNearGround(wrapper.isOnGround())) { // If player isn't near ground
// 1.8 boats have a mind on their own... only flag if they're not near a boat or are on 1.9+
if (!GhostBlockDetector.isGhostBlock(player) && flagWithSetback()) alert("");
if (!GhostBlockDetector.isGhostBlock(player)) flagAndAlertWithSetback();
if (shouldModifyPackets()) {
wrapper.setOnGround(false);
event.markForReEncode(true);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ac/grim/grimac/checks/impl/movement/NoSlow.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public void onPredictionComplete(final PredictionComplete predictionComplete) {
}

if (bestOffset > offsetToFlag) {
if (flaggedLastTick && flagWithSetback()) {
alert("");
if (flaggedLastTick) {
flagAndAlertWithSetback();
}
flaggedLastTick = true;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ public void onPredictionComplete(final PredictionComplete predictionComplete) {
if (player.packetStateData.lastPacketWasTeleport) return;

if (player.clientClaimsLastOnGround != player.onGround) {
if (flagAndAlert("claimed " + player.clientClaimsLastOnGround)) {
setbackIfAboveSetbackVL();
}
flagAndAlertWithSetback("claimed " + player.clientClaimsLastOnGround);
player.checkManager.getNoFall().flipPlayerGroundStatus = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public void onPredictionComplete(final PredictionComplete predictionComplete) {
continue; // 1.8 glitchy block, ignore
}
}
if (flagWithSetback())
alert("");
flagAndAlertWithSetback();
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public DuplicateRotPlace(GrimPlayer player) {
}

private float deltaX, deltaY;

private float lastPlacedDeltaX;
private double lastPlacedDeltaDotsX;
private double deltaDotsX;
private boolean rotated = false;

Expand All @@ -26,9 +27,7 @@ public void process(final RotationUpdate rotationUpdate) {
rotated = true;
}

private float lastPlacedDeltaX;
private double lastPlacedDeltaDotsX;

@Override
public void onPostFlyingBlockPlace(BlockPlace place) {
if (rotated) {
if (deltaX > 2) {
Expand All @@ -48,6 +47,4 @@ public void onPostFlyingBlockPlace(BlockPlace place) {
rotated = false;
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void onPredictionComplete(final PredictionComplete predictionComplete) {
}

if (player.isSprinting && !player.isSwimming && (player.fluidOnEyes != FluidTag.WATER || version.isOlderThan(ClientVersion.V_1_21_4))) {
if (flagWithSetback()) alert("");
flagAndAlertWithSetback();
} else reward();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void onPredictionComplete(final PredictionComplete predictionComplete) {
}

if (player.isSprinting && (!player.isSwimming || client.isOlderThan(ClientVersion.V_1_21_4))) {
if (flaggedLastTick && flagWithSetback()) alert("");
if (flaggedLastTick) flagAndAlertWithSetback();
flaggedLastTick = true;
} else {
reward();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void onPredictionComplete(final PredictionComplete predictionComplete) {

if (player.compensatedEntities.getSelf().hasPotionEffect(BLINDNESS)) {
if (player.isSprinting && !startedSprintingBeforeBlind) {
if (flagWithSetback()) alert("");
flagAndAlertWithSetback();
} else reward();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void onPredictionComplete(final PredictionComplete predictionComplete) {

if (wasHorizontalCollision && !startedSprintingThisTick) {
if (player.isSprinting) {
if (flagAndAlert()) setbackIfAboveSetbackVL();
flagAndAlertWithSetback();
} else reward();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public SprintF(GrimPlayer player) {
public void onPredictionComplete(final PredictionComplete predictionComplete) {
if (player.wasGliding && player.isGliding && player.getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_21_4)) {
if (player.isSprinting) {
if (flagAndAlert()) setbackIfAboveSetbackVL();
flagAndAlertWithSetback();
} else {
reward();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void onPredictionComplete(final PredictionComplete predictionComplete) {

if (timerBalanceRealTime < lastMovementPlayerClock - clockDrift) {
int lostMS = (int) ((System.nanoTime() - timerBalanceRealTime) / 1e6);
if (flagAndAlert("-" + lostMS)) setbackIfAboveSetbackVL();
flagAndAlertWithSetback("-" + lostMS);
timerBalanceRealTime += 50e6;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/ac/grim/grimac/checks/impl/timer/TickTimer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,21 @@ public TickTimer(GrimPlayer player) {
public void onPacketReceive(PacketReceiveEvent event) {
if (!player.supportsEndTick()) return;
if (isFlying(event.getPacketType()) && !player.packetStateData.lastPacketWasTeleport) {
if (!receivedTickEnd && flagAndAlert("type=flying, packets=" + flyingPackets)) {
if (!receivedTickEnd && flagAndAlertWithSetback("type=flying, packets=" + flyingPackets)) {
handleViolation();
}
receivedTickEnd = false;
flyingPackets++;
} else if (event.getPacketType() == PacketType.Play.Client.CLIENT_TICK_END) {
receivedTickEnd = true;
if (flyingPackets > 1 && flagAndAlert("type=end, packets=" + flyingPackets)) {
if (flyingPackets > 1 && flagAndAlertWithSetback("type=end, packets=" + flyingPackets)) {
handleViolation();
}
flyingPackets = 0;
}
}

private void handleViolation() {
setbackIfAboveSetbackVL();
// Although we don't cancel the packet, this should be counted as an invalid packet.
player.onPacketCancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,7 @@ public void onPredictionComplete(final PredictionComplete predictionComplete) {
// 100% known kb was taken
if (player.likelyExplosions != null && !player.compensatedEntities.getSelf().isDead) {
if (player.likelyExplosions.offset > offsetToFlag) {
if (flagAndAlert(player.likelyExplosions.offset == Integer.MAX_VALUE ? "ignored explosion" : "o: " + formatOffset(offset))) {
setbackIfAboveSetbackVL();
}
flagAndAlertWithSetback(player.likelyExplosions.offset == Integer.MAX_VALUE ? "ignored explosion" : "o: " + formatOffset(offset));
} else {
reward();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ public void onPredictionComplete(final PredictionComplete predictionComplete) {
} else if (flagAndAlert(player.likelyKB.offset == Integer.MAX_VALUE ? "ignored knockback"
: "o: " + formatOffset(player.likelyKB.offset))) { // This velocity was sent by the server.
if (player.likelyKB.offset >= immediate || threshold >= maxAdv) {
if (!isNoSetbackPermission()) {
player.getSetbackTeleportUtil().executeViolationSetback();
}
setbackIfAboveSetbackVL();
}
} else {
reward();
Expand Down

0 comments on commit dcf0c73

Please sign in to comment.