-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
添加BlinkA检查。 添加AirJumpA检查。 添加AirPlaceA检查。 添加SpeedA检查。 修复一些误判。 更改架构,改善性能。 已知误判: - **FlightA** 鞘翅、三叉戟。 - **BlinkA** 状态效果。 - **SpeedA** 状态效果、道具。 - **AirJumpA** blink时意外触发。
- Loading branch information
Showing
13 changed files
with
374 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/main/java/top/infsky/timerecorder/anticheat/TRPlayer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package top.infsky.timerecorder.anticheat; | ||
|
||
import lombok.Getter; | ||
import lombok.val; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Range; | ||
import top.infsky.timerecorder.Utils; | ||
import top.infsky.timerecorder.config.AntiCheatConfig; | ||
import top.infsky.timerecorder.config.ModConfig; | ||
import top.infsky.timerecorder.data.PlayerData; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* 管理玩家信息的类。每个玩家都应有一个TRPlayer实例。 | ||
*/ | ||
@Getter | ||
public class TRPlayer { | ||
public ServerPlayer fabricPlayer; | ||
public CheckManager manager; | ||
public PlayerData playerData; | ||
public static MinecraftServer SERVER = Utils.getSERVER(); | ||
|
||
public static AntiCheatConfig CONFIG() { return ModConfig.INSTANCE.getAntiCheat(); } | ||
public Vec3 currentPos; | ||
public Vec3 lastPos; | ||
@Range(from = 0, to = 19) public List<Vec3> posHistory; | ||
public Vec3 lastOnGroundPos; | ||
public Vec3 lastInLiquidPos; | ||
public boolean lastOnGround; | ||
public boolean hasSetback = false; | ||
|
||
public List<Runnable> needToDoNextTick = new LinkedList<>(); | ||
|
||
public TRPlayer(@NotNull PlayerData playerData) { | ||
this.fabricPlayer = (ServerPlayer) playerData.player; | ||
this.manager = CheckManager.create(this); | ||
this.playerData = playerData; | ||
currentPos = fabricPlayer.position(); | ||
lastOnGround = fabricPlayer.onGround(); | ||
posHistory = new LinkedList<>(); | ||
for (int i = 0; i < 20; i++) { | ||
posHistory.add(currentPos); | ||
} | ||
} | ||
|
||
public void update() { | ||
fabricPlayer = (ServerPlayer) playerData.player; | ||
if (fabricPlayer == null) return; | ||
|
||
currentPos = fabricPlayer.position(); | ||
updatePoses(); | ||
if (fabricPlayer.onGround()) { | ||
lastOnGroundPos = currentPos; | ||
} | ||
if (fabricPlayer.isInWater() || fabricPlayer.isInLava()) { | ||
lastInLiquidPos = currentPos; | ||
} | ||
|
||
val preTask = needToDoNextTick; | ||
for (Runnable task : preTask) { | ||
task.run(); | ||
needToDoNextTick.remove(task); | ||
} | ||
manager.update(); | ||
|
||
|
||
lastPos = currentPos; | ||
lastOnGround = fabricPlayer.onGround(); | ||
} | ||
|
||
private void updatePoses() { | ||
if (posHistory.size() >= 20) { | ||
posHistory.remove(posHistory.size() - 1); | ||
updatePoses(); | ||
} | ||
posHistory.add(0, currentPos); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/top/infsky/timerecorder/anticheat/checks/AirJumpA.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package top.infsky.timerecorder.anticheat.checks; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
import top.infsky.timerecorder.anticheat.Check; | ||
import top.infsky.timerecorder.anticheat.TRPlayer; | ||
|
||
public class AirJumpA extends Check { | ||
public AirJumpA(@NotNull TRPlayer player) { | ||
super("AirJumpA", player); | ||
} | ||
|
||
@Override | ||
public void _onJump() { | ||
if (!player.fabricPlayer.onGround()) { | ||
flag(); | ||
setback(player.currentPos); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/top/infsky/timerecorder/anticheat/checks/AirPlaceA.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package top.infsky.timerecorder.anticheat.checks; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.network.protocol.Packet; | ||
import net.minecraft.network.protocol.game.ServerGamePacketListener; | ||
import net.minecraft.network.protocol.game.ServerboundUseItemOnPacket; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.world.level.block.AirBlock; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
import org.jetbrains.annotations.Contract; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Unmodifiable; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import top.infsky.timerecorder.anticheat.Check; | ||
import top.infsky.timerecorder.anticheat.TRPlayer; | ||
|
||
import java.util.List; | ||
|
||
public class AirPlaceA extends Check { | ||
public AirPlaceA(@NotNull TRPlayer player) { | ||
super("AirPlaceA", player); | ||
} | ||
|
||
@Contract("_ -> new") | ||
private static @Unmodifiable List<BlockPos> getBlocksNeedToCheck(@NotNull BlockPos pos) { | ||
return List.of(pos.east(), pos.west(), pos.north(), pos.south(), pos.above(), pos.below()); | ||
} | ||
|
||
@Override | ||
public void _onPacketReceive(Packet<ServerGamePacketListener> basePacket, CallbackInfo ci) { | ||
if (basePacket instanceof ServerboundUseItemOnPacket packet) { | ||
final BlockHitResult hitResult = packet.getHitResult(); | ||
final ServerLevel level = player.fabricPlayer.serverLevel(); | ||
|
||
short airCount = 0; | ||
for (BlockPos pos : getBlocksNeedToCheck(hitResult.getBlockPos())) { | ||
if (level.getBlockState(pos).getBlock() instanceof AirBlock) { | ||
airCount++; | ||
} | ||
} | ||
|
||
if (airCount >= 6) { | ||
flag(); | ||
setback(ci); | ||
} | ||
} | ||
} | ||
} |
34 changes: 12 additions & 22 deletions
34
src/main/java/top/infsky/timerecorder/anticheat/checks/BlinkA.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,26 @@ | ||
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.ServerboundKeepAlivePacket; | ||
import org.jetbrains.annotations.NotNull; | ||
import top.infsky.timerecorder.anticheat.Check; | ||
import top.infsky.timerecorder.data.PlayerData; | ||
import top.infsky.timerecorder.anticheat.TRPlayer; | ||
|
||
import java.util.Queue; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
import static top.infsky.timerecorder.anticheat.TRPlayer.CONFIG; | ||
|
||
public class BlinkA extends Check { | ||
public Queue<ServerboundKeepAlivePacket> keepAlivePackets = new LinkedBlockingQueue<>(10); | ||
|
||
public BlinkA(@NotNull PlayerData playerData) { | ||
super("BlinkA", playerData); | ||
} | ||
|
||
@Override | ||
public void _onPacketReceive(Packet<ServerGamePacketListener> packet) { | ||
if (packet instanceof ServerboundKeepAlivePacket) { | ||
try { | ||
keepAlivePackets.add((ServerboundKeepAlivePacket) packet); | ||
} catch (IllegalStateException ignored) { | ||
keepAlivePackets.poll(); | ||
keepAlivePackets.add((ServerboundKeepAlivePacket) packet); | ||
} | ||
} | ||
public class BlinkA extends Check { | ||
|
||
public BlinkA(@NotNull TRPlayer player) { | ||
super("BlinkA", player); | ||
} | ||
|
||
@Override | ||
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())) { | ||
flag(); | ||
|
||
setback(player.lastPos); | ||
} | ||
} | ||
} |
Oops, something went wrong.