diff --git a/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/LongChecker.java b/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/LongChecker.java new file mode 100644 index 0000000..6ebf317 --- /dev/null +++ b/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/LongChecker.java @@ -0,0 +1,40 @@ +package gearth.misc.packetrepresentation.prediction.checkers; + +import gearth.protocol.HPacket; + +public class LongChecker extends TypeChecker { + + private IntegerChecker integerChecker; + + protected LongChecker(HPacket hPacket) { + super("l", hPacket); + integerChecker = new IntegerChecker(hPacket); + } + + @Override + public boolean canRead(int index) { + return index >= 6 && !(index + 8 > hPacket.getBytesLength()); + } + + @Override + public double score(int index) { + int split1 = hPacket.readInteger(index); + int split2 = hPacket.readInteger(index + 4); + + if (split2 > 256 * 256 * 3 && split1 == 0) { + return integerChecker.score(index); + } + + return 0; + } + + @Override + Long get(int index) { + return hPacket.readLong(index); + } + + @Override + int nextIndexSafe(int index) { + return index + 8; + } +} diff --git a/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/TypeCheckerProducer.java b/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/TypeCheckerProducer.java index 675699c..f7d7959 100644 --- a/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/TypeCheckerProducer.java +++ b/G-Earth/src/main/java/gearth/misc/packetrepresentation/prediction/checkers/TypeCheckerProducer.java @@ -2,18 +2,26 @@ package gearth.misc.packetrepresentation.prediction.checkers; import gearth.protocol.HPacket; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class TypeCheckerProducer { + public static volatile boolean USE_LONG_DATATYPE = false; + public static List getValidators(HPacket packet) { - return Arrays.asList( + List typeCheckers = new ArrayList<>(Arrays.asList( new BooleanChecker(packet), new ByteChecker(packet), new IntegerChecker(packet), - new StringChecker(packet) - ); + new StringChecker(packet))); + + if (USE_LONG_DATATYPE) { + typeCheckers.add(new LongChecker(packet)); + } + + return typeCheckers; } } diff --git a/G-Earth/src/main/java/gearth/ui/extra/ExtraController.java b/G-Earth/src/main/java/gearth/ui/extra/ExtraController.java index d7212eb..1a98ee4 100644 --- a/G-Earth/src/main/java/gearth/ui/extra/ExtraController.java +++ b/G-Earth/src/main/java/gearth/ui/extra/ExtraController.java @@ -2,6 +2,8 @@ package gearth.ui.extra; import gearth.Main; import gearth.misc.Cacher; +import gearth.misc.packetrepresentation.prediction.StructurePredictor; +import gearth.misc.packetrepresentation.prediction.checkers.TypeCheckerProducer; import gearth.protocol.HConnection; import gearth.protocol.connection.HState; import gearth.protocol.connection.proxy.ProxyProviderFactory; @@ -62,7 +64,11 @@ public class ExtraController extends SubForm implements SocksConfiguration { public RadioButton rd_flash; public void initialize() { - tgl_clientMode.selectedToggleProperty().addListener(observable -> parentController.connectionController.changeClientMode()); + TypeCheckerProducer.USE_LONG_DATATYPE = rd_unity.isSelected(); + tgl_clientMode.selectedToggleProperty().addListener(observable -> { + parentController.connectionController.changeClientMode(); + TypeCheckerProducer.USE_LONG_DATATYPE = rd_unity.isSelected(); + }); url_troubleshooting.setTooltip(new Tooltip("https://github.com/sirjonasxx/G-Earth/wiki/Troubleshooting")); InfoController.activateHyperlink(url_troubleshooting);