Skip to content

Commit

Permalink
Correctly handle negative compression thresholds even though this is …
Browse files Browse the repository at this point in the history
…not standardized whatsoever
  • Loading branch information
astei committed Apr 19, 2023
1 parent af203ae commit 80720b2
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import me.steinborn.krypton.mod.shared.network.compression.MinecraftCompressDecoder;
import me.steinborn.krypton.mod.shared.network.compression.MinecraftCompressEncoder;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.PacketDeflater;
import net.minecraft.network.PacketInflater;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -37,9 +39,13 @@ private static void krypton_findViaEvent() {

@Inject(method = "setCompressionThreshold", at = @At("HEAD"), cancellable = true)
public void setCompressionThreshold(int compressionThreshold, boolean validate, CallbackInfo ci) {
if (compressionThreshold == -1) {
this.channel.pipeline().remove("decompress");
this.channel.pipeline().remove("compress");
if (compressionThreshold < 0) {
if (isKryptonOrVanillaDecompressor(this.channel.pipeline().get("decompress"))) {
this.channel.pipeline().remove("decompress");
}
if (isKryptonOrVanillaCompressor(this.channel.pipeline().get("compress"))) {
this.channel.pipeline().remove("compress");
}
} else {
MinecraftCompressDecoder decoder = (MinecraftCompressDecoder) channel.pipeline()
.get("decompress");
Expand All @@ -64,6 +70,14 @@ public void setCompressionThreshold(int compressionThreshold, boolean validate,
ci.cancel();
}

private static boolean isKryptonOrVanillaDecompressor(Object o) {
return o instanceof PacketInflater || o instanceof MinecraftCompressDecoder;
}

private static boolean isKryptonOrVanillaCompressor(Object o) {
return o instanceof PacketDeflater || o instanceof MinecraftCompressEncoder;
}

private void handleViaCompression() {
if (krypton_viaEventConstructor == null) return;
try {
Expand Down

0 comments on commit 80720b2

Please sign in to comment.