mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
Add AntiXray layered obfuscation mode (#8799)
This commit is contained in:
parent
ab76bb014b
commit
905b16a361
2 changed files with 36 additions and 2 deletions
|
@ -428,7 +428,31 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ bitStorageWriter.setBuffer(chunkPacketInfoAntiXray.getBuffer());
|
||||
+ int numberOfBlocks = presetBlockStateBits.length;
|
||||
+ // Keep the lambda expressions as simple as possible. They are used very frequently.
|
||||
+ IntSupplier random = numberOfBlocks == 1 ? (() -> 0) : new IntSupplier() {
|
||||
+ LayeredIntSupplier random = numberOfBlocks == 1 ? (() -> 0) : engineMode == EngineMode.OBFUSCATE_LAYER ? new LayeredIntSupplier() {
|
||||
+ // engine-mode: 3
|
||||
+ private int state;
|
||||
+ private int next;
|
||||
+
|
||||
+ {
|
||||
+ while ((state = ThreadLocalRandom.current().nextInt()) == 0) ;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void nextLayer() {
|
||||
+ // https://en.wikipedia.org/wiki/Xorshift
|
||||
+ state ^= state << 13;
|
||||
+ state ^= state >>> 17;
|
||||
+ state ^= state << 5;
|
||||
+ // https://www.pcg-random.org/posts/bounded-rands.html
|
||||
+ next = (int) ((Integer.toUnsignedLong(state) * numberOfBlocks) >>> 32);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public int getAsInt() {
|
||||
+ return next;
|
||||
+ }
|
||||
+ } : new LayeredIntSupplier() {
|
||||
+ // engine-mode: 2
|
||||
+ private int state;
|
||||
+
|
||||
+ {
|
||||
|
@ -509,6 +533,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ current = next;
|
||||
+ next = nextNext;
|
||||
+ nextNext = temp;
|
||||
+ random.nextLayer();
|
||||
+ obfuscateLayer(y, bitStorageReader, bitStorageWriter, solidTemp, obfuscateTemp, presetBlockStateBitsTemp, current, next, nextNext, nearbyChunkSections, random);
|
||||
+ }
|
||||
+
|
||||
|
@ -534,6 +559,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ // There is nothing to read anymore
|
||||
+ bitStorageReader.setBits(0);
|
||||
+ solid[0] = true;
|
||||
+ random.nextLayer();
|
||||
+ obfuscateLayer(15, bitStorageReader, bitStorageWriter, solid, obfuscateTemp, presetBlockStateBitsTemp, current, next, nextNext, nearbyChunkSections, random);
|
||||
+ }
|
||||
+ } else {
|
||||
|
@ -546,6 +572,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ current = next;
|
||||
+ next = nextNext;
|
||||
+ nextNext = temp;
|
||||
+ random.nextLayer();
|
||||
+ obfuscateLayer(15, bitStorageReader, bitStorageWriter, solidTemp, obfuscateTemp, presetBlockStateBitsTemp, current, next, nextNext, nearbyChunkSections, random);
|
||||
+ }
|
||||
+
|
||||
|
@ -838,6 +865,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ ((ServerLevel) level).getChunkSource().blockChanged(blockPos);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ @FunctionalInterface
|
||||
+ private interface LayeredIntSupplier extends IntSupplier {
|
||||
+ default void nextLayer() {
|
||||
+
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/antixray/ChunkPacketInfo.java b/src/main/java/com/destroystokyo/paper/antixray/ChunkPacketInfo.java
|
||||
new file mode 100644
|
||||
|
|
|
@ -4013,7 +4013,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+
|
||||
+public enum EngineMode {
|
||||
+
|
||||
+ HIDE(1, "hide ores"), OBFUSCATE(2, "obfuscate");
|
||||
+ HIDE(1, "hide ores"), OBFUSCATE(2, "obfuscate"), OBFUSCATE_LAYER(3, "obfuscate layer");
|
||||
+
|
||||
+ public static final ScalarSerializer<EngineMode> SERIALIZER = new EngineModeSerializer();
|
||||
+
|
||||
|
|
Loading…
Reference in a new issue