mirror of
https://github.com/PaperMC/Paper.git
synced 2025-04-26 22:06:20 +02:00
Correctly track raw data reader index for antixray
The written buffer no longer prefixes the byte[] with the varint len.
This commit is contained in:
parent
e8eba887f4
commit
212dfc9418
4 changed files with 31 additions and 33 deletions
|
@ -5,7 +5,7 @@ Subject: [PATCH] Anti-Xray
|
|||
|
||||
|
||||
diff --git a/io/papermc/paper/FeatureHooks.java b/io/papermc/paper/FeatureHooks.java
|
||||
index d153f707429ee816da82f8ca711c1dc88c40e123..30eced048bb49368076e37eb9a36ae28909d97a6 100644
|
||||
index b9a838d638571bca1d00a620cedf169a3fa87e9d..329e9562e9c2b25228b04c21ff7353d2d8d6e5f6 100644
|
||||
--- a/io/papermc/paper/FeatureHooks.java
|
||||
+++ b/io/papermc/paper/FeatureHooks.java
|
||||
@@ -37,20 +37,25 @@ public final class FeatureHooks {
|
||||
|
@ -55,10 +55,10 @@ index d4872b7f4e9591b3b1c67406312905851303f521..cb41460e94161675e2ab43f4b1b5286e
|
|||
}
|
||||
|
||||
diff --git a/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java b/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
|
||||
index 89761bd368d75b8fb84f850fb3f8162fa280e236..625caeeceaa0abfa942fd37b0646089c932a2641 100644
|
||||
index 89761bd368d75b8fb84f850fb3f8162fa280e236..272da41db7ce4619a8e459a2f0a2221e42f58a40 100644
|
||||
--- a/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
|
||||
+++ b/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
|
||||
@@ -33,13 +33,24 @@ public class ClientboundLevelChunkPacketData {
|
||||
@@ -33,13 +33,23 @@ public class ClientboundLevelChunkPacketData {
|
||||
private final byte[] buffer;
|
||||
private final List<ClientboundLevelChunkPacketData.BlockEntityInfo> blockEntitiesData;
|
||||
|
||||
|
@ -73,7 +73,6 @@ index 89761bd368d75b8fb84f850fb3f8162fa280e236..625caeeceaa0abfa942fd37b0646089c
|
|||
.stream()
|
||||
.filter(entry1 -> entry1.getKey().sendToClient())
|
||||
.collect(Collectors.toMap(Entry::getKey, entry1 -> (long[])entry1.getValue().getRawData().clone()));
|
||||
+
|
||||
this.buffer = new byte[calculateChunkSize(levelChunk)];
|
||||
- extractChunkData(new FriendlyByteBuf(this.getWriteBuffer()), levelChunk);
|
||||
+ // Paper start - Anti-Xray - Add chunk packet info
|
||||
|
@ -84,7 +83,7 @@ index 89761bd368d75b8fb84f850fb3f8162fa280e236..625caeeceaa0abfa942fd37b0646089c
|
|||
this.blockEntitiesData = Lists.newArrayList();
|
||||
|
||||
for (Entry<BlockPos, BlockEntity> entry : levelChunk.getBlockEntities().entrySet()) {
|
||||
@@ -82,9 +93,17 @@ public class ClientboundLevelChunkPacketData {
|
||||
@@ -82,9 +92,17 @@ public class ClientboundLevelChunkPacketData {
|
||||
return byteBuf;
|
||||
}
|
||||
|
||||
|
@ -273,7 +272,7 @@ index 8fa871512ad52c345f15b1f5fb1baf54bb2ec93b..08e2442f6965cc6eaab67bdf9340a515
|
|||
this.gameEventListenerRegistrySections = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
diff --git a/net/minecraft/world/level/chunk/LevelChunkSection.java b/net/minecraft/world/level/chunk/LevelChunkSection.java
|
||||
index 2399a0f8839c0925a9923bae87362c2c9a217197..84bc77939865d35d166545b3caf257a27a27105f 100644
|
||||
index 2399a0f8839c0925a9923bae87362c2c9a217197..1aa4e39431a93a7789b74a2e3476a3e47605e2cc 100644
|
||||
--- a/net/minecraft/world/level/chunk/LevelChunkSection.java
|
||||
+++ b/net/minecraft/world/level/chunk/LevelChunkSection.java
|
||||
@@ -38,9 +38,15 @@ public class LevelChunkSection {
|
||||
|
@ -309,12 +308,12 @@ index 2399a0f8839c0925a9923bae87362c2c9a217197..84bc77939865d35d166545b3caf257a2
|
|||
- this.biomes.write(buffer);
|
||||
+ this.states.write(buffer, chunkPacketInfo, chunkSectionIndex);
|
||||
+ this.biomes.write(buffer, null, chunkSectionIndex);
|
||||
+ // Paper end - Anti-Xray
|
||||
+ // Paper end - Anti-Xray - Add chunk packet info
|
||||
}
|
||||
|
||||
public int getSerializedSize() {
|
||||
diff --git a/net/minecraft/world/level/chunk/PalettedContainer.java b/net/minecraft/world/level/chunk/PalettedContainer.java
|
||||
index 5a3ed1c2dd22434d96947580c4dff28a95eb8252..6781df510906f4e7e51ea852f3d2f6dcbea42b3b 100644
|
||||
index 5a3ed1c2dd22434d96947580c4dff28a95eb8252..1491401ec94038450ea5eeb589fc33a336a3ae55 100644
|
||||
--- a/net/minecraft/world/level/chunk/PalettedContainer.java
|
||||
+++ b/net/minecraft/world/level/chunk/PalettedContainer.java
|
||||
@@ -28,6 +28,7 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
|
||||
|
@ -526,9 +525,9 @@ index 5a3ed1c2dd22434d96947580c4dff28a95eb8252..6781df510906f4e7e51ea852f3d2f6dc
|
|||
+ if (chunkPacketInfo != null) {
|
||||
+ chunkPacketInfo.setBits(chunkSectionIndex, this.configuration.bits());
|
||||
+ chunkPacketInfo.setPalette(chunkSectionIndex, this.palette);
|
||||
+ chunkPacketInfo.setIndex(chunkSectionIndex, buffer.writerIndex() + VarInt.getByteSize(this.storage.getRaw().length));
|
||||
+ chunkPacketInfo.setIndex(chunkSectionIndex, buffer.writerIndex());
|
||||
+ }
|
||||
+ // Paper end
|
||||
+ // Paper end - Anti-Xray - Add chunk packet info
|
||||
buffer.writeFixedSizeLongArray(this.storage.getRaw());
|
||||
}
|
||||
|
||||
|
@ -549,7 +548,7 @@ index bfbb1a2bb4abbb369a24f2f01439e9ea3e16794b..8d6ed8be4d93f7d4e6ea80c351020d88
|
|||
int getSerializedSize();
|
||||
|
||||
diff --git a/net/minecraft/world/level/chunk/storage/SerializableChunkData.java b/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
|
||||
index 8efb5148a22b57ed090fb8fd20dd642223b3fb95..34d072fe7464ae76f0a48c06ccc517746b97a6c2 100644
|
||||
index 8efb5148a22b57ed090fb8fd20dd642223b3fb95..58bc96235f0149ea868da3bc3d20472f96d5f6ec 100644
|
||||
--- a/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
|
||||
+++ b/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
|
||||
@@ -94,7 +94,7 @@ public record SerializableChunkData(
|
||||
|
@ -569,12 +568,11 @@ index 8efb5148a22b57ed090fb8fd20dd642223b3fb95..34d072fe7464ae76f0a48c06ccc51774
|
|||
if (tag.getString("Status").isEmpty()) {
|
||||
return null;
|
||||
} else {
|
||||
@@ -190,15 +191,18 @@ public record SerializableChunkData(
|
||||
@@ -190,15 +191,17 @@ public record SerializableChunkData(
|
||||
int byteOr = compoundTag.getByteOr("Y", (byte)0);
|
||||
LevelChunkSection levelChunkSection;
|
||||
if (byteOr >= levelHeightAccessor.getMinSectionY() && byteOr <= levelHeightAccessor.getMaxSectionY()) {
|
||||
+ // Paper start - Anti-Xray - Add preset block states
|
||||
+ final BlockState[] presetBlockStates = serverLevel.chunkPacketBlockController.getPresetBlockStates(serverLevel, chunkPos, byteOr);
|
||||
+ final BlockState[] presetBlockStates = serverLevel.chunkPacketBlockController.getPresetBlockStates(serverLevel, chunkPos, byteOr); // Paper - Anti-Xray - Add preset block states
|
||||
+ final Codec<PalettedContainer<BlockState>> blockStateCodec = presetBlockStates == null ? BLOCK_STATE_CODEC : PalettedContainer.codecRW(Block.BLOCK_STATE_REGISTRY, BlockState.CODEC, PalettedContainer.Strategy.SECTION_STATES, Blocks.AIR.defaultBlockState(), presetBlockStates); // Paper - Anti-Xray
|
||||
PalettedContainer<BlockState> palettedContainer = compoundTag.getCompound("block_states")
|
||||
.map(
|
||||
|
@ -590,7 +588,7 @@ index 8efb5148a22b57ed090fb8fd20dd642223b3fb95..34d072fe7464ae76f0a48c06ccc51774
|
|||
)
|
||||
);
|
||||
PalettedContainer<Holder<Biome>> palettedContainerRo = compoundTag.getCompound("biomes") // CraftBukkit - read/write
|
||||
@@ -209,7 +213,7 @@ public record SerializableChunkData(
|
||||
@@ -209,7 +212,7 @@ public record SerializableChunkData(
|
||||
)
|
||||
.orElseGet(
|
||||
() -> new PalettedContainer<>(
|
||||
|
@ -599,7 +597,7 @@ index 8efb5148a22b57ed090fb8fd20dd642223b3fb95..34d072fe7464ae76f0a48c06ccc51774
|
|||
)
|
||||
);
|
||||
levelChunkSection = new LevelChunkSection(palettedContainer, palettedContainerRo);
|
||||
@@ -382,7 +386,7 @@ public record SerializableChunkData(
|
||||
@@ -382,7 +385,7 @@ public record SerializableChunkData(
|
||||
|
||||
// CraftBukkit start - read/write
|
||||
private static Codec<PalettedContainer<Holder<Biome>>> makeBiomeCodecRW(Registry<Biome> biomeRegistry) {
|
||||
|
|
|
@ -9,7 +9,7 @@ creating too large of a packet to sed.
|
|||
Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
||||
|
||||
diff --git a/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java b/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
|
||||
index 625caeeceaa0abfa942fd37b0646089c932a2641..9e94256a031ccfdab74710018fa7b7a084bf25c6 100644
|
||||
index 272da41db7ce4619a8e459a2f0a2221e42f58a40..526c117e0d53ad527eb610c79cdc46ec16b18c0c 100644
|
||||
--- a/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
|
||||
+++ b/net/minecraft/network/protocol/game/ClientboundLevelChunkPacketData.java
|
||||
@@ -32,6 +32,14 @@ public class ClientboundLevelChunkPacketData {
|
||||
|
@ -27,7 +27,7 @@ index 625caeeceaa0abfa942fd37b0646089c932a2641..9e94256a031ccfdab74710018fa7b7a0
|
|||
|
||||
// Paper start - Anti-Xray - Add chunk packet info
|
||||
@Deprecated @io.papermc.paper.annotation.DoNotUse
|
||||
@@ -52,8 +60,18 @@ public class ClientboundLevelChunkPacketData {
|
||||
@@ -51,8 +59,18 @@ public class ClientboundLevelChunkPacketData {
|
||||
}
|
||||
extractChunkData(new FriendlyByteBuf(this.getWriteBuffer()), levelChunk, chunkPacketInfo);
|
||||
this.blockEntitiesData = Lists.newArrayList();
|
||||
|
|
|
@ -32470,7 +32470,7 @@ index 08e2442f6965cc6eaab67bdf9340a5152c08db2a..5d3fc807221392d378fec283bfdefb87
|
|||
|
||||
@Nullable
|
||||
diff --git a/net/minecraft/world/level/chunk/LevelChunkSection.java b/net/minecraft/world/level/chunk/LevelChunkSection.java
|
||||
index 84bc77939865d35d166545b3caf257a27a27105f..03edf6dc751cc59ae1f16c23340e41668350b32a 100644
|
||||
index 1aa4e39431a93a7789b74a2e3476a3e47605e2cc..df717c545472006b99532280c38c1fbef12bcf82 100644
|
||||
--- a/net/minecraft/world/level/chunk/LevelChunkSection.java
|
||||
+++ b/net/minecraft/world/level/chunk/LevelChunkSection.java
|
||||
@@ -13,7 +13,7 @@ import net.minecraft.world.level.block.Blocks;
|
||||
|
@ -32727,7 +32727,7 @@ index b4b973e453a093dcc04a6b7257883aa0065e2a89..a80b2e9dceea423180a9c390d1970317
|
|||
|
||||
boolean maybeHas(Predicate<T> filter);
|
||||
diff --git a/net/minecraft/world/level/chunk/PalettedContainer.java b/net/minecraft/world/level/chunk/PalettedContainer.java
|
||||
index 6781df510906f4e7e51ea852f3d2f6dcbea42b3b..95b5249fbd7e255a115403c3fbe88d402444b3cb 100644
|
||||
index 1491401ec94038450ea5eeb589fc33a336a3ae55..7da7ce0fd19896593e63edc88b492c02f926bba0 100644
|
||||
--- a/net/minecraft/world/level/chunk/PalettedContainer.java
|
||||
+++ b/net/minecraft/world/level/chunk/PalettedContainer.java
|
||||
@@ -29,7 +29,7 @@ public class PalettedContainer<T> implements PaletteResize<T>, PalettedContainer
|
||||
|
@ -33879,7 +33879,7 @@ index 7dc1ffffd9d0fec54dbc254c154ee85ee750174d..778bd73a938c94ecb85ca0f8b686ff4e
|
|||
|
||||
record PackedChunk<T>(Int2ObjectMap<T> sectionsByY, boolean versionChanged) {
|
||||
diff --git a/net/minecraft/world/level/chunk/storage/SerializableChunkData.java b/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
|
||||
index 34d072fe7464ae76f0a48c06ccc517746b97a6c2..47f8145ef36e05b9139c76bd692d605069405072 100644
|
||||
index 58bc96235f0149ea868da3bc3d20472f96d5f6ec..03d1527073cf827fc3e191915fe5f7f064e36c3b 100644
|
||||
--- a/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
|
||||
+++ b/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
|
||||
@@ -149,7 +149,7 @@ public record SerializableChunkData(
|
||||
|
@ -33900,7 +33900,7 @@ index 34d072fe7464ae76f0a48c06ccc517746b97a6c2..47f8145ef36e05b9139c76bd692d6050
|
|||
int byteOr = compoundTag.getByteOr("Y", (byte)0);
|
||||
LevelChunkSection levelChunkSection;
|
||||
if (byteOr >= levelHeightAccessor.getMinSectionY() && byteOr <= levelHeightAccessor.getMaxSectionY()) {
|
||||
@@ -223,7 +223,17 @@ public record SerializableChunkData(
|
||||
@@ -222,7 +222,17 @@ public record SerializableChunkData(
|
||||
|
||||
DataLayer dataLayer = compoundTag.getByteArray("BlockLight").map(DataLayer::new).orElse(null);
|
||||
DataLayer dataLayer1 = compoundTag.getByteArray("SkyLight").map(DataLayer::new).orElse(null);
|
||||
|
@ -33919,7 +33919,7 @@ index 34d072fe7464ae76f0a48c06ccc517746b97a6c2..47f8145ef36e05b9139c76bd692d6050
|
|||
}
|
||||
}
|
||||
|
||||
@@ -251,6 +261,59 @@ public record SerializableChunkData(
|
||||
@@ -250,6 +260,59 @@ public record SerializableChunkData(
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33979,7 +33979,7 @@ index 34d072fe7464ae76f0a48c06ccc517746b97a6c2..47f8145ef36e05b9139c76bd692d6050
|
|||
public ProtoChunk read(ServerLevel level, PoiManager poiManager, RegionStorageInfo regionStorageInfo, ChunkPos pos) {
|
||||
if (!Objects.equals(pos, this.chunkPos)) {
|
||||
LOGGER.error("Chunk file at {} is in the wrong location; relocating. (Expected {}, got {})", pos, pos, this.chunkPos);
|
||||
@@ -269,7 +332,7 @@ public record SerializableChunkData(
|
||||
@@ -268,7 +331,7 @@ public record SerializableChunkData(
|
||||
SectionPos sectionPos = SectionPos.of(pos, sectionData.y);
|
||||
if (sectionData.chunkSection != null) {
|
||||
levelChunkSections[level.getSectionIndexFromSectionY(sectionData.y)] = sectionData.chunkSection;
|
||||
|
@ -33988,7 +33988,7 @@ index 34d072fe7464ae76f0a48c06ccc517746b97a6c2..47f8145ef36e05b9139c76bd692d6050
|
|||
}
|
||||
|
||||
boolean flag1 = sectionData.blockLight != null;
|
||||
@@ -351,7 +414,7 @@ public record SerializableChunkData(
|
||||
@@ -350,7 +413,7 @@ public record SerializableChunkData(
|
||||
}
|
||||
|
||||
if (chunkType == ChunkType.LEVELCHUNK) {
|
||||
|
@ -33997,7 +33997,7 @@ index 34d072fe7464ae76f0a48c06ccc517746b97a6c2..47f8145ef36e05b9139c76bd692d6050
|
|||
} else {
|
||||
ProtoChunk protoChunk1 = (ProtoChunk)chunkAccess;
|
||||
|
||||
@@ -367,7 +430,7 @@ public record SerializableChunkData(
|
||||
@@ -366,7 +429,7 @@ public record SerializableChunkData(
|
||||
protoChunk1.setCarvingMask(new CarvingMask(this.carvingMask, chunkAccess.getMinY()));
|
||||
}
|
||||
|
||||
|
@ -34006,7 +34006,7 @@ index 34d072fe7464ae76f0a48c06ccc517746b97a6c2..47f8145ef36e05b9139c76bd692d6050
|
|||
}
|
||||
}
|
||||
|
||||
@@ -395,22 +458,48 @@ public record SerializableChunkData(
|
||||
@@ -394,22 +457,48 @@ public record SerializableChunkData(
|
||||
throw new IllegalArgumentException("Chunk can't be serialized: " + chunk);
|
||||
} else {
|
||||
ChunkPos pos = chunk.getPos();
|
||||
|
@ -34066,7 +34066,7 @@ index 34d072fe7464ae76f0a48c06ccc517746b97a6c2..47f8145ef36e05b9139c76bd692d6050
|
|||
|
||||
List<CompoundTag> list1 = new ArrayList<>(chunk.getBlockEntitiesPos().size());
|
||||
|
||||
@@ -496,7 +585,7 @@ public record SerializableChunkData(
|
||||
@@ -495,7 +584,7 @@ public record SerializableChunkData(
|
||||
Codec<PalettedContainerRO<Holder<Biome>>> codec = makeBiomeCodec(this.biomeRegistry);
|
||||
|
||||
for (SerializableChunkData.SectionData sectionData : this.sectionData) {
|
||||
|
@ -34075,7 +34075,7 @@ index 34d072fe7464ae76f0a48c06ccc517746b97a6c2..47f8145ef36e05b9139c76bd692d6050
|
|||
LevelChunkSection levelChunkSection = sectionData.chunkSection;
|
||||
if (levelChunkSection != null) {
|
||||
compoundTag1.store("block_states", BLOCK_STATE_CODEC, levelChunkSection.getStates());
|
||||
@@ -511,6 +600,19 @@ public record SerializableChunkData(
|
||||
@@ -510,6 +599,19 @@ public record SerializableChunkData(
|
||||
compoundTag1.putByteArray("SkyLight", sectionData.skyLight.getData());
|
||||
}
|
||||
|
||||
|
@ -34095,7 +34095,7 @@ index 34d072fe7464ae76f0a48c06ccc517746b97a6c2..47f8145ef36e05b9139c76bd692d6050
|
|||
if (!compoundTag1.isEmpty()) {
|
||||
compoundTag1.putByte("Y", (byte)sectionData.y);
|
||||
listTag.add(compoundTag1);
|
||||
@@ -545,6 +647,14 @@ public record SerializableChunkData(
|
||||
@@ -544,6 +646,14 @@ public record SerializableChunkData(
|
||||
compoundTag.put("ChunkBukkitValues", this.persistentDataContainer);
|
||||
}
|
||||
// CraftBukkit end
|
||||
|
@ -34110,7 +34110,7 @@ index 34d072fe7464ae76f0a48c06ccc517746b97a6c2..47f8145ef36e05b9139c76bd692d6050
|
|||
return compoundTag;
|
||||
}
|
||||
|
||||
@@ -682,6 +792,66 @@ public record SerializableChunkData(
|
||||
@@ -681,6 +791,66 @@ public record SerializableChunkData(
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -699,7 +699,7 @@ index 1649119f45d970a9bf1683d676c47ecfc18ad047..cc544f3199cd6af29e50362923d06517
|
|||
public static final RegionFileVersion VERSION_GZIP = register(
|
||||
new RegionFileVersion(
|
||||
diff --git a/net/minecraft/world/level/chunk/storage/SerializableChunkData.java b/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
|
||||
index 47f8145ef36e05b9139c76bd692d605069405072..cbb6d1f6e715316e170936d29b816c0e6b02478d 100644
|
||||
index 03d1527073cf827fc3e191915fe5f7f064e36c3b..749096358fccbd5d1d13801092255c51096eb001 100644
|
||||
--- a/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
|
||||
+++ b/net/minecraft/world/level/chunk/storage/SerializableChunkData.java
|
||||
@@ -122,6 +122,18 @@ public record SerializableChunkData(
|
||||
|
@ -721,7 +721,7 @@ index 47f8145ef36e05b9139c76bd692d605069405072..cbb6d1f6e715316e170936d29b816c0e
|
|||
|
||||
// Paper start - Do not let the server load chunks from newer versions
|
||||
private static final int CURRENT_DATA_VERSION = net.minecraft.SharedConstants.getCurrentVersion().getDataVersion().getVersion();
|
||||
@@ -572,7 +584,7 @@ public record SerializableChunkData(
|
||||
@@ -571,7 +583,7 @@ public record SerializableChunkData(
|
||||
compoundTag.putInt("xPos", this.chunkPos.x);
|
||||
compoundTag.putInt("yPos", this.minSectionY);
|
||||
compoundTag.putInt("zPos", this.chunkPos.z);
|
||||
|
|
Loading…
Add table
Reference in a new issue