Compare commits

...
15 Commits
16 changed files with 195 additions and 162 deletions

No files matched your search

+1 -3
View File
@@ -118,9 +118,7 @@ gradle-app.setting
**/build/
# Common working directory
run/
runs/
run-1-21-11/
run*/
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
+1 -1
View File
@@ -13,7 +13,7 @@ The supported minecraft versions are 1.21.4+. Only Paper and derivative software
- Prevent cheating (anti-esp hacks)
- This is the plugin's primary purpose.
- Block usage of pie-ray to locate underground bases or farms.
- Prevent mods such as mini-maps or cheat clients from displaying the locations of hidden entities.
- Prevent mods such as mini-maps or cheat clients from displaying the locations of entities which would not be visible to vanilla players.
- Increase client-side performance for low-end devices
- Massive megabases containing hundreds of armour stands, item frames, banners etc can cause performance issues on low-end devices unable to process so many entities. Raycasted AntiESP will cull those entities for the client, reducing the number of entities to process.
- Reduce network load by limiting packets
@@ -20,17 +20,21 @@ import org.spongepowered.configurate.ConfigurationNode;
import org.spongepowered.configurate.yaml.NodeStyle;
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
import java.lang.invoke.VarHandle;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.annotation.Documented;
import java.lang.invoke.VarHandle;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.function.Supplier;
public class ConfigManager {
@@ -306,28 +310,13 @@ public class ConfigManager {
Files.createFile(configPath);
}
}
prependConfigDocumentationHeaderIfMissing();
ConfigMigrations.prependConfigDocumentationHeaderIfMissing(configPath);
ConfigMigrations.migrateSoundEffectsEnabled(configPath);
} catch (IOException e) {
throw new ConfigLoadException("Failed to create config.yml", e);
}
}
private void prependConfigDocumentationHeaderIfMissing() {
try {
String content = Files.readString(configPath);
if (content.startsWith("#")) {
Logger.debug("Config starts with comment");
return;
}
Logger.debug("no starting comment");
Files.writeString(configPath, "# An explanation of this configuration file and what all the options do can be found at https://raycastedantiesp.cubi.games/config/" + System.lineSeparator() + content);
} catch (Exception e) {
Logger.warning(e,3, ConfigManager.class);
}
}
private ConfigurationNode loadConfigNode() {
try {
return loader.load();
@@ -374,6 +363,108 @@ public class ConfigManager {
}
}
/**
* Temporary text-level config mutations. Remove this class when these migrations are no longer needed.
*/
private static final class ConfigMigrations {
private static final Pattern YAML_KEY = Pattern.compile("^([ \\t]*)([^:#\\s][^:]*):.*$");
private static final Pattern SOUND_EFFECTS_ENABLED_TRUE = Pattern.compile("^([ \\t]*enabled[ \\t]*:[ \\t]*)true([ \\t]*(?:#.*)?)$", Pattern.CASE_INSENSITIVE);
private ConfigMigrations() {
}
private static void prependConfigDocumentationHeaderIfMissing(Path configPath) {
try {
String content = Files.readString(configPath);
if (content.startsWith("#")) {
Logger.debug("Config starts with comment");
return;
}
Logger.debug("no starting comment");
Files.writeString(configPath, "# An explanation of this configuration file and what all the options do can be found at https://raycastedantiesp.cubi.games/config/" + System.lineSeparator() + content);
} catch (Exception e) {
Logger.warning(e,3, ConfigManager.class);
}
}
@Temporary(forRemovalIn = "0.8.0")
private static void migrateSoundEffectsEnabled(Path configPath) {
try {
String content = Files.readString(configPath, StandardCharsets.UTF_8);
String migrated = replaceSoundEffectsEnabled(content);
if (!content.equals(migrated)) {
Files.writeString(configPath, migrated, StandardCharsets.UTF_8);
}
} catch (IOException e) {
throw new ConfigLoadException("Failed to migrate sound-effects.enabled in config.yml", e);
}
}
private static String replaceSoundEffectsEnabled(String content) {
StringBuilder migrated = new StringBuilder(content.length());
int lineStart = 0;
int checksIndent = -1;
int soundEffectsIndent = -1;
boolean changed = false;
while (lineStart < content.length()) {
int lineEnd = content.indexOf('\n', lineStart);
boolean hasLineEnding = lineEnd >= 0;
int contentEnd = hasLineEnding ? lineEnd : content.length();
int lineContentEnd = contentEnd > lineStart && content.charAt(contentEnd - 1) == '\r'
? contentEnd - 1 : contentEnd;
String line = content.substring(lineStart, lineContentEnd);
String lineEnding = content.substring(lineContentEnd, contentEnd) + (hasLineEnding ? "\n" : "");
Matcher key = YAML_KEY.matcher(line);
if (key.matches()) {
int indent = key.group(1).length();
String name = key.group(2).trim();
if (checksIndent < 0) {
if (name.equals("checks")) {
checksIndent = indent;
}
} else if (indent <= checksIndent) {
checksIndent = name.equals("checks") ? indent : -1;
soundEffectsIndent = -1;
} else if (soundEffectsIndent < 0) {
if (name.equals("sound-effects")) {
soundEffectsIndent = indent;
}
} else if (indent <= soundEffectsIndent) {
soundEffectsIndent = name.equals("sound-effects") ? indent : -1;
}
}
if (soundEffectsIndent >= 0 && key.matches()
&& key.group(2).trim().equals("enabled")
&& key.group(1).length() > soundEffectsIndent) {
Matcher enabled = SOUND_EFFECTS_ENABLED_TRUE.matcher(line);
if (enabled.matches()) {
line = enabled.group(1) + "false" + enabled.group(2);
changed = true;
}
}
migrated.append(line).append(lineEnding);
if (!hasLineEnding) {
break;
}
lineStart = contentEnd + 1;
}
return changed ? migrated.toString() : content;
}
@Documented
private @interface Temporary {
String forRemovalIn();
}
}
private ConfigurationNode node(ConfigurationNode root, String path) {
String[] parts = path.split("\\.");
return ConfigReader.node(root, parts);
@@ -8,7 +8,6 @@
package games.cubi.raycastedantiesp.core.engine;
import games.cubi.locatables.api.ImmutableSpatial;
import games.cubi.locatables.api.Locatable;
import games.cubi.logs.Logger;
import games.cubi.raycastedantiesp.core.config.ConfigManager;
@@ -25,6 +24,8 @@ import games.cubi.raycastedantiesp.core.raycast.RaycastUtil;
import games.cubi.raycastedantiesp.core.utils.PrimitiveIntArrayList;
import games.cubi.raycastedantiesp.core.view.BlockView;
import games.cubi.raycastedantiesp.core.view.EntityView;
import games.cubi.utils.events.CancellableEvent;
import games.cubi.utils.events.CancellableEventRegistry;
import java.util.ArrayList;
import java.util.Collection;
@@ -120,6 +121,9 @@ public abstract class AsyncEngine implements Engine {
}
}
public static class EngineTickEvent extends CancellableEvent {}
public final CancellableEventRegistry<EngineTickEvent> engineTickEventRegistry = new CancellableEventRegistry<>();
/**
* Claims worker capacity and either runs work immediately or schedules worker batches.
*
@@ -127,6 +131,11 @@ public abstract class AsyncEngine implements Engine {
* lifecycle; false if this attempt was skipped or cleaned up during setup.
*/
private boolean dispatchTick(int scheduledTick, int startTick, long scheduledNanos) {
if (!engineTickEventRegistry.dispatch(EngineTickEvent::new)) {
Logger.debug("Skipping tick due to event being cancelled");
finishTickState();
return false;
}
int threads = config.getEngineConfig().asyncConfig().asyncProcessingThreads();
if (threads < 1) threads = 1;
@@ -22,4 +22,6 @@ public interface ParticleSpawner {
void spawnParticleAt(Locatable locatable, Colour colour);
void spawnParticleAt(UUID world, Spatial spatial, Colour colour);
void spawnParticleAt(UUID world, double x, double y, double z, Colour colour);
}
@@ -189,72 +189,59 @@ public class RaycastUtil {
if (total > maxRaycastRadius) return false;
float finalDist = (float) (total - stepSize);
RayChunkSection currentChunk = new RayChunkSection().updateFrom(current);
ChunkOcclusionView currentOcclusionView = snap.getChunkOcclusionView(currentChunk.chunkX, currentChunk.chunkY, currentChunk.chunkZ);
int occluded = 0;
final RayAdvancer rayAdvancer = new RayAdvancer(current, direction, snap);
float traveled = 0;
final float fourSteps = stepSize * 4.0f;
while (traveled + fourSteps <= finalDist) {
current.advance(direction);
int blockX = current.blockX();
int blockY = current.blockY();
int blockZ = current.blockZ();
if (blockX >> 4 != currentChunk.chunkX || blockY >> 4 != currentChunk.chunkY || blockZ >> 4 != currentChunk.chunkZ) {
currentChunk.updateFrom(current);
currentOcclusionView = snap.getChunkOcclusionView(currentChunk.chunkX, currentChunk.chunkY, currentChunk.chunkZ);
}
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded++;
rayAdvancer.advance();
current.advance(direction);
blockX = current.blockX();
blockY = current.blockY();
blockZ = current.blockZ();
if (blockX >> 4 != currentChunk.chunkX || blockY >> 4 != currentChunk.chunkY || blockZ >> 4 != currentChunk.chunkZ) {
currentChunk.updateFrom(current);
currentOcclusionView = snap.getChunkOcclusionView(currentChunk.chunkX, currentChunk.chunkY, currentChunk.chunkZ);
}
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded++;
rayAdvancer.advance();
current.advance(direction);
blockX = current.blockX();
blockY = current.blockY();
blockZ = current.blockZ();
if (blockX >> 4 != currentChunk.chunkX || blockY >> 4 != currentChunk.chunkY || blockZ >> 4 != currentChunk.chunkZ) {
currentChunk.updateFrom(current);
currentOcclusionView = snap.getChunkOcclusionView(currentChunk.chunkX, currentChunk.chunkY, currentChunk.chunkZ);
}
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded++;
rayAdvancer.advance();
current.advance(direction);
blockX = current.blockX();
blockY = current.blockY();
blockZ = current.blockZ();
if (blockX >> 4 != currentChunk.chunkX || blockY >> 4 != currentChunk.chunkY || blockZ >> 4 != currentChunk.chunkZ) {
currentChunk.updateFrom(current);
currentOcclusionView = snap.getChunkOcclusionView(currentChunk.chunkX, currentChunk.chunkY, currentChunk.chunkZ);
}
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded++;
rayAdvancer.advance();
if (occluded >= maxOccluding) return false;
if (rayAdvancer.occluded >= maxOccluding) return false;
traveled += fourSteps;
}
for (; traveled < finalDist; traveled += stepSize) {
rayAdvancer.advance();
}
return rayAdvancer.occluded < maxOccluding;
}
private static final class RayAdvancer {
private final RayPosition current;
private final RayDirection direction;
private final RayChunkSection currentChunk;
private final BlockView blockView;
private ChunkOcclusionView currentOcclusionView;
private int occluded = 0;
private RayAdvancer(RayPosition rayPosition, RayDirection rayDirection, BlockView blockView) {
current = rayPosition;
direction = rayDirection;
currentChunk = new RayChunkSection().updateFrom(current);
currentOcclusionView = blockView.getChunkOcclusionView(currentChunk.chunkX, currentChunk.chunkY, currentChunk.chunkZ);
this.blockView = blockView;
}
private void advance() {
current.advance(direction);
int blockX = current.blockX();
int blockY = current.blockY();
int blockZ = current.blockZ();
if (blockX >> 4 != currentChunk.chunkX || blockY >> 4 != currentChunk.chunkY || blockZ >> 4 != currentChunk.chunkZ) {
currentChunk.updateFrom(current);
currentOcclusionView = snap.getChunkOcclusionView(currentChunk.chunkX, currentChunk.chunkY, currentChunk.chunkZ);
currentOcclusionView = blockView.getChunkOcclusionView(currentChunk.chunkX, currentChunk.chunkY, currentChunk.chunkZ);
}
if (currentOcclusionView != null && currentOcclusionView.isOccludingGlobal(blockX, blockY, blockZ)) occluded++;
}
return occluded < maxOccluding;
}
private static final class RayPosition {
Submodule leafpile updated: dca89261e9...d49fa5bc39.
@@ -8,6 +8,7 @@
package games.cubi.raycastedantiesp.packetevents.viewcontrollers;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityMetadata;
import games.cubi.logs.Logger;
@@ -33,6 +34,12 @@ final class PECacheablePacketReconciliationTask extends BaseEntitySpawnTask {
NettyEntity<?> entity = playerData.entityFromID(entityID);
if (entity == null) {
Logger.error("Reconciliation fail: Attempted to cache packet for unknown entity, id=" + entityID + " packet=" + packet.getClass().getSimpleName() + ".", 3, this.getClass());
if (packet instanceof WrapperPlayServerEntityMetadata metadataPacket) {
var data = metadataPacket.getEntityMetadata();
for (EntityData<?> eData : data) {
Logger.debug("Index:"+eData.getIndex()+"Type:"+eData.getType()+"Value:"+eData.getValue());
}
}
return;
}
if (packet instanceof WrapperPlayServerEntityMetadata metadataPacket) {
-4
View File
@@ -21,7 +21,6 @@ repositories {
maven { url = uri("https://repo.codemc.io/repository/maven-releases/") }
maven { url = uri("https://repo.codemc.io/repository/maven-snapshots/") }
maven { url = uri("https://eldonexus.de/repository/maven-public/") }
maven("https://repo.fancyinnovations.com/releases")
}
dependencies {
@@ -31,9 +30,6 @@ dependencies {
compileOnly("org.spongepowered:configurate-core:4.2.0")
compileOnly("org.spongepowered:configurate-yaml:4.2.0")
compileOnly("de.oliver:FancyHolograms:2.9.1")
compileOnly("de.oliver:FancyNpcs:2.9.2")
compileOnly("net.strokkur.commands:annotations-paper:2.1.2")
annotationProcessor("net.strokkur.commands:processor-paper:2.1.2")
@@ -17,9 +17,10 @@ import games.cubi.raycastedantiesp.core.players.PlayerRegistry;
import games.cubi.raycastedantiesp.paper.engine.PaperAsyncEngine;
import games.cubi.raycastedantiesp.core.players.PlayerData;
import games.cubi.raycastedantiesp.paper.utils.PaperListener;
import games.cubi.utils.events.CancellableEvent;
import games.cubi.utils.events.CancellableEventRegistry;
import io.papermc.paper.event.player.PlayerClientLoadedWorldEvent;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -44,6 +45,9 @@ public class EventListener extends PaperListener {
this.plugin = plugin;
this.engine = engine;
this.currentTickSupplier = currentTickSupplier;
playerValidityCheckEventRegistry.register(CancellableEventRegistry.Order.NORMAL, (event) -> {
if (event.player.hasMetadata("NPC")) event.cancel();
});
}
public static EventListener initialise(RaycastedAntiESP plugin, PaperAsyncEngine engine, IntSupplier currentTickSupplier) {
@@ -58,11 +62,23 @@ public class EventListener extends PaperListener {
EntityBypassRegistry.markEntityDespawned(event.getEntity().getEntityId());
}
public static final class PlayerValidityCheckEvent extends CancellableEvent {
public final Player player;
PlayerValidityCheckEvent(Player player) {
this.player = player;
}
}
/**
* If this event is cancelled, player join processing will be skipped for this entity
*/
public static final CancellableEventRegistry<PlayerValidityCheckEvent> playerValidityCheckEventRegistry = new CancellableEventRegistry<PlayerValidityCheckEvent>();
@EventHandler(priority = EventPriority.LOWEST) //Runs first
public void onPlayerJoin(PlayerClientLoadedWorldEvent e) {
Player player = e.getPlayer();
if (player.hasMetadata("NPC")) return;
if (!playerValidityCheckEventRegistry.dispatch(new PlayerValidityCheckEvent(player))) return;
PlayerData playerData = PlayerRegistry.getInstance().getPlayerData(player.getUniqueId());
if (playerData == null) {
@@ -73,7 +89,7 @@ public class EventListener extends PaperListener {
if (ConfigManager.get().getUpdateConfig().notifyInGame()
&& player.hasPermission("raycastedantiesp.updatecheck")
&& (playerData.getJoinTick() - currentTickSupplier.getAsInt() < 10)) { //todo: centralise permission strings to prevent issues when perm names are changed
&& (currentTickSupplier.getAsInt() - playerData.getJoinTick() < 10)) { //todo: centralise permission strings to prevent issues when perm names are changed
checkForUpdates(plugin, player);
}
@@ -1,78 +0,0 @@
/*
* SPDX-License-Identifier: AGPL-3.0-only
* Copyright © 2026 Cubicake.
* This file is part of RaycastedAntiESP.
* RaycastedAntiESP is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License v3.0 only, which can be accessed at https://www.gnu.org/licenses/agpl-3.0.html.
* See README.md for warranty disclaimer and further information.
*/
package games.cubi.raycastedantiesp.paper;
import de.oliver.fancyholograms.api.events.*;
import de.oliver.fancyholograms.api.hologram.Hologram;
import de.oliver.fancynpcs.api.events.NpcCreateEvent;
import de.oliver.fancynpcs.api.events.NpcModifyEvent;
import de.oliver.fancynpcs.api.events.NpcSpawnEvent;
import games.cubi.logs.Logger;
import games.cubi.raycastedantiesp.core.entity.EntityBypassRegistry;
import games.cubi.raycastedantiesp.paper.utils.PaperListener;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
// Entity remove events aren't listened to because the event names are a bit confusing to me and I'm unclear when each event is called.
// This should not be an issue as NPCs and Holograms are typically static entities which are not spawned or unspawned.
public class FancyCompatibility {
FancyCompatibility() {
Logger.info("Attempting to initiate FancyNPCs and FancyHolograms compatibility layer. If you are not using those plugins, you will see an error. This is safe to ignore.", 5);
new NPCs();
new Holograms();
}
static class NPCs extends PaperListener {
@EventHandler(priority = EventPriority.LOWEST)
public void npcLoad(NpcSpawnEvent event) {
int id = event.getNpc().getEntityId();
Logger.info("NpcSpawnEvent called, adding entity: " + id, 1);
EntityBypassRegistry.addEntity(id);
}
@EventHandler(priority = EventPriority.LOWEST)
public void npcLoad(NpcCreateEvent event) {
int id = event.getNpc().getEntityId();
Logger.info("NpcCreateEvent called, adding entity: " + id, 1);
EntityBypassRegistry.addEntity(id);
}
@EventHandler(priority = EventPriority.LOWEST)
public void npcLoad(NpcModifyEvent event) {
int id = event.getNpc().getEntityId();
Logger.info("NpcModifyEvent called, adding entity: " + id, 1);
EntityBypassRegistry.addEntity(id);
}
}
static class Holograms extends PaperListener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onHologramCreate(HologramCreateEvent event) {
add(event.getHologram());
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onHologramShow(HologramShowEvent event) {
add(event.getHologram());
}
@EventHandler(priority = EventPriority.LOWEST)
public void onHologramsLoaded(HologramsLoadedEvent event) {
event.getManager().forEach(this::add);
}
private void add(Hologram hologram) {
int id = hologram.getEntityId();
Logger.info("Hologram event called, adding entity: " + id, 1);
EntityBypassRegistry.addEntity(id);
}
}
}
@@ -32,6 +32,11 @@ public class PaperParticleSpawner implements ParticleSpawner {
world.spawnParticle(Particle.DUST, spatial.x(), spatial.y(), spatial.z(), 0, toBukkitDust(colour));
}
public void spawnParticleAt(UUID worldUUID, double x, double y, double z, Colour colour) {
World world = Logger.requireNonNull(LocatableAdapterUtils.getWorld(worldUUID), "UUID resolved to nonexistent world", 2, PaperParticleSpawner.class);
world.spawnParticle(Particle.DUST, x, y, z, 0, toBukkitDust(colour));
}
private static final Particle.DustOptions RED_DUST = new Particle.DustOptions(Color.RED, 1);
private static final Particle.DustOptions GREEN_DUST = new Particle.DustOptions(Color.GREEN, 1);
private static final Particle.DustOptions BLUE_DUST = new Particle.DustOptions(Color.BLUE, 1);
@@ -120,7 +120,6 @@ public final class RaycastedAntiESP extends JavaPlugin implements CommandExecuto
}
}, 1200, 1200);*/
/*Do not delete, this is a legal notice*/Attribution.sendAttributionMessage(Bukkit.getConsoleSender()); // Legal notice as required by AGPLv3, it prominently offers users of this plugin the source code and displays an appropriate copyright notice. If you are a fork developer, do NOT remove this unless you have a thorough understanding of the AGPL and have replaced it with a suitable equivalent notice which is "prominently visible", displays the copyright notice, and includes a link to the source code of your fork which is accessible to all users of the plugin.
new FancyCompatibility();
}
private String parseTrackers(Set<Player> trackers) {
@@ -69,7 +69,8 @@ public class PacketEventsPaperBlockInfoResolver implements BlockInfoResolver {
run = false;
continue;
}
if (blockData.getMaterial() == Material.AIR) {
Material material = blockData.getMaterial();
if (material == Material.AIR) {
airs++;
if (airs > 80000) { // There is a sequence of ~40 air blocks around ID 100, and another of several hundred at ~3000. We scan forwards 80k to future-proof any mojank. Since it runs once at startup, perf is irrelevant here
run = false;
@@ -79,12 +80,12 @@ public class PacketEventsPaperBlockInfoResolver implements BlockInfoResolver {
else {
airs = 0;
lastNonAirID = iterator;
if (materialToIDMode) {
Logger.info(blockData.getAsString() + iterator,1);
}
}
occlusion.put(iterator, blockData.getMaterial().isOccluding());
boolean occluding = material != Material.BARRIER && material.isOccluding();
if (materialToIDMode && material != Material.AIR) {
Logger.info(blockData.getAsString() + iterator + occluding,1);
}
occlusion.put(iterator, occluding);
try {
if (blockData.createBlockState() instanceof TileState) {
//Logger.debug("tile at" + iterator + " is tile entity" + material.name());
+1 -1
View File
@@ -71,7 +71,7 @@ checks:
hide-on-spawn-distance: 24
visible-recheck-interval-ticks: -1 # -1 disables visible rechecks. When set to -1, once an entity is shown by any mechanism, it will be permanently visible.
sound-effects:
enabled: true
enabled: false
max-occluding-count: 3
always-play-radius: 8
raycast-radius: 48