Improved accuracy

This commit is contained in:
Dawson
2022-09-16 19:55:15 -04:00
parent b24053f1ca
commit 8015f4cb99
5 changed files with 73 additions and 27 deletions
@@ -20,8 +20,8 @@ public class KABot extends Check {
WAction<WPacketPlayInUseEntity> packet = packet -> {
val optional = player.getEntityLocationHandler().getFakeMob(packet.getEntityId());
if(optional.isPresent()) {
if(++buffer > 1) {
if(optional.isPresent() && player.getEntityLocationHandler().clientHasEntity.get()) {
if(++buffer > 3) {
flag("Attacked player without attacking bot!");
}
} else buffer = 0;
@@ -3,6 +3,7 @@ package dev.brighten.ac.data.info;
import dev.brighten.ac.packet.wrapper.objects.PlayerCapabilities;
import dev.brighten.ac.utils.KLocation;
import dev.brighten.ac.utils.PastLocation;
import dev.brighten.ac.utils.math.RollingAverage;
import dev.brighten.ac.utils.objects.evicting.EvictingList;
import dev.brighten.ac.utils.timer.Timer;
import dev.brighten.ac.utils.timer.impl.TickTimer;
@@ -30,7 +31,7 @@ public class GeneralInformation {
lastRespawn = new TickTimer(), lastEntityCollision = new TickTimer(), lastWeb = new TickTimer(),
lastLiquid = new TickTimer(), lastBlockDig = new TickTimer(), lastBlockPlace = new TickTimer(),
lastBlockUpdate = new TickTimer(), lastMiscNear = new TickTimer(), lastHalfBlock = new TickTimer(),
lastFence = new TickTimer();
lastFence = new TickTimer(), lastFakeBotHit = new TickTimer();
public LivingEntity target;
public Optional<PotionEffect> groundJumpBoost;
public boolean serverGround, lastServerGround, canFly, nearGround, worldLoaded, generalCancel, inVehicle, creative,
@@ -38,6 +39,8 @@ public class GeneralInformation {
public List<Entity> nearbyEntities = Collections.emptyList();
public PastLocation targetPastLocation = new PastLocation();
public KLocation lastKnownGoodPosition;
public long lastArmSwing;
public RollingAverage cps = new RollingAverage(10);
public List<Vector> velocityHistory = Collections.synchronizedList(new EvictingList<>(5));
public List<PlayerCapabilities> possibleCapabilities = new ArrayList<>();
private int clientGroundTicks, clientAirTicks;
@@ -4,6 +4,7 @@ import dev.brighten.ac.Anticheat;
import dev.brighten.ac.data.APlayer;
import dev.brighten.ac.handler.entity.FakeMob;
import dev.brighten.ac.packet.ProtocolVersion;
import dev.brighten.ac.packet.wrapper.objects.WrappedWatchableObject;
import dev.brighten.ac.packet.wrapper.out.*;
import dev.brighten.ac.utils.EntityLocation;
import dev.brighten.ac.utils.Tuple;
@@ -18,6 +19,7 @@ import org.bukkit.entity.EntityType;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
@RequiredArgsConstructor
public class EntityLocationHandler {
@@ -25,12 +27,13 @@ public class EntityLocationHandler {
private final APlayer data;
private final Map<UUID, Tuple<EntityLocation, EntityLocation>> entityLocationMap = new ConcurrentHashMap<>();
private final Map<Integer, FakeMob> fakeMobs = new Int2ObjectArrayMap<>();
private final Map<Integer, List<FakeMob>> fakeMobs = new Int2ObjectArrayMap<>();
private final Map<Integer, Integer> fakeMobToEntityId = new Int2ObjectArrayMap<>();
private final Timer lastFlying = new MillisTimer();
public Set<Integer> canCreateMob = new HashSet<>();
public int streak;
public AtomicBoolean clientHasEntity = new AtomicBoolean(false);
private static final EnumSet<EntityType> allowedEntityTypes = EnumSet.of(EntityType.ZOMBIE, EntityType.SHEEP,
EntityType.BLAZE, EntityType.SKELETON, EntityType.PLAYER, EntityType.VILLAGER, EntityType.IRON_GOLEM,
@@ -48,7 +51,7 @@ public class EntityLocationHandler {
return Optional.ofNullable(entityLocationMap.get(entity.getUniqueId()));
}
public Optional<FakeMob> getFakeMob(int entityId) {
public Optional<List<FakeMob>> getFakeMob(int entityId) {
return Optional.ofNullable(fakeMobs.get(entityId));
}
@@ -224,50 +227,79 @@ public class EntityLocationHandler {
public void onEntityDestroy(WPacketPlayOutEntityDestroy packet) {
for(int id : packet.getEntityIds()) {
if(fakeMobs.containsKey(id)) {
FakeMob mob = fakeMobs.get(id);
mob.despawn();
fakeMobToEntityId.remove(mob.getEntityId());
List<FakeMob> mobs = fakeMobs.get(id);
for (FakeMob mob : mobs) {
mob.despawn();
fakeMobToEntityId.remove(mob.getEntityId());
}
fakeMobs.remove(id);
clientHasEntity.set(false);
}
}
}
public void removeFakeMob(int id) {
if(fakeMobs.containsKey(id)) {
FakeMob mob = fakeMobs.get(id);
mob.despawn();
fakeMobToEntityId.remove(mob.getEntityId());
List<FakeMob> mobs = fakeMobs.get(id);
for (FakeMob mob : mobs) {
mob.despawn();
fakeMobToEntityId.remove(mob.getEntityId());
}
fakeMobs.remove(id);
}
clientHasEntity.set(false);
}
private static double[] offsets = new double[]{-1.25, 0, 1.25};
private void createFakeMob(int entityId, Location location) {
if(!canCreateMob.contains(entityId)) return;
FakeMob mob = new FakeMob(EntityType.GIANT);
mob.spawn(true, location, data);
List<FakeMob> mobs = new ArrayList<>();
this.fakeMobs.put(entityId, mob);
fakeMobToEntityId.put(mob.getEntityId(), entityId);
clientHasEntity.set(false);
for (double offset : offsets) {
FakeMob mob = new FakeMob(EntityType.MAGMA_CUBE);
mob.spawn(true, location.clone().add(offset, offset, offset),
new ArrayList<>(Arrays.asList(new WrappedWatchableObject(0, 16, (byte)10))), data);
fakeMobToEntityId.put(mob.getEntityId(), entityId);
mobs.add(mob);
}
this.fakeMobs.put(entityId, mobs);
canCreateMob.remove(entityId);
data.runKeepaliveAction(ka -> clientHasEntity.set(true));
}
public void processFakeMobs(int entityId, boolean rel, double x, double y, double z) {
FakeMob fakeMob = fakeMobs.get(entityId);
List<FakeMob> fakeMobs = this.fakeMobs.get(entityId);
if(fakeMob == null) {
if(fakeMobs == null) {
if(!rel) {
createFakeMob(entityId, new Location(data.getBukkitPlayer().getWorld(), x, y, z));
fakeMob = fakeMobs.get(entityId);
if(fakeMob == null) return;
} else return;
}
return;
}
if(rel) {
fakeMob.move(x, y, z);
} else {
fakeMob.teleport(x, y, z, 0, 0);
if(fakeMobs.size() != offsets.length) {
fakeMobs.forEach(fakeMob -> removeFakeMob(fakeMob.getEntityId()));
}
int current = 0;
for (FakeMob fakeMob : fakeMobs) {
double offset = offsets[current++];
if(rel) {
fakeMob.move(x, y, z);
} else {
fakeMob.teleport(x + offset, y + offset, z + offset, 0, 0);
}
}
}
}
@@ -282,12 +282,13 @@ public class PacketHandler {
player.getEntityLocationHandler().getTargetOfFakeMob(mob.getEntityId())
.ifPresent(targetId -> {
player.getEntityLocationHandler().removeFakeMob(targetId);
player.getInfo().lastFakeBotHit.reset();
});
} else {
Entity target = packet.getEntity(player.getBukkitPlayer().getWorld());
if(target instanceof LivingEntity) {
if(Math.random() > 0.9) {
if(player.getInfo().lastFakeBotHit.isPassed(400) && Math.random() > 0.9) {
player.getEntityLocationHandler().canCreateMob.add(target.getEntityId());
}
player.getInfo().setTarget((LivingEntity) target);
@@ -295,6 +296,13 @@ public class PacketHandler {
}
break;
}
case ARM_ANIMATION: {
long delta = timestamp - player.getInfo().lastArmSwing;
player.getInfo().cps.add(1000D / delta, timestamp);
player.getInfo().lastArmSwing = timestamp;
break;
}
case BLOCK_PLACE: {
WPacketPlayInBlockPlace packet = (WPacketPlayInBlockPlace) packetObject;
@@ -41,13 +41,16 @@ public class FakeMob {
}
*/
public void spawn(boolean invisible, Location location, APlayer... players) {
spawn(invisible, location, new ArrayList<>(), players);
}
public void spawn(boolean invisible, Location location, List<WrappedWatchableObject> objects, APlayer... players) {
if(watching.size() > 0) {
despawn();
}
watching = new ArrayList<>();
for (APlayer player : players) {
List<WrappedWatchableObject> objects = new ArrayList<>();
if(invisible) {
objects.add(new WrappedWatchableObject(0, 0, (byte)((byte)1 << 5)));
}