Skip to content

Commit

Permalink
Release 2.3.1
Browse files Browse the repository at this point in the history
- 修复bug
  • Loading branch information
xia-mc committed May 1, 2024
1 parent 4136d89 commit 2dcf6bf
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 122 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 @@ org.gradle.jvmargs=-Xmx1G
loader_version=0.14.23

# Mod Properties
mod_version = 2.3.0
mod_version = 2.3.1
maven_group = top.infsky
archives_base_name = CheatDetector

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import top.infsky.cheatdetector.anticheat.Module;
import top.infsky.cheatdetector.anticheat.TRPlayer;
import top.infsky.cheatdetector.anticheat.TRSelf;
import top.infsky.cheatdetector.anticheat.utils.LevelUtils;
import top.infsky.cheatdetector.anticheat.utils.PlayerMove;
import top.infsky.cheatdetector.config.Advanced3Config;
import top.infsky.cheatdetector.config.ModuleConfig;

import java.io.IOException;

public class AirWalk extends Module {
@Getter
@Nullable
Expand All @@ -34,35 +32,32 @@ public AirWalk(@NotNull TRSelf player) {
@Override
public void _onTick() {
BlockPos current;
try (ClientLevel level = TRPlayer.CLIENT.level) {
if (isDisabled()) {
if (fakeBlockPos != null && level != null) {
if (level.getBlockState(fakeBlockPos).is(Blocks.BARRIER))
level.setBlock(fakeBlockPos, Blocks.AIR.defaultBlockState(), 3);
}
fakeBlockPos = null;
yPos = null;
return;
}
if (level == null) return;
if (yPos == null) yPos = player.fabricPlayer.getBlockY() - 1;

current = player.fabricPlayer.blockPosition().below();
if (Advanced3Config.airWalkSameY && fakeBlockPos != null)
current = current.atY(yPos);
if (current == fakeBlockPos) return;

if (fakeBlockPos != null) {
ClientLevel level = LevelUtils.getClientLevel();
if (isDisabled()) {
if (fakeBlockPos != null && level != null) {
if (level.getBlockState(fakeBlockPos).is(Blocks.BARRIER))
level.setBlock(fakeBlockPos, Blocks.AIR.defaultBlockState(), 3);
fakeBlockPos = null;
}
if (level.getBlockState(current).isAir()) {
level.setBlock(current, Blocks.BARRIER.defaultBlockState(), 3);
fakeBlockPos = current;
}
} catch (IOException e) {
throw new RuntimeException(e);
fakeBlockPos = null;
yPos = null;
return;
}
if (level == null) return;
if (yPos == null) yPos = player.fabricPlayer.getBlockY() - 1;

current = player.fabricPlayer.blockPosition().below();
if (Advanced3Config.airWalkSameY && fakeBlockPos != null)
current = current.atY(yPos);
if (current == fakeBlockPos) return;

if (fakeBlockPos != null) {
if (level.getBlockState(fakeBlockPos).is(Blocks.BARRIER))
level.setBlock(fakeBlockPos, Blocks.AIR.defaultBlockState(), 3);
fakeBlockPos = null;
}
if (level.getBlockState(current).isAir()) {
level.setBlock(current, Blocks.BARRIER.defaultBlockState(), 3);
fakeBlockPos = current;
}

if (PlayerMove.getXzSecSpeed(player.lastPos, player.currentPos) > 1.8 && Advanced3Config.airWalkAutoJump && player.currentOnGround)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.block.AirBlock;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import top.infsky.cheatdetector.CheatDetector;
import top.infsky.cheatdetector.anticheat.Module;
import top.infsky.cheatdetector.anticheat.TRPlayer;
import top.infsky.cheatdetector.anticheat.TRSelf;
import top.infsky.cheatdetector.anticheat.utils.LevelUtils;
import top.infsky.cheatdetector.config.Advanced3Config;
import top.infsky.cheatdetector.config.ModuleConfig;

import java.io.IOException;

public class AntiFall extends Module {
@Getter
@Nullable
Expand All @@ -33,63 +30,60 @@ public AntiFall(@NotNull TRSelf player) {

@Override
public void _onTick() {
try (ClientLevel level = TRPlayer.CLIENT.level) {
if (isDisabled()) {
if (fakeBlockPos != null && level != null)
if (level.getBlockState(fakeBlockPos).is(Blocks.BARRIER))
level.setBlock(fakeBlockPos, Blocks.AIR.defaultBlockState(), 3);
fakeBlockPos = null;
return;
}
if (level == null) return;
ClientLevel level = LevelUtils.getClientLevel();
if (isDisabled()) {
if (fakeBlockPos != null && level != null)
if (level.getBlockState(fakeBlockPos).is(Blocks.BARRIER))
level.setBlock(fakeBlockPos, Blocks.AIR.defaultBlockState(), 3);
fakeBlockPos = null;
return;
}
if (level == null) return;

BlockPos current = player.fabricPlayer.blockPosition().below();
if (!needToClutch && Advanced3Config.antiFallFastClutchOnVoid) {
boolean isVoid = true;
try {
for (int yPos = -65; yPos <= current.getY(); yPos++) {
BlockState blockState = level.getBlockState(current.atY(yPos));
if (!blockState.isAir()) {
isVoid = false;
break;
}
BlockPos current = player.fabricPlayer.blockPosition().below();
if (!needToClutch && Advanced3Config.antiFallFastClutchOnVoid) {
boolean isVoid = true;
try {
for (int yPos = -65; yPos <= current.getY(); yPos++) {
BlockState blockState = level.getBlockState(current.atY(yPos));
if (!blockState.isAir()) {
isVoid = false;
break;
}
} catch (Exception e) {
customMsg(e.getLocalizedMessage());
}
if (isVoid) {
needToClutch = true;
customMsg(Component.translatable("cheatdetector.chat.alert.clutch").getString());
}
} catch (Exception e) {
customMsg(e.getLocalizedMessage());
}
if (!needToClutch && !player.fabricPlayer.isFallFlying() && player.fabricPlayer.fallDistance >= Advanced3Config.antiFallFallDistance) {
if (isVoid) {
needToClutch = true;
customMsg(Component.translatable("cheatdetector.chat.alert.clutch").getString());
}
}
if (!needToClutch && !player.fabricPlayer.isFallFlying() && player.fabricPlayer.fallDistance >= Advanced3Config.antiFallFallDistance) {
needToClutch = true;
customMsg(Component.translatable("cheatdetector.chat.alert.clutch").getString());
}

if (needToClutch) {
if (player.fabricPlayer.input.shiftKeyDown && player.currentOnGround) current = current.below();
if (current == fakeBlockPos) return;
if (needToClutch) {
if (player.fabricPlayer.input.shiftKeyDown && player.currentOnGround) current = current.below();
if (current == fakeBlockPos) return;


if (fakeBlockPos != null) {
if (level.getBlockState(fakeBlockPos).is(Blocks.BARRIER))
level.setBlock(fakeBlockPos, Blocks.AIR.defaultBlockState(), 3);
fakeBlockPos = null;
}
if (level.getBlockState(current).isAir()) {
level.setBlock(current, Blocks.BARRIER.defaultBlockState(), 3);
fakeBlockPos = current;
} else {
needToClutch = false;
if (Advanced3Config.antiFallClutchMsg)
customMsg(Component.translatable("cheatdetector.chat.alert.clutchDone").getString());
if (Advanced3Config.antiFallAutoDisabled)
CheatDetector.CONFIG_HANDLER.configManager.setValue("antiFallEnabled", false);
}
if (fakeBlockPos != null) {
if (level.getBlockState(fakeBlockPos).is(Blocks.BARRIER))
level.setBlock(fakeBlockPos, Blocks.AIR.defaultBlockState(), 3);
fakeBlockPos = null;
}
if (level.getBlockState(current).isAir()) {
level.setBlock(current, Blocks.BARRIER.defaultBlockState(), 3);
fakeBlockPos = current;
} else {
needToClutch = false;
if (Advanced3Config.antiFallClutchMsg)
customMsg(Component.translatable("cheatdetector.chat.alert.clutchDone").getString());
if (Advanced3Config.antiFallAutoDisabled)
CheatDetector.CONFIG_HANDLER.configManager.setValue("antiFallEnabled", false);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public boolean _handleAttack(Entity entity) {
if (targetVisual != null)
targetVisual.hide();
targetVisual = null;
targetVisual = new FakePlayer(player.fabricPlayer.level(), target.blockPosition(), target.getGameProfile());
targetVisual = new FakePlayer(target);
targetVisual.show();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public void _onTick() {
if (!VelocityUtils.shouldCheck(player, null)) return;

if (player.lastOnGround) {
customMsg("jump!");
player.fabricPlayer.jumpFromGround();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.NoteBlock;
import net.minecraft.world.level.block.state.BlockState;
Expand All @@ -35,6 +36,8 @@
import top.infsky.cheatdetector.utils.LogUtils;

import java.io.File;
import java.io.IOException;
import java.nio.file.InvalidPathException;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.CancellationException;
Expand Down Expand Up @@ -78,10 +81,18 @@ public boolean isDisabled() {
@Override
public void _onTick() {
if (!lastEnabled && !isDisabled()) {
String baseStringPath = Advanced3Config.noteBotFilePath;
String stringPath = baseStringPath.charAt(0) == '"' && baseStringPath.charAt(baseStringPath.length() - 1) == '"' ?
baseStringPath.substring(1, baseStringPath.length() - 1) : baseStringPath;

try {
loadSong(Path.of(Advanced3Config.noteBotFilePath).toFile());
loadSong(Path.of(stringPath).toFile());
// tune();
} catch (NullPointerException ignored) {}
} catch (NullPointerException ignored) {
} catch (InvalidPathException e) {
error("Invalid path: %s".formatted(stringPath));
stop();
}
} else if (lastEnabled && isDisabled()) {
stop();
}
Expand Down Expand Up @@ -235,7 +246,7 @@ private void tune() {
}

private void tuneBlocks() {
if (TRPlayer.CLIENT.level == null || player.fabricPlayer == null) {
if (player.fabricPlayer == null) {
CheatDetector.CONFIG_HANDLER.configManager.setValue("noteBotEnabled", false);
ModuleConfig.noteBotEnabled = false;
}
Expand Down Expand Up @@ -486,18 +497,20 @@ private void onTickPlay() {
}

private void playRotate(BlockPos pos) {
if (TRPlayer.CLIENT.player == null) return;
if (TRPlayer.CLIENT.gameMode == null) return;
try {
TRPlayer.CLIENT.player.connection.send(new ServerboundPlayerActionPacket(ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK, pos, Direction.DOWN, 0));
player.fabricPlayer.connection.send(new ServerboundPlayerActionPacket(ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK, pos, Direction.DOWN, 0));
} catch (NullPointerException ignored) {
}
}

private boolean isValidScanSpot(BlockPos pos) {
if (TRPlayer.CLIENT.level == null) return false;
if (TRPlayer.CLIENT.level.getBlockState(pos).getBlock() != Blocks.NOTE_BLOCK) return false;
return TRPlayer.CLIENT.level.getBlockState(pos.above()).isAir();
try (Level level = TRPlayer.CLIENT.level) {
if (level == null) return false;
if (level.getBlockState(pos).getBlock() != Blocks.NOTE_BLOCK) return false;
return level.getBlockState(pos.above()).isAir();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void packetRot() {

@Override
public boolean _handleMovePlayer(@NotNull ServerboundMovePlayerPacket packet, @NotNull Connection connection, PacketSendListener listener, @NotNull CallbackInfo ci) {
if (isDisabled()) return false;
if (!Advanced3Config.spinOnlyPacket) return false;
return PlayerRotation.cancelRotationPacket(packet, connection, listener, ci);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package top.infsky.cheatdetector.anticheat.utils;

import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.*;
import net.minecraft.world.item.ItemStack;

public class EntityUtils {
/**
* @see LivingEntity#getAttributes()
*/
public static AttributeMap getAttributes(LivingEntity entity) {
AttributeMap attributes = new AttributeMap(getDefaultForEntity(entity));

// Equipment
for (var equipmentSlot : EquipmentSlot.values()) {
ItemStack stack = entity.getItemBySlot(equipmentSlot);
attributes.addTransientAttributeModifiers(stack.getAttributeModifiers(equipmentSlot));
}

// Status effects
for (var statusEffect : entity.getActiveEffectsMap().values()) {
statusEffect.getEffect().addAttributeModifiers(entity, attributes, statusEffect.getAmplifier());
}

return attributes;
}

@SuppressWarnings("unchecked")
private static <T extends LivingEntity> AttributeSupplier getDefaultForEntity(T entity) {
return DefaultAttributes.getSupplier((EntityType<? extends LivingEntity>) entity.getType());
}
}
Loading

0 comments on commit 2dcf6bf

Please sign in to comment.