Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync update #13

Merged
merged 4 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
## 反作弊
反作弊 旨在不被发现的情况下揭示其他玩家的作弊行为。
- **Fly** 飞行检查
- **BoatFly** 船飞检查
- **HighJump** 高跳检查
- **Blink** 闪现检查
- **NoSlow** 无减速检查
Expand All @@ -32,6 +33,9 @@
- **GameMode** 游戏模式检查
- **Velocity** 反击退检查
- **GroundSpoof** 假地面检查
- **AutoClicker** 连点器检查
- **Reach** 距离检查
- **HitBox** 命中框检查

## 修复
修复 旨在避免被生电服务器反作弊错误标记。
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ minecraft_version=1.20.1
loader_version=0.14.23

# Mod Properties
mod_version = 2.10.1
mod_version = 2.10.2
maven_group = top.infsky
archives_base_name = CheatDetector

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static void register(@NotNull CommandDispatcher<FabricClientCommandSource
.then(argument("name", StringArgumentType.string())
.executes(CatchCommand::execute))
)
.then(literal("debug")
.then(argument("name", StringArgumentType.string())
.executes(DebugCommand::execute))
)
);
}
}
29 changes: 29 additions & 0 deletions src/main/java/top/infsky/cheatdetector/commands/DebugCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package top.infsky.cheatdetector.commands;

import com.mojang.brigadier.context.CommandContext;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.network.chat.Component;
import org.jetbrains.annotations.NotNull;
import top.infsky.cheatdetector.CheatDetector;
import top.infsky.cheatdetector.impl.utils.ListUtils;

import java.util.NoSuchElementException;

public class DebugCommand {
public static int execute(@NotNull CommandContext<FabricClientCommandSource> context) {
String name = context.getArgument("name", String.class);

try {
context.getSource().sendFeedback(Component.literal(ListUtils.getSpilt(
CheatDetector.manager.getDataMap().values()
.stream()
.filter(trPlayer -> trPlayer.fabricPlayer.getName().getString().endsWith(name))
.findAny()
.orElseThrow()
.motionHistory)));
return 1;
} catch (NoSuchElementException e) {
return 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class HelpCommand {
§r/ctr notebot <path> §f- §7修改音符机器人.nbs文件路径§r
§r/ctr clientspoof <brand> §f- §7设置客户端伪装名§r
§r/ctr writer <part> §f- §7写一本书。§r
§r/ctr catch <name> §f- §7设置自动骑上一名玩家。§r
""";

public static int execute(@NotNull CommandContext<FabricClientCommandSource> context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ public class AdvancedConfig {
@Config(category = ConfigCategory.ADVANCED)
public static int boatFlyAAlertBuffer = 20;

@Config(category = ConfigCategory.ADVANCED)
public static boolean strafeACheck = true;
@Config(category = ConfigCategory.ADVANCED)
public static int strafeAAlertBuffer = 20;
@Config(category = ConfigCategory.ADVANCED)
public static double strafeAMaxDiffToFlag = 0.005;

public static short getNoSlowAInJumpDisableTick() {
return (short) noSlowAInJumpDisableTick;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public boolean _onPacketReceive(@NotNull Packet<ClientGamePacketListener> basePa
if (packet.getId() != player.fabricPlayer.getId()) return false;
if (packet.getAction() != ClientboundAnimatePacket.SWING_MAIN_HAND) return false;

if (player.fabricPlayer.pick(4.5, 0, false).getType() != HitResult.Type.MISS) return false; // 1.7/Visual 1.7允许玩家对着方块一边挥手一边使用
if (player.fabricPlayer.pick(3, 0, false).getType() != HitResult.Type.MISS) return false; // 1.7/Visual 1.7允许玩家对着方块一边挥手一边使用

if (player.fabricPlayer.getMainHandItem().getItem() instanceof SwordItem && player.fabricPlayer.getOffhandItem().is(Items.SHIELD)) // viaVersion一般会把其他玩家显示为持有盾牌,而不是格挡
if (player.fabricPlayer.getMainHandItem().getItem() instanceof SwordItem && (player.fabricPlayer.isUsingItem() || player.fabricPlayer.getOffhandItem().is(Items.SHIELD))) // viaVersion一般会把其他玩家显示为持有盾牌,而不是格挡
flag("impossible hit.");
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public FlyA(@NotNull TRPlayer player) {

@Override
public void _onTick() {
if (player.fabricPlayer.isPassenger() || !PlayerMove.isMove(player.currentMotion) || (player.currentOnGround && player.fabricPlayer.isFallFlying())) return;
if (PlayerMove.isInvalidMotion(player.currentMotion)) return;
if (player.fabricPlayer.isPassenger() || PlayerMove.isNoMove(player.currentMotion) || (player.currentOnGround && player.fabricPlayer.isFallFlying())) return;

if (player.lastMotion.y() == 0 && player.currentMotion.y() == 0) {
flag("Invalid Y-motion: %.2f onGround=%s".formatted(player.currentMotion.y() , player.currentOnGround));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.jetbrains.annotations.NotNull;
import top.infsky.cheatdetector.config.AdvancedConfig;
import top.infsky.cheatdetector.impl.Check;
import top.infsky.cheatdetector.impl.utils.world.PlayerMove;
import top.infsky.cheatdetector.utils.TRPlayer;

import java.util.List;
Expand All @@ -20,19 +21,22 @@ public FlyC(@NotNull TRPlayer player) {
public void _onTick() {
if (player.fabricPlayer.isPassenger()
|| player.currentOnGround || player.fabricPlayer.isFallFlying()
// || player.fabricPlayer.hurtTime > 0
|| IGNORED_BLOCKS.stream().anyMatch(block -> player.fabricPlayer.getFeetBlockState().is(block))) return;

if (PlayerMove.isInvalidMotion(player.currentMotion)) return;


List<Vec3> posDiff = PlayerMove.getPosHistoryDiff(player.posHistory);
int repeatFromTick = 0;
for (Vec3 motion : player.motionHistory) {
if (motion.y() != player.currentMotion.y()) {
return;
for (Vec3 diff : posDiff) {
if (diff.y() == posDiff.get(0).y()) {
repeatFromTick++;
}

repeatFromTick++;
}

if (repeatFromTick >= AdvancedConfig.flyCMinRepeatTicks) {
flag("Repeat Y-motion from %s ticks: %.2f".formatted(repeatFromTick, player.currentMotion.y()));
flag("Repeat Y-diff from %s ticks: %.2f".formatted(repeatFromTick, posDiff.get(0).y()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void _onTick() {
final BlockPos groundPos = player.fabricPlayer.blockPosition().below();

if (check(level, groundPos)) {
flag();
flag("spoof onGround=true");
setback();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ public void _onTick() {
if (level == null) return;

if (!player.currentOnGround && Math.floor(player.currentPos.y()) == player.currentPos.y()) { // check if it's *OnGround*
final BlockPos groundPos = player.fabricPlayer.blockPosition().below();

if (check(level, groundPos)) {
flag();
if (check(level, player.fabricPlayer.getOnPos())) {
flag("spoof onGround=false");
setback();
}
}
Expand All @@ -36,7 +34,7 @@ public void setback() {
}

public static boolean check(@NotNull Level level, @NotNull BlockPos groundPos) {
if (!BlockUtils.isFullBlock(level.getBlockState(groundPos)) || !BlockUtils.isFullBlock(level.getBlockState(groundPos.above())))
if (!BlockUtils.isFullBlock(level.getBlockState(groundPos)))
return false;

short count = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import top.infsky.cheatdetector.config.AdvancedConfig;
import top.infsky.cheatdetector.impl.Check;
import top.infsky.cheatdetector.impl.utils.world.BlockUtils;
import top.infsky.cheatdetector.impl.utils.world.PlayerMove;
import top.infsky.cheatdetector.utils.TRPlayer;

import java.util.List;
Expand Down Expand Up @@ -65,6 +66,8 @@ public void _onTick() {
}

private boolean check() {
if (PlayerMove.isInvalidMotion(player.currentMotion)) return false;

if (player.fabricPlayer.isFallFlying()) {
disableTicks = (int) Math.ceil(player.latency / 50.0) + 3;
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package top.infsky.cheatdetector.impl.checks.movement;

import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import top.infsky.cheatdetector.config.AdvancedConfig;
import top.infsky.cheatdetector.impl.Check;
import top.infsky.cheatdetector.impl.utils.world.PlayerMove;
import top.infsky.cheatdetector.utils.TRPlayer;

public class StrafeA extends Check {
private Vec3 futureMotion = null;

public StrafeA(@NotNull TRPlayer player) {
super("StrafeA", player);
}

@Override
public void _onTick() {
if (player.currentOnGround || PlayerMove.isNoMove(player.currentMotion) || player.lastRot.equals(player.currentRot)) {
futureMotion = null;
return;
}

if (PlayerMove.isInvalidMotion(player.currentMotion)) return;

if (futureMotion != null) {
double diff = PlayerMove.getMaxXZDiff(player.currentMotion, futureMotion);
if (diff <= AdvancedConfig.strafeAMaxDiffToFlag) {
flag("Strafe in air. diff:%.4f".formatted(diff));
}
}

futureMotion = PlayerMove.getStrafeMotion(
PlayerMove.speed(player.fabricPlayer),
PlayerMove.direction(1, 0, player.fabricPlayer.yRotO + (player.fabricPlayer.getYRot() - player.fabricPlayer.yRotO) * 50),
player.currentMotion.y()
);
}



@Override
public int getAlertBuffer() {
return AdvancedConfig.strafeAAlertBuffer;
}

@Override
public boolean isDisabled() {
return !AdvancedConfig.strafeACheck;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public AntiBot(@NotNull TRSelf player) {
public void _onTick() {
if (isDisabled()) {
botList.clear();
disableCheck = false;
}

if (!Advanced3Config.antiBotLatency)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import top.infsky.cheatdetector.utils.TRPlayer;
import top.infsky.cheatdetector.utils.TRSelf;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class PlayerMove {
Expand All @@ -26,11 +28,6 @@ public static double getXzSecSpeed(@NotNull Vec3 lastTick, @NotNull Vec3 current
return new Vec3(position.x(), 0, position.z());
}

@Contract("_ -> new")
public static @NotNull Vec3 getYOnlyPos(@NotNull Vec3 position) {
return new Vec3(0, position.y(), 0);
}

public static double getJumpDistance(@NotNull AbstractClientPlayer player) {
try {
final int x = Objects.requireNonNull(player.getActiveEffectsMap().get(MobEffects.JUMP)).getAmplifier() + 1;
Expand All @@ -48,8 +45,8 @@ public static boolean isMove() {
|| TRPlayer.CLIENT.options.keyRight.isDown();
}

public static boolean isMove(@NotNull Vec3 motion) {
return motion.x() != 0 || motion.z() != 0;
public static boolean isNoMove(@NotNull Vec3 motion) {
return motion.x() == 0 && motion.z() == 0;
}

/**
Expand Down Expand Up @@ -99,21 +96,24 @@ public static void strafe(final double speed) {
}

TRSelf trSelf = TRSelf.getInstance();
final double yaw = direction();
final double yaw = direction(
trSelf.fabricPlayer.input.forwardImpulse,
trSelf.fabricPlayer.input.leftImpulse,
trSelf.fabricPlayer.yRotO + (trSelf.fabricPlayer.getYRot() - trSelf.fabricPlayer.yRotO) * TRPlayer.CLIENT.getFrameTime()
);

trSelf.fabricPlayer.setDeltaMovement(getStrafeMotion(speed, yaw, trSelf.fabricPlayer.getDeltaMovement().y()));
}

trSelf.fabricPlayer.setDeltaMovement(-Mth.sin((float) yaw) * speed, trSelf.fabricPlayer.getDeltaMovement().y(), Mth.cos((float) yaw) * speed);
@Contract("_, _, _ -> new")
public static @NotNull Vec3 getStrafeMotion(final double speed, final double yaw, final double motionY) {
return new Vec3(-Mth.sin((float) yaw) * speed, motionY, Mth.cos((float) yaw) * speed);
}

/**
* Gets the players' movement yaw
*/
public static double direction() {
TRSelf trSelf = TRSelf.getInstance();

float moveForward = trSelf.fabricPlayer.input.forwardImpulse;
float moveStrafing = trSelf.fabricPlayer.input.leftImpulse;
float rotationYaw = trSelf.fabricPlayer.yRotO + (trSelf.fabricPlayer.getYRot() - trSelf.fabricPlayer.yRotO) * TRPlayer.CLIENT.getFrameTime();

public static double direction(float moveForward, float moveStrafing, float rotationYaw) {
if (moveForward < 0) {
rotationYaw += 180;
}
Expand All @@ -136,4 +136,24 @@ public static double direction() {

return Math.toRadians(rotationYaw);
}

public static boolean isInvalidMotion(@NotNull Vec3 motion) {
return Math.abs(motion.x()) >= 3.9
|| Math.abs(motion.y()) >= 3.9
|| Math.abs(motion.z()) >= 3.9;
}

public static double getMaxXZDiff(@NotNull Vec3 motion1, @NotNull Vec3 motion2) {
return Math.max(Math.abs(motion1.x() - motion2.x()), Math.abs(motion1.z() - motion2.z()));
}

public static @NotNull List<Vec3> getPosHistoryDiff(final @NotNull List<Vec3> posHistory) {
List<Vec3> result = new ArrayList<>(posHistory.size() - 1);

for (int i = 0; i < posHistory.size() - 1; i++) {
result.add(posHistory.get(i + 1).subtract(posHistory.get(i)));
}

return result;
}
}
10 changes: 0 additions & 10 deletions src/main/java/top/infsky/cheatdetector/mixins/MixinKeyMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import top.infsky.cheatdetector.CheatDetector;
import top.infsky.cheatdetector.impl.modules.danger.AirStuck;
import top.infsky.cheatdetector.impl.modules.danger.Fly;
import top.infsky.cheatdetector.impl.modules.pas.Speed;
import top.infsky.cheatdetector.impl.utils.world.PlayerMove;
Expand All @@ -28,15 +27,6 @@ public void isDown(@NotNull CallbackInfoReturnable<Boolean> ci) {

if (ci.isCancelled()) return;

AirStuck airStuck = (AirStuck) (AirStuck.getInstance());
if (airStuck != null) {
if (airStuck.isShouldStuck()) {
ci.cancel();
}
}

if (ci.isCancelled()) return;

Fly fly = (Fly) (Fly.getInstance());
if (fly != null) {
if (fly.isNoJump() && PlayerMove.isMove()) {
Expand Down
Loading
Loading