From 886e4f56b5844bbc7933d3077a852e835b92f52c Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sun, 24 Sep 2023 12:35:16 +1000 Subject: [PATCH] Readd anti xray and oversized block entity patches --- ...llow-delegation-to-vanilla-chunk-gen.patch | 2 +- .../{unapplied => }/server/Anti-Xray.patch | 55 ++++++------------- ...culate-regionfile-header-if-it-is-co.patch | 2 +- patches/server/Collision-optimisations.patch | 2 +- ...le-Oversized-Tile-Entities-in-chunks.patch | 6 +- .../Optimise-random-block-ticking.patch | 4 +- .../Player-Chunk-Load-Unload-Events.patch | 10 ++-- ...ttedContainer-instead-of-ThreadingDe.patch | 16 +++--- ...etChunkIfLoadedImmediately-in-places.patch | 2 +- 9 files changed, 40 insertions(+), 59 deletions(-) rename patches/{unapplied => }/server/Anti-Xray.patch (96%) rename patches/{unapplied => }/server/Handle-Oversized-Tile-Entities-in-chunks.patch (94%) diff --git a/patches/server/Allow-delegation-to-vanilla-chunk-gen.patch b/patches/server/Allow-delegation-to-vanilla-chunk-gen.patch index 5ad66808e1..ae88eca2fb 100644 --- a/patches/server/Allow-delegation-to-vanilla-chunk-gen.patch +++ b/patches/server/Allow-delegation-to-vanilla-chunk-gen.patch @@ -9,7 +9,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -0,0 +0,0 @@ public final class CraftServer implements Server { - return new OldCraftChunkData(world.getMinHeight(), world.getMaxHeight(), handle.registryAccess().registryOrThrow(Registries.BIOME)); + return new OldCraftChunkData(world.getMinHeight(), world.getMaxHeight(), handle.registryAccess().registryOrThrow(Registries.BIOME), world); // Paper - Anti-Xray - Add parameters } + // Paper start diff --git a/patches/unapplied/server/Anti-Xray.patch b/patches/server/Anti-Xray.patch similarity index 96% rename from patches/unapplied/server/Anti-Xray.patch rename to patches/server/Anti-Xray.patch index b4b6e5f001..9449a49e2c 100644 --- a/patches/unapplied/server/Anti-Xray.patch +++ b/patches/server/Anti-Xray.patch @@ -1099,41 +1099,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } public ClientboundLevelChunkWithLightPacket(FriendlyByteBuf buf) { -diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/net/minecraft/server/level/ChunkMap.java -+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java -@@ -0,0 +0,0 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider - - } - -- public void updateChunkTracking(ServerPlayer player, ChunkPos pos, MutableObject packet, boolean oldWithinViewDistance, boolean newWithinViewDistance) { // Paper - public -+ public void updateChunkTracking(ServerPlayer player, ChunkPos pos, MutableObject> packet, boolean oldWithinViewDistance, boolean newWithinViewDistance) { // Paper - public // Paper - Anti-Xray - Bypass - io.papermc.paper.util.TickThread.ensureTickThread(this.level, pos, "May not update chunk tracking for chunk async"); // Paper - replace chunk loader system - io.papermc.paper.util.TickThread.ensureTickThread(player, "May not update chunk tracking for player async"); // Paper - replace chunk loader system - if (player.level() == this.level) { -@@ -0,0 +0,0 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider - }); - } - -- private void playerLoadedChunk(ServerPlayer player, MutableObject cachedDataPacket, LevelChunk chunk) { -- if (cachedDataPacket.getValue() == null) { -- cachedDataPacket.setValue(new ClientboundLevelChunkWithLightPacket(chunk, this.lightEngine, (BitSet) null, (BitSet) null)); -+ // Paper start - Anti-Xray - Bypass -+ private void playerLoadedChunk(ServerPlayer player, MutableObject> cachedDataPackets, LevelChunk chunk) { -+ if (cachedDataPackets.getValue() == null) { -+ cachedDataPackets.setValue(new java.util.HashMap<>()); - } - -- player.trackChunk(chunk.getPos(), (Packet) cachedDataPacket.getValue()); -+ Boolean shouldModify = chunk.getLevel().chunkPacketBlockController.shouldModify(player, chunk); -+ player.trackChunk(chunk.getPos(), (Packet) cachedDataPackets.getValue().computeIfAbsent(shouldModify, (s) -> { -+ return new ClientboundLevelChunkWithLightPacket(chunk, this.lightEngine, (BitSet) null, (BitSet) null, (Boolean) s); -+ })); -+ // Paper end - DebugPackets.sendPoiPacketsForChunk(this.level, chunk.getPos()); - List list = Lists.newArrayList(); - List list1 = Lists.newArrayList(); diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/server/level/ServerLevel.java @@ -1169,6 +1134,22 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 } public void destroyAndAck(BlockPos pos, int sequence, String reason) { +diff --git a/src/main/java/net/minecraft/server/network/PlayerChunkSender.java b/src/main/java/net/minecraft/server/network/PlayerChunkSender.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/net/minecraft/server/network/PlayerChunkSender.java ++++ b/src/main/java/net/minecraft/server/network/PlayerChunkSender.java +@@ -0,0 +0,0 @@ public class PlayerChunkSender { + + public static void sendChunk(ServerGamePacketListenerImpl handler, ServerLevel world, LevelChunk chunk) { // Paper - rewrite chunk loader - public + handler.player.serverLevel().chunkSource.chunkMap.getVisibleChunkIfPresent(chunk.getPos().toLong()).addPlayer(handler.player); +- handler.send(new ClientboundLevelChunkWithLightPacket(chunk, world.getLightEngine(), (BitSet)null, (BitSet)null)); ++ // Paper start - Anti-Xray ++ final boolean shouldModify = world.chunkPacketBlockController.shouldModify(handler.player, chunk); ++ handler.send(new ClientboundLevelChunkWithLightPacket(chunk, world.getLightEngine(), (BitSet)null, (BitSet)null, shouldModify)); ++ // Paper end - Anti-Xray + ChunkPos chunkPos = chunk.getPos(); + DebugPackets.sendPoiPacketsForChunk(world, chunkPos); + } diff --git a/src/main/java/net/minecraft/world/level/Level.java b/src/main/java/net/minecraft/world/level/Level.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/Level.java @@ -1470,7 +1451,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @Override @@ -0,0 +0,0 @@ public class PalettedContainer implements PaletteResize, PalettedContainer - return 1 + this.palette.getSerializedSize() + FriendlyByteBuf.getVarIntSize(this.storage.getSize()) + this.storage.getRaw().length * 8; + return 1 + this.palette.getSerializedSize() + VarInt.getByteSize(this.storage.getRaw().length) + this.storage.getRaw().length * 8; } - public void write(FriendlyByteBuf buf) { @@ -1482,7 +1463,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (chunkPacketInfo != null) { + chunkPacketInfo.setBits(chunkSectionIndex, this.configuration.bits()); + chunkPacketInfo.setPalette(chunkSectionIndex, this.palette); -+ chunkPacketInfo.setIndex(chunkSectionIndex, buf.writerIndex() + FriendlyByteBuf.getVarIntSize(this.storage.getRaw().length)); ++ chunkPacketInfo.setIndex(chunkSectionIndex, buf.writerIndex() + VarInt.getByteSize(this.storage.getRaw().length)); + } + // Paper end + diff --git a/patches/server/Attempt-to-recalculate-regionfile-header-if-it-is-co.patch b/patches/server/Attempt-to-recalculate-regionfile-header-if-it-is-co.patch index 4d4e8748b7..816b86f218 100644 --- a/patches/server/Attempt-to-recalculate-regionfile-header-if-it-is-co.patch +++ b/patches/server/Attempt-to-recalculate-regionfile-header-if-it-is-co.patch @@ -30,7 +30,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + // Paper end - public static final Codec> BLOCK_STATE_CODEC = PalettedContainer.codecRW(Block.BLOCK_STATE_REGISTRY, BlockState.CODEC, PalettedContainer.Strategy.SECTION_STATES, Blocks.AIR.defaultBlockState()); + public static final Codec> BLOCK_STATE_CODEC = PalettedContainer.codecRW(Block.BLOCK_STATE_REGISTRY, BlockState.CODEC, PalettedContainer.Strategy.SECTION_STATES, Blocks.AIR.defaultBlockState(), null); // Paper - Anti-Xray - Add preset block states private static final Logger LOGGER = LogUtils.getLogger(); @@ -0,0 +0,0 @@ public class ChunkSerializer { nbttagcompound.putInt("xPos", chunkcoordintpair.x); diff --git a/patches/server/Collision-optimisations.patch b/patches/server/Collision-optimisations.patch index 21f8c6f109..48023fe3a2 100644 --- a/patches/server/Collision-optimisations.patch +++ b/patches/server/Collision-optimisations.patch @@ -2633,9 +2633,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/net/minecraft/world/level/Level.java +++ b/src/main/java/net/minecraft/world/level/Level.java @@ -0,0 +0,0 @@ public abstract class Level implements LevelAccessor, AutoCloseable { - this.keepSpawnInMemory = this.paperConfig().spawn.keepSpawnLoaded; // Paper this.entityLimiter = new org.spigotmc.TickLimiter(spigotConfig.entityMaxTickTime); this.tileLimiter = new org.spigotmc.TickLimiter(spigotConfig.tileMaxTickTime); + this.chunkPacketBlockController = this.paperConfig().anticheat.antiXray.enabled ? new com.destroystokyo.paper.antixray.ChunkPacketBlockControllerAntiXray(this, executor) : com.destroystokyo.paper.antixray.ChunkPacketBlockController.NO_OPERATION_INSTANCE; // Paper - Anti-Xray + // Paper start - optimise collisions + this.minSection = io.papermc.paper.util.WorldUtil.getMinSection(this); + this.maxSection = io.papermc.paper.util.WorldUtil.getMaxSection(this); diff --git a/patches/unapplied/server/Handle-Oversized-Tile-Entities-in-chunks.patch b/patches/server/Handle-Oversized-Tile-Entities-in-chunks.patch similarity index 94% rename from patches/unapplied/server/Handle-Oversized-Tile-Entities-in-chunks.patch rename to patches/server/Handle-Oversized-Tile-Entities-in-chunks.patch index 638d5681dc..afdc83526b 100644 --- a/patches/unapplied/server/Handle-Oversized-Tile-Entities-in-chunks.patch +++ b/patches/server/Handle-Oversized-Tile-Entities-in-chunks.patch @@ -17,10 +17,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 private final byte[] buffer; private final List blockEntitiesData; + // Paper start -+ private final java.util.List extraPackets = new java.util.ArrayList<>(); ++ private final java.util.List> extraPackets = new java.util.ArrayList<>(); + private static final int TE_LIMIT = Integer.getInteger("Paper.excessiveTELimit", 750); + -+ public List getExtraPackets() { ++ public List> getExtraPackets() { + return this.extraPackets; + } + // Paper end @@ -57,7 +57,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + // Paper start - handle over-sized TE packets + @Override -+ public java.util.List getExtraPackets() { ++ public java.util.List> getExtraPackets() { + return this.chunkData.getExtraPackets(); + } + // Paper end diff --git a/patches/server/Optimise-random-block-ticking.patch b/patches/server/Optimise-random-block-ticking.patch index 6a32121c48..61ab89d98d 100644 --- a/patches/server/Optimise-random-block-ticking.patch +++ b/patches/server/Optimise-random-block-ticking.patch @@ -422,9 +422,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 - } - } -- -- a a0 = new a(); +- a a0 = new a(); +- - this.states.count(a0); - this.nonEmptyBlockCount = (short) a0.nonEmptyBlockCount; - this.tickingBlockCount = (short) a0.tickingBlockCount; diff --git a/patches/server/Player-Chunk-Load-Unload-Events.patch b/patches/server/Player-Chunk-Load-Unload-Events.patch index 55bd80cf94..85828f1e7f 100644 --- a/patches/server/Player-Chunk-Load-Unload-Events.patch +++ b/patches/server/Player-Chunk-Load-Unload-Events.patch @@ -21,14 +21,14 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 // Paper end - rewrite player chunk loader @@ -0,0 +0,0 @@ public class PlayerChunkSender { - public static void sendChunk(ServerGamePacketListenerImpl handler, ServerLevel world, LevelChunk chunk) { // Paper - rewrite chunk loader - public - handler.player.serverLevel().chunkSource.chunkMap.getVisibleChunkIfPresent(chunk.getPos().toLong()).addPlayer(handler.player); - handler.send(new ClientboundLevelChunkWithLightPacket(chunk, world.getLightEngine(), (BitSet)null, (BitSet)null)); -+ // Paper start + final boolean shouldModify = world.chunkPacketBlockController.shouldModify(handler.player, chunk); + handler.send(new ClientboundLevelChunkWithLightPacket(chunk, world.getLightEngine(), (BitSet)null, (BitSet)null, shouldModify)); + // Paper end - Anti-Xray ++ // Paper start - PlayerChunkLoadEvent + if (io.papermc.paper.event.packet.PlayerChunkLoadEvent.getHandlerList().getRegisteredListeners().length > 0) { + new io.papermc.paper.event.packet.PlayerChunkLoadEvent(new org.bukkit.craftbukkit.CraftChunk(chunk), handler.getPlayer().getBukkitEntity()).callEvent(); + } -+ // Paper end ++ // Paper end - PlayerChunkLoadEvent ChunkPos chunkPos = chunk.getPos(); DebugPackets.sendPoiPacketsForChunk(world, chunkPos); } diff --git a/patches/server/Synchronize-PalettedContainer-instead-of-ThreadingDe.patch b/patches/server/Synchronize-PalettedContainer-instead-of-ThreadingDe.patch index 1685367dfe..61d806d98a 100644 --- a/patches/server/Synchronize-PalettedContainer-instead-of-ThreadingDe.patch +++ b/patches/server/Synchronize-PalettedContainer-instead-of-ThreadingDe.patch @@ -18,7 +18,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java +++ b/src/main/java/net/minecraft/world/level/chunk/PalettedContainer.java @@ -0,0 +0,0 @@ public class PalettedContainer implements PaletteResize, PalettedContainer - public final IdMap registry; + private final T @org.jetbrains.annotations.Nullable [] presetValues; // Paper - Anti-Xray - Add preset values private volatile PalettedContainer.Data data; private final PalettedContainer.Strategy strategy; - private final ThreadingDetector threadingDetector = new ThreadingDetector("PalettedContainer"); @@ -34,7 +34,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // this.threadingDetector.checkAndUnlock(); // Paper - disable this } - public static Codec> codecRW(IdMap idList, Codec entryCodec, PalettedContainer.Strategy paletteProvider, T defaultValue) { + // Paper start - Anti-Xray - Add preset values @@ -0,0 +0,0 @@ public class PalettedContainer implements PaletteResize, PalettedContainer } @@ -42,8 +42,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 - public int onResize(int newBits, T object) { + public synchronized int onResize(int newBits, T object) { // Paper - synchronize PalettedContainer.Data data = this.data; - PalettedContainer.Data data2 = this.createOrReuseData(data, newBits); - data2.copyFrom(data.palette, data.storage); + + // Paper start - Anti-Xray - Add preset values @@ -0,0 +0,0 @@ public class PalettedContainer implements PaletteResize, PalettedContainer return this.getAndSet(this.strategy.getIndex(x, y, z), value); } @@ -72,11 +72,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 try { @@ -0,0 +0,0 @@ public class PalettedContainer implements PaletteResize, PalettedContainer - } - @Override -- public void write(FriendlyByteBuf buf) { -+ public synchronized void write(FriendlyByteBuf buf) { // Paper - synchronize + @Deprecated @io.papermc.paper.annotation.DoNotUse public void write(FriendlyByteBuf buf) { this.write(buf, null, 0); } + @Override +- public void write(FriendlyByteBuf buf, @Nullable com.destroystokyo.paper.antixray.ChunkPacketInfo chunkPacketInfo, int chunkSectionIndex) { ++ public synchronized void write(FriendlyByteBuf buf, @Nullable com.destroystokyo.paper.antixray.ChunkPacketInfo chunkPacketInfo, int chunkSectionIndex) { // Paper - synchronize this.acquire(); try { diff --git a/patches/server/Use-getChunkIfLoadedImmediately-in-places.patch b/patches/server/Use-getChunkIfLoadedImmediately-in-places.patch index 6fadb1fc8f..196e898ad3 100644 --- a/patches/server/Use-getChunkIfLoadedImmediately-in-places.patch +++ b/patches/server/Use-getChunkIfLoadedImmediately-in-places.patch @@ -37,7 +37,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public abstract ResourceKey getTypeKey(); - protected Level(WritableLevelData worlddatamutable, ResourceKey resourcekey, RegistryAccess iregistrycustom, Holder holder, Supplier supplier, boolean flag, boolean flag1, long i, int j, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider, org.bukkit.World.Environment env, java.util.function.Function paperWorldConfigCreator) { // Paper + protected Level(WritableLevelData worlddatamutable, ResourceKey resourcekey, RegistryAccess iregistrycustom, Holder holder, Supplier supplier, boolean flag, boolean flag1, long i, int j, org.bukkit.generator.ChunkGenerator gen, org.bukkit.generator.BiomeProvider biomeProvider, org.bukkit.World.Environment env, java.util.function.Function paperWorldConfigCreator, java.util.concurrent.Executor executor) { // Paper - Async-Anti-Xray - Pass executor diff --git a/src/main/java/net/minecraft/world/level/gameevent/GameEventDispatcher.java b/src/main/java/net/minecraft/world/level/gameevent/GameEventDispatcher.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/net/minecraft/world/level/gameevent/GameEventDispatcher.java