Skip to content

Commit

Permalink
反作弊错误修复
Browse files Browse the repository at this point in the history
- 修复NoSlowA, SpeedA在速度buff下的误判。
- 同步cheat detector更新。
  • Loading branch information
xia-mc committed Apr 5, 2024
1 parent 1f4a446 commit cd72e7c
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/main/java/top/infsky/timerecorder/anticheat/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<ServerGamePacketListener> packet, CallbackInfo ci) {}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public CheckManager(List<Check> 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;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/top/infsky/timerecorder/anticheat/TRPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ServerGamePacketListener> 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);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Float, Float> 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);
}
}

0 comments on commit cd72e7c

Please sign in to comment.