From cd72e7cee309430bf1142aefb25248d44b0ad611 Mon Sep 17 00:00:00 2001 From: xia-mc <2052472631@qq.com> Date: Fri, 5 Apr 2024 23:23:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=8D=E4=BD=9C=E5=BC=8A=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复NoSlowA, SpeedA在速度buff下的误判。 - 同步cheat detector更新。 --- .../infsky/timerecorder/anticheat/Check.java | 4 +-- .../timerecorder/anticheat/CheckManager.java | 3 +- .../timerecorder/anticheat/TRPlayer.java | 5 +++ .../timerecorder/anticheat/checks/BlinkA.java | 3 +- .../anticheat/checks/FlightA.java | 1 + .../anticheat/checks/NoSlowA.java | 4 +-- .../anticheat/checks/ScaffoldA.java | 34 +++++++++++++++++++ .../timerecorder/anticheat/checks/SpeedA.java | 2 +- .../anticheat/utils/PlayerRotation.java | 22 ++++++++++++ 9 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 src/main/java/top/infsky/timerecorder/anticheat/checks/ScaffoldA.java create mode 100644 src/main/java/top/infsky/timerecorder/anticheat/utils/PlayerRotation.java diff --git a/src/main/java/top/infsky/timerecorder/anticheat/Check.java b/src/main/java/top/infsky/timerecorder/anticheat/Check.java index beb2d82..fbd4882 100644 --- a/src/main/java/top/infsky/timerecorder/anticheat/Check.java +++ b/src/main/java/top/infsky/timerecorder/anticheat/Check.java @@ -52,18 +52,18 @@ public final void setback(@NotNull CallbackInfo ci) { } public final void badPacket() { + if (!CONFIG().isAllowSetback()) return; if (setbackFoodLevel == null) setbackFoodLevel = player.fabricPlayer.getFoodData().getFoodLevel(); player.fabricPlayer.getFoodData().setFoodLevel(0); player.timeTask.addTask(() -> { player.fabricPlayer.getFoodData().setFoodLevel(setbackFoodLevel); setbackFoodLevel = null; - }); + }, 1); } public void _onTick() {} public void _onTeleport() {} public void _onJump() {} public void _onPacketReceive(Packet packet, CallbackInfo ci) {} - } diff --git a/src/main/java/top/infsky/timerecorder/anticheat/CheckManager.java b/src/main/java/top/infsky/timerecorder/anticheat/CheckManager.java index 2b8fa02..2ba0c50 100644 --- a/src/main/java/top/infsky/timerecorder/anticheat/CheckManager.java +++ b/src/main/java/top/infsky/timerecorder/anticheat/CheckManager.java @@ -30,7 +30,8 @@ public CheckManager(List checks, TRPlayer player) { new SpeedA(player), new SpeedB(player), new HighJumpA(player), - new NoSlowA(player) + new NoSlowA(player), + new ScaffoldA(player) ), player); checkManager.onTeleport(); return checkManager; diff --git a/src/main/java/top/infsky/timerecorder/anticheat/TRPlayer.java b/src/main/java/top/infsky/timerecorder/anticheat/TRPlayer.java index 08ec09f..ff9edbf 100644 --- a/src/main/java/top/infsky/timerecorder/anticheat/TRPlayer.java +++ b/src/main/java/top/infsky/timerecorder/anticheat/TRPlayer.java @@ -3,6 +3,7 @@ import lombok.Getter; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.effect.MobEffects; import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Range; @@ -36,6 +37,7 @@ public class TRPlayer { public boolean hasSetback = false; public boolean jumping = false; public boolean lastUsingItem = false; + public double speedMul = 1; public TimeTaskManager timeTask = new TimeTaskManager(); @@ -56,6 +58,9 @@ public void update() { if (fabricPlayer == null) return; currentPos = fabricPlayer.position(); + speedMul = fabricPlayer.getActiveEffectsMap().containsKey(MobEffects.MOVEMENT_SPEED) + ? fabricPlayer.getActiveEffectsMap().get(MobEffects.MOVEMENT_SPEED).getAmplifier() * 0.2 + 1 + : 1; updatePoses(); if (fabricPlayer.onGround()) { lastOnGroundPos = currentPos; diff --git a/src/main/java/top/infsky/timerecorder/anticheat/checks/BlinkA.java b/src/main/java/top/infsky/timerecorder/anticheat/checks/BlinkA.java index 5afbb92..844d8b5 100644 --- a/src/main/java/top/infsky/timerecorder/anticheat/checks/BlinkA.java +++ b/src/main/java/top/infsky/timerecorder/anticheat/checks/BlinkA.java @@ -17,9 +17,8 @@ public BlinkA(@NotNull TRPlayer player) { public void _onTick() { if (player.lastPos == null || player.hasSetback) return; - if (player.lastPos.distanceTo(player.currentPos) > (player.fabricPlayer.getSpeed() * 10 + player.fabricPlayer.fallDistance + CONFIG().getThreshold())) { + if (player.lastPos.distanceTo(player.currentPos) > (player.fabricPlayer.getSpeed() * 10 * player.speedMul + player.fabricPlayer.fallDistance + CONFIG().getThreshold())) { flag(); - setback(player.lastPos); } } diff --git a/src/main/java/top/infsky/timerecorder/anticheat/checks/FlightA.java b/src/main/java/top/infsky/timerecorder/anticheat/checks/FlightA.java index 53cfbbc..f4cb2b7 100644 --- a/src/main/java/top/infsky/timerecorder/anticheat/checks/FlightA.java +++ b/src/main/java/top/infsky/timerecorder/anticheat/checks/FlightA.java @@ -52,6 +52,7 @@ public void _onTick() { ) { jumpTick--; } else if ((!player.fabricPlayer.isInWater() || !player.fabricPlayer.isInLava()) && liquidTick > 0 + && player.currentPos.y() - player.lastInLiquidPos.y() < 0.5 + CONFIG().getThreshold() // 瞎写的 // && (lastPos.y() - lastPos2.y() + CONFIG().getThreshold()) > (player.position().y() - lastPos.y()) // 警惕出水弱检测 ) { liquidTick--; diff --git a/src/main/java/top/infsky/timerecorder/anticheat/checks/NoSlowA.java b/src/main/java/top/infsky/timerecorder/anticheat/checks/NoSlowA.java index 7772254..6306f9c 100644 --- a/src/main/java/top/infsky/timerecorder/anticheat/checks/NoSlowA.java +++ b/src/main/java/top/infsky/timerecorder/anticheat/checks/NoSlowA.java @@ -34,10 +34,10 @@ public void _onTick() { final double secSpeed = PlayerMove.getXzSecSpeed(player.lastPos, player.currentPos); - if (secSpeed > SLOW_SPEED.get(itemUseTick) * (1 + player.fabricPlayer.getSpeed()) + CONFIG().getThreshold()) { + if (secSpeed > SLOW_SPEED.get(itemUseTick) * player.speedMul + CONFIG().getThreshold()) { flag(); setback(player.lastPos); - player.fabricPlayer.stopUsingItem(); + if (CONFIG().isAllowSetback()) player.fabricPlayer.stopUsingItem(); badPacket(); } if (itemUseTick < SLOW_SPEED.size() - 1) itemUseTick++; diff --git a/src/main/java/top/infsky/timerecorder/anticheat/checks/ScaffoldA.java b/src/main/java/top/infsky/timerecorder/anticheat/checks/ScaffoldA.java new file mode 100644 index 0000000..0ee2665 --- /dev/null +++ b/src/main/java/top/infsky/timerecorder/anticheat/checks/ScaffoldA.java @@ -0,0 +1,34 @@ +package top.infsky.timerecorder.anticheat.checks; + +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.protocol.game.ServerGamePacketListener; +import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket; +import net.minecraft.world.phys.BlockHitResult; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import top.infsky.timerecorder.anticheat.Check; +import top.infsky.timerecorder.anticheat.TRPlayer; + +public class ScaffoldA extends Check { + public ScaffoldA(TRPlayer player) { + super("ScaffoldA", player); + } + + @Override + public void _onPacketReceive(Packet basePacket, CallbackInfo ci) { + if (basePacket instanceof ServerboundUseItemOnPacket packet) { + final BlockHitResult hitResult = packet.getHitResult(); + + if (hitResult.getBlockPos().getX() == player.fabricPlayer.getBlockX() + && hitResult.getBlockPos().getZ() == player.fabricPlayer.getBlockZ() + && hitResult.getBlockPos().getY() < player.fabricPlayer.getBlockY() + && player.fabricPlayer.onGround() + ) { // is scaffolding + if (Math.abs(player.fabricPlayer.getYHeadRot()) > 60) { + flag(); + setback(player.lastPos); + setback(ci); + } + } + } + } +} diff --git a/src/main/java/top/infsky/timerecorder/anticheat/checks/SpeedA.java b/src/main/java/top/infsky/timerecorder/anticheat/checks/SpeedA.java index 045c951..9a23bbc 100644 --- a/src/main/java/top/infsky/timerecorder/anticheat/checks/SpeedA.java +++ b/src/main/java/top/infsky/timerecorder/anticheat/checks/SpeedA.java @@ -38,7 +38,7 @@ else if (player.fabricPlayer.isSilent()) maxSecSpeed = 4.317; final double speed = PlayerMove.getXzSecSpeed(player.lastPos, player.currentPos); - if (speed > (maxSecSpeed * (1 + player.fabricPlayer.getSpeed()) + CONFIG().getThreshold())) { + if (speed > (maxSecSpeed * player.speedMul + CONFIG().getThreshold())) { flag(String.valueOf(speed)); // setback(player.lastPos); } diff --git a/src/main/java/top/infsky/timerecorder/anticheat/utils/PlayerRotation.java b/src/main/java/top/infsky/timerecorder/anticheat/utils/PlayerRotation.java new file mode 100644 index 0000000..a262af9 --- /dev/null +++ b/src/main/java/top/infsky/timerecorder/anticheat/utils/PlayerRotation.java @@ -0,0 +1,22 @@ +package top.infsky.timerecorder.anticheat.utils; + +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerPlayer; +import org.jetbrains.annotations.NotNull; +import oshi.util.tuples.Pair; + +public class PlayerRotation { + /** + * 无法使用 + */ + @SuppressWarnings("unused") + public static @NotNull Pair getLookAt(@NotNull ServerPlayer player, @NotNull BlockPos blockPos) { + double dx = (blockPos.getX() + 0.5) - player.getX(); + double dy = (blockPos.getY() + 0.5) - (player.getY() + player.getEyeHeight()); + double dz = (blockPos.getZ() + 0.5) - player.getZ(); + double dh = Math.sqrt(dx * dx + dz * dz); + float yaw = (float) Math.toDegrees(Math.atan2(dz, dx)) - 90; + float pitch = (float) -Math.toDegrees(Math.atan2(dy, dh)); + return new Pair<>(yaw, pitch); + } +}