Add AntiXray layered obfuscation mode#8799
Merged
kennytv merged 3 commits intoFeb 9, 2023
Merged
Conversation
* Removes code duplication from obfuscateLayer * Adds a 3rd engine mode (layered obfuscation), this mode works the same as engine mode 2, but instead of randomizing every blocks only randomizes block per chunk layer (https://github.com/DrexHD/AntiXray/blob/1.19.3/stable/media/enginemode-3.png). This helps a lot with chunk packet compression and can reduce the network load when joining by a factor of 2-3 (from very basic testing)
Contributor
The code duplication is very much intended. You are touching the hottest code in Anti-Xray and with your changes you are introducing lots of branches into that code. Also your changes can be implemented without even touching the I like the idea. The implementation of it should be a matter of changing like 2 or 3 lines tho. |
Contributor
|
This will do it (not tested): 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;
{
while ((state = ThreadLocalRandom.current().nextInt()) == 0) ;
}
@Override
public int getAsInt() {
// https://en.wikipedia.org/wiki/Xorshift
state ^= state << 13;
state ^= state >>> 17;
state ^= state << 5;
// https://www.pcg-random.org/posts/bounded-rands.html
return (int) ((Integer.toUnsignedLong(state) * numberOfBlocks) >>> 32);
}
};
@FunctionalInterface
private static interface LayeredIntSupplier extends IntSupplier {
default void nextLayer() {
}
}Then call |
* Reverts code de-duplication for a slight performance improvement * Implements layered obfuscation using a separate int supplier
stonar96
suggested changes
Jan 20, 2023
Contributor
stonar96
left a comment
There was a problem hiding this comment.
Everything else looks good to me. Thanks!
stonar96
approved these changes
Jan 20, 2023
kennytv
approved these changes
Jan 22, 2023
maestro-denery
pushed a commit
to maestro-denery/Paper
that referenced
this pull request
Feb 19, 2023
imirochi
referenced
this pull request
in PlazmaMC/PlazmaBukkit
Mar 24, 2023
LeonTG
pushed a commit
to LeonTG/Paper
that referenced
this pull request
May 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
obfuscateLayerTesting
The tests have been run on a plain new paper server by joining three times in the same spot in spawn chunks. After every test, the server has been rebooted, and these results have shown to be reproducible.
Results: imgur