Add AntiXray layered obfuscation mode (#8799)

This commit is contained in:
Drex 2023-02-09 18:38:00 +01:00
parent ab76bb014b
commit 905b16a361
2 changed files with 36 additions and 2 deletions

View file

@ -428,7 +428,31 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ bitStorageWriter.setBuffer(chunkPacketInfoAntiXray.getBuffer()); + bitStorageWriter.setBuffer(chunkPacketInfoAntiXray.getBuffer());
+ int numberOfBlocks = presetBlockStateBits.length; + int numberOfBlocks = presetBlockStateBits.length;
+ // Keep the lambda expressions as simple as possible. They are used very frequently. + // 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; + private int state;
+ +
+ { + {
@ -509,6 +533,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ current = next; + current = next;
+ next = nextNext; + next = nextNext;
+ nextNext = temp; + nextNext = temp;
+ random.nextLayer();
+ obfuscateLayer(y, bitStorageReader, bitStorageWriter, solidTemp, obfuscateTemp, presetBlockStateBitsTemp, current, next, nextNext, nearbyChunkSections, random); + 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 + // There is nothing to read anymore
+ bitStorageReader.setBits(0); + bitStorageReader.setBits(0);
+ solid[0] = true; + solid[0] = true;
+ random.nextLayer();
+ obfuscateLayer(15, bitStorageReader, bitStorageWriter, solid, obfuscateTemp, presetBlockStateBitsTemp, current, next, nextNext, nearbyChunkSections, random); + obfuscateLayer(15, bitStorageReader, bitStorageWriter, solid, obfuscateTemp, presetBlockStateBitsTemp, current, next, nextNext, nearbyChunkSections, random);
+ } + }
+ } else { + } else {
@ -546,6 +572,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ current = next; + current = next;
+ next = nextNext; + next = nextNext;
+ nextNext = temp; + nextNext = temp;
+ random.nextLayer();
+ obfuscateLayer(15, bitStorageReader, bitStorageWriter, solidTemp, obfuscateTemp, presetBlockStateBitsTemp, current, next, nextNext, nearbyChunkSections, random); + obfuscateLayer(15, bitStorageReader, bitStorageWriter, solidTemp, obfuscateTemp, presetBlockStateBitsTemp, current, next, nextNext, nearbyChunkSections, random);
+ } + }
+ +
@ -838,6 +865,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ ((ServerLevel) level).getChunkSource().blockChanged(blockPos); + ((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 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 new file mode 100644

View file

@ -4013,7 +4013,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ +
+public enum EngineMode { +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(); + public static final ScalarSerializer<EngineMode> SERIALIZER = new EngineModeSerializer();
+ +