Skip to content

Commit

Permalink
Release 2.9.2
Browse files Browse the repository at this point in the history
- 新模块 AutoCatch 自动骑乘
    - 仅限PAS模式
    - 自动骑到设定的玩家身上
- 修复静默瞄准系统的一个bug
- 改进AntiBot
  • Loading branch information
xia-mc committed May 23, 2024
1 parent 5a0c508 commit 3cfa8ae
Show file tree
Hide file tree
Showing 27 changed files with 256 additions and 60 deletions.
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.9.1
mod_version = 2.9.2
maven_group = top.infsky
archives_base_name = CheatDetector

Expand Down
34 changes: 34 additions & 0 deletions src/main/java/top/infsky/cheatdetector/commands/CatchCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package top.infsky.cheatdetector.commands;

import com.mojang.brigadier.context.CommandContext;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.ChatFormatting;
import net.minecraft.world.entity.player.Player;
import org.jetbrains.annotations.NotNull;
import top.infsky.cheatdetector.CheatDetector;
import top.infsky.cheatdetector.config.Advanced3Config;
import top.infsky.cheatdetector.utils.LogUtils;
import top.infsky.cheatdetector.utils.TRPlayer;

public class CatchCommand {
public static int execute(@NotNull CommandContext<FabricClientCommandSource> context) {
String name;

try {
name = context.getArgument("name", String.class);
} catch (IllegalArgumentException e) {
if (TRPlayer.CLIENT.crosshairPickEntity instanceof Player target) {
name = target.getName().getString();
} else {
name = Advanced3Config.autoCatchName;
}
}

if (CheatDetector.CONFIG_HANDLER.configManager.setValue("autoCatchName", name)) {
LogUtils.custom(ChatFormatting.GREEN + "已设置: " + ChatFormatting.WHITE + name);
return 1;
} else {
return -1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public static void register(@NotNull CommandDispatcher<FabricClientCommandSource
.then(argument("part", IntegerArgumentType.integer(1))
.executes(WriterCommand::execute))
)
.then(literal("catch")
.executes(CatchCommand::execute)
.then(argument("name", StringArgumentType.string())
.executes(CatchCommand::execute))
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public class Advanced3Config {
@Config(category = ConfigCategory.ADVANCED3, predicate = ConfigPredicate.DangerMode.class)
public static boolean airStuckAntiKick = false;

@Config(category = ConfigCategory.ADVANCED3, predicate = ConfigPredicate.PASMode.class)
@Config(category = ConfigCategory.ADVANCED3)
public static String clientSpoofBrand = "vanilla";

@Numeric(minValue = 0, maxValue = 5)
Expand Down Expand Up @@ -292,6 +292,24 @@ public class Advanced3Config {
@Config(category = ConfigCategory.ADVANCED3, predicate = ConfigPredicate.DangerMode.class)
public static boolean slowMotionFastStop = false;

@Config(category = ConfigCategory.ADVANCED3, predicate = ConfigPredicate.PASMode.class)
public static String autoCatchName = "";
@Numeric(minValue = 0, maxValue = 100)
@Config(category = ConfigCategory.ADVANCED3, predicate = ConfigPredicate.PASMode.class)
public static double autoCatchDistance = 6;
@Config(category = ConfigCategory.ADVANCED3, predicate = ConfigPredicate.PASMode.class)
public static boolean autoCatchFast = false;
@Config(category = ConfigCategory.ADVANCED3, predicate = ConfigPredicate.PASMode.class)
public static boolean autoCatchAlways = false;
@Config(category = ConfigCategory.ADVANCED3, predicate = ConfigPredicate.PASMode.class)
public static boolean autoCatchAsPossible = false;
@Config(category = ConfigCategory.ADVANCED3, predicate = ConfigPredicate.PASMode.class)
public static double autoCatchAsPossibleTeleportDistance = 10;
@Config(category = ConfigCategory.ADVANCED3, predicate = ConfigPredicate.PASMode.class)
public static boolean autoCatchRotate = false;
@Config(category = ConfigCategory.ADVANCED3, predicate = ConfigPredicate.PASMode.class)
public static boolean autoCatchSilentRotate = false;

public static NotebotUtils.NotebotMode getNoteBotMode() {
if (noteBotMode.equals("AnyInstrument")) {
return NotebotUtils.NotebotMode.AnyInstrument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,8 @@ public class ModuleConfig {
@Hotkey
@Config(category = ConfigCategory.MODULES)
public static boolean sprintEnabled = false;

@Hotkey
@Config(category = ConfigCategory.MODULES, predicate = ConfigPredicate.PASMode.class)
public static boolean autoCatchEnabled = false;
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package top.infsky.cheatdetector.impl.modules.common;

import io.netty.channel.ChannelHandlerContext;
import lombok.Getter;
import net.minecraft.network.Connection;
import net.minecraft.network.PacketSendListener;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ServerGamePacketListener;
import net.minecraft.network.protocol.game.ServerboundEditBookPacket;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundEntityEventPacket;
import net.minecraft.network.protocol.game.ClientboundGameEventPacket;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import top.infsky.cheatdetector.config.ModuleConfig;
import top.infsky.cheatdetector.impl.Module;
import top.infsky.cheatdetector.impl.utils.world.LevelUtils;
import top.infsky.cheatdetector.utils.TRSelf;

import java.util.Objects;

public class Debug extends Module {
@Getter
@Nullable
Expand All @@ -24,11 +28,14 @@ public Debug(@NotNull TRSelf player) {
}

@Override
public boolean _onPacketSend(@NotNull Packet<ServerGamePacketListener> basePacket, Connection connection, PacketSendListener listener, CallbackInfo ci) {
public boolean _onPacketReceive(@NotNull Packet<ClientGamePacketListener> basePacket, Connection connection, ChannelHandlerContext channelHandlerContext, CallbackInfo ci) {
if (isDisabled()) return false;

if (basePacket instanceof ServerboundEditBookPacket packet) {
customMsg("slot:%s page:%s title:%s".formatted(packet.getSlot(), packet.getPages(), packet.getTitle()));
if (basePacket instanceof ClientboundEntityEventPacket packet) {
customMsg("EntityEvent: entity:%s eventId:%s".formatted(Objects.requireNonNull(packet.getEntity(LevelUtils.getClientLevel())).getName().getString(), packet.getEventId()));
}
if (basePacket instanceof ClientboundGameEventPacket packet) {
customMsg("GameEvent: event:%s param:%s".formatted(Objects.requireNonNull(packet.getEvent()), packet.getParam()));
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.jetbrains.annotations.Nullable;
import top.infsky.cheatdetector.CheatDetector;
import top.infsky.cheatdetector.impl.Module;
import top.infsky.cheatdetector.impl.modules.pas.Fly;
import top.infsky.cheatdetector.impl.modules.danger.Fly;
import top.infsky.cheatdetector.utils.TRSelf;
import top.infsky.cheatdetector.config.Advanced3Config;
import top.infsky.cheatdetector.config.ModuleConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ public void onFinallyPacketSend(ConnectionAccessor connection, Packet<?> basePac
stoppedSprint = true;
lastStopSprintTime = player.upTime;
}
} else if (stoppedSprint) {
player.fabricPlayer.connection.send(new ServerboundPlayerCommandPacket(player.fabricPlayer, ServerboundPlayerCommandPacket.Action.START_SPRINTING));
} else {
if (stoppedSprint)
player.fabricPlayer.connection.send(new ServerboundPlayerCommandPacket(player.fabricPlayer, ServerboundPlayerCommandPacket.Action.START_SPRINTING));
stoppedSprint = false;
}

if (basePacket instanceof Pos) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package top.infsky.cheatdetector.impl.modules.common;
package top.infsky.cheatdetector.impl.modules.danger;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package top.infsky.cheatdetector.impl.modules.common;
package top.infsky.cheatdetector.impl.modules.danger;

import lombok.Getter;
import net.minecraft.client.multiplayer.ClientLevel;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package top.infsky.cheatdetector.impl.modules.pas;
package top.infsky.cheatdetector.impl.modules.danger;

import io.netty.channel.ChannelHandlerContext;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package top.infsky.cheatdetector.impl.modules.pas;
package top.infsky.cheatdetector.impl.modules.danger;

import lombok.Getter;
import net.minecraft.core.BlockPos;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package top.infsky.cheatdetector.impl.modules.pas;
package top.infsky.cheatdetector.impl.modules.danger;

import net.minecraft.world.item.Items;
import net.minecraft.world.phys.Vec3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import io.netty.channel.ChannelHandlerContext;
import lombok.Getter;
import net.minecraft.ChatFormatting;
import net.minecraft.client.multiplayer.PlayerInfo;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientGamePacketListener;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket;
Expand All @@ -31,10 +28,11 @@ public class AntiBot extends Module {
private static final String botLeftMsg = " left the game";

@Getter
private static List<PlayerInfo> botList = new ArrayList<>();
private static List<UUID> botList = new LinkedList<>();

public AntiBot(@NotNull TRSelf player) {
super("AntiBot", player);
botList = new LinkedList<>();
instance = this;
}

Expand All @@ -54,19 +52,19 @@ public boolean _onPacketReceive(@NotNull Packet<ClientGamePacketListener> basePa
String msg = packet.content().getString();
try {
if (msg.endsWith(botJoinMsg)) {
final String name = msg.substring(0, msg.length() - botJoinMsg.length());
String name = msg.substring(0, msg.length() - botJoinMsg.length());
addBotVisual(player.fabricPlayer.connection.getPlayerInfo(name));
} else if (msg.endsWith(botLeftMsg)) {
final String name = msg.substring(0, msg.length() - botLeftMsg.length());
String name = msg.substring(0, msg.length() - botLeftMsg.length());
removeBotVisual(player.fabricPlayer.connection.getPlayerInfo(name));
}
} catch (NullPointerException e) {
customMsg("receive invalid player join msg: %s".formatted(msg));
}
}
if (Advanced3Config.antiBotLatency && basePacket instanceof ClientboundPlayerInfoUpdatePacket packet) {
List<PlayerInfo> players = new LinkedList<>(player.fabricPlayer.connection.getOnlinePlayers());
if (packet.newEntries().isEmpty()) {
if (packet.actions().stream().allMatch(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY::equals)) {
List<PlayerInfo> players = new LinkedList<>(player.fabricPlayer.connection.getOnlinePlayers());
packet.entries().forEach(entry -> {
try {
PlayerInfo playerInfo = Objects.requireNonNull(player.fabricPlayer.connection.getPlayerInfo(entry.profileId()));
Expand All @@ -84,29 +82,23 @@ public boolean _onPacketReceive(@NotNull Packet<ClientGamePacketListener> basePa
}

private void addBotVisual(PlayerInfo playerInfo) {
if (botList.contains(playerInfo)) return;
if (playerInfo == null) return;
if (botList.contains(playerInfo.getProfile().getId())) return;
player.timeTask.schedule(() -> {
MutableComponent displayName = Objects.requireNonNullElse(playerInfo.getTabListDisplayName(), Component.literal(playerInfo.getProfile().getName())).copy();
if (displayName.getString().startsWith(Component.translatable("cheatdetector.overlay.tab.bot").withStyle(ChatFormatting.AQUA).getString())) return;
playerInfo.setTabListDisplayName(Component.literal(
Component.translatable("cheatdetector.overlay.tab.bot").withStyle(ChatFormatting.AQUA).getString() + ChatFormatting.RESET + displayName.getString()
));
botList.add(playerInfo);
if (getBotList().contains(playerInfo.getProfile().getId())) return;
getBotList().add(playerInfo.getProfile().getId());
if (Advanced3Config.antiBotDebug) {
customMsg("remove bot :)");
}
}, player.getLatency() + 150, TimeUnit.MILLISECONDS);
}

private void removeBotVisual(PlayerInfo playerInfo) {
if (!botList.contains(playerInfo)) return;
if (playerInfo == null) return;
if (!botList.contains(playerInfo.getProfile().getId())) return;
player.timeTask.schedule(() -> {
MutableComponent displayName = Objects.requireNonNullElse(playerInfo.getTabListDisplayName(), Component.literal(playerInfo.getProfile().getName())).copy();
if (!displayName.getString().startsWith(Component.translatable("cheatdetector.overlay.tab.bot").withStyle(ChatFormatting.AQUA).getString())) return;
playerInfo.setTabListDisplayName(Component.literal(
displayName.getString().substring(Component.translatable("cheatdetector.overlay.tab.bot").withStyle(ChatFormatting.AQUA).getString().length())
));
botList.remove(playerInfo);
if (getBotList().contains(playerInfo.getProfile().getId())) return;
getBotList().remove(playerInfo.getProfile().getId());
}, player.getLatency() + 150, TimeUnit.MILLISECONDS);
}

Expand Down
106 changes: 106 additions & 0 deletions src/main/java/top/infsky/cheatdetector/impl/modules/pas/AutoCatch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package top.infsky.cheatdetector.impl.modules.pas;

import lombok.Getter;
import net.minecraft.client.player.AbstractClientPlayer;
import net.minecraft.network.protocol.game.ServerboundInteractPacket;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.AirItem;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import top.infsky.cheatdetector.config.Advanced3Config;
import top.infsky.cheatdetector.config.ModuleConfig;
import top.infsky.cheatdetector.impl.Module;
import top.infsky.cheatdetector.impl.modules.common.Rotation;
import top.infsky.cheatdetector.impl.utils.world.ContainerUtils;
import top.infsky.cheatdetector.impl.utils.world.LevelUtils;
import top.infsky.cheatdetector.impl.utils.world.PlayerRotation;
import top.infsky.cheatdetector.utils.TRSelf;

import java.util.NoSuchElementException;

public class AutoCatch extends Module {
@Getter
@Nullable
private static Module instance = null;
public AutoCatch(@NotNull TRSelf player) {
super("AutoCatch", player);
instance = this;
}

@Override
public void _onTick() {
if (isDisabled()) return;
if (!Advanced3Config.autoCatchAlways && player.fabricPlayer.isPassenger()) return;

doCatch();
}

private void doCatch() {
try {
AbstractClientPlayer target = LevelUtils.getClientLevel().players().stream()
.filter(p -> p.getGameProfile().getName().equals(Advanced3Config.autoCatchName))
.findFirst()
.orElseThrow();

double distance = target.distanceTo(player.fabricPlayer);
if (distance > Advanced3Config.autoCatchDistance && !Advanced3Config.autoCatchAsPossible) return;
if (distance > 6) {
if (Advanced3Config.autoCatchAsPossible) {
Vec3 targetPos = target.position().add(target.getDeltaMovement());
player.fabricPlayer.setDeltaMovement(getTeleportMotion(targetPos).add(target.getDeltaMovement()));
return;
}
}
player.fabricPlayer.setDeltaMovement(0, 0, 0);

player.fabricPlayer.getInventory().selected = ContainerUtils.findItem(player.fabricPlayer.getInventory(), AirItem.class, ContainerUtils.SlotType.HOTBAR);
if (Advanced3Config.autoCatchRotate) {
float yaw = PlayerRotation.getYaw(target.getEyePosition());
float pitch = PlayerRotation.getPitch(target.getEyePosition());
if (Advanced3Config.autoCatchSilentRotate) {
Rotation.silentRotate(yaw, pitch);
} else {
PlayerRotation.rotate(yaw, pitch);
}
}

player.fabricPlayer.setSilent(false);
player.fabricPlayer.connection.send(ServerboundInteractPacket.createInteractionPacket(target, false, InteractionHand.MAIN_HAND, player.fabricPlayer.position()));
player.fabricPlayer.swing(InteractionHand.MAIN_HAND);
} catch (NoSuchElementException ignored) {
}
}

private @NotNull Vec3 getTeleportMotion(@NotNull final Vec3 targetPos) {
Vec3 current = player.fabricPlayer.position();
final double step = Advanced3Config.autoCatchAsPossibleTeleportDistance;

current = new Vec3(
add(current.x(), step, targetPos.x()),
add(current.y(), step, targetPos.y()),
add(current.z(), step, targetPos.z())
);
return current.subtract(player.fabricPlayer.position());
}

private static double add(double current, double step, double target) {
if (current < target) {
return Math.min(current + step, target);
} else {
return Math.max(current - step, target);
}
}

public void onStopRiding() {
if (isDisabled()) return;
if (!Advanced3Config.autoCatchFast) return;

doCatch();
}

@Override
public boolean isDisabled() {
return !ModuleConfig.autoCatchEnabled || !ModuleConfig.aaaPASModeEnabled;
}
}
Loading

0 comments on commit 3cfa8ae

Please sign in to comment.