From 42f9af57ce765b2623347b5ae71434a3043d4c97 Mon Sep 17 00:00:00 2001 From: Bella Date: Sat, 11 Jan 2020 20:23:18 -0500 Subject: [PATCH] add antichunkload patch --- .../client/MixinNettyCompressionDecoder.java | 67 +++++++++++++++++++ .../bewwawho/player/AntiChunkLoadPatch.java | 19 ++++++ src/main/resources/mixins.kami.json | 3 +- 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/main/java/me/zeroeightsix/kami/mixin/client/MixinNettyCompressionDecoder.java create mode 100644 src/main/java/me/zeroeightsix/kami/module/modules/bewwawho/player/AntiChunkLoadPatch.java diff --git a/src/main/java/me/zeroeightsix/kami/mixin/client/MixinNettyCompressionDecoder.java b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinNettyCompressionDecoder.java new file mode 100644 index 000000000..1721c7da5 --- /dev/null +++ b/src/main/java/me/zeroeightsix/kami/mixin/client/MixinNettyCompressionDecoder.java @@ -0,0 +1,67 @@ +package me.zeroeightsix.kami.mixin.client; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandlerContext; +import me.zeroeightsix.kami.command.Command; +import me.zeroeightsix.kami.module.modules.bewwawho.player.AntiChunkLoadPatch; +import net.minecraft.client.Minecraft; +import net.minecraft.network.NettyCompressionDecoder; +import net.minecraft.network.PacketBuffer; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.List; +import java.util.zip.DataFormatException; +import java.util.zip.Inflater; + +/** + * Created by 0x2E | PretendingToCode on 29/12/19 + * Updated by S-B99 on 11/01/20 + */ +@Mixin(NettyCompressionDecoder.class) +public class MixinNettyCompressionDecoder { + + public int readVarIntFromBuffer(PacketBuffer arg){ + int i = 0; + int j = 0; + + while (true) { + byte b0 = arg.readByte(); + i |= (b0 & 127) << j++ * 7; + + if (j > 5) throw new RuntimeException("VarInt too big"); + if ((b0 & 128) != 128) break; + } + return i; + } + + @Inject(method = "decode", at = @At("HEAD"), cancellable = true) + private void decode(ChannelHandlerContext p_decode_1_, ByteBuf p_decode_2_, List p_decode_3_, CallbackInfo info) throws DataFormatException { + Inflater packetInflater = new Inflater(); + if (p_decode_2_.readableBytes() != 0 && AntiChunkLoadPatch.enabled()) { + PacketBuffer packetbuffer = new PacketBuffer(p_decode_2_); + int i = readVarIntFromBuffer(packetbuffer); + + if (i == 0) { + p_decode_3_.add(packetbuffer.readBytes(packetbuffer.readableBytes())); + } + else if (i > 2097152) { + if (Minecraft.getMinecraft().player != null) { + Command.sendWarningMessage("&7[&c&lDecoderException&r&7] &rBadly compressed packet - size of " + String.valueOf(i) + " is larger than protocol maximum of 2097152"); + Command.sendErrorMessage("&7[&c&lDecoderException&r&7] Not loading chunk due to possible kick"); + } + + byte[] abyte = new byte[packetbuffer.readableBytes()]; + packetbuffer.readBytes(abyte); + packetInflater.setInput(abyte); + byte[] abyte1 = new byte[i]; + packetInflater.inflate(abyte1); + p_decode_3_.add(Unpooled.wrappedBuffer(abyte1)); + packetInflater.reset(); + } + } + } +} diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/bewwawho/player/AntiChunkLoadPatch.java b/src/main/java/me/zeroeightsix/kami/module/modules/bewwawho/player/AntiChunkLoadPatch.java new file mode 100644 index 000000000..56ad55f87 --- /dev/null +++ b/src/main/java/me/zeroeightsix/kami/module/modules/bewwawho/player/AntiChunkLoadPatch.java @@ -0,0 +1,19 @@ +package me.zeroeightsix.kami.module.modules.bewwawho.player; + +import me.zeroeightsix.kami.module.Module; + +/*** + * Created by S-B99 on 11/01/20 + */ +@Module.Info(name = "AntiChunkLoadPatch", category = Module.Category.PLAYER, description = "Prevents loading of overloaded chunks", showOnArray = Module.ShowOnArray.OFF) +public class AntiChunkLoadPatch extends Module { + private static AntiChunkLoadPatch INSTANCE = new AntiChunkLoadPatch(); + + public AntiChunkLoadPatch() { + INSTANCE = this; + } + + public static boolean enabled() { + return INSTANCE.isEnabled(); + } +} diff --git a/src/main/resources/mixins.kami.json b/src/main/resources/mixins.kami.json index 41671c29b..ef59a616b 100644 --- a/src/main/resources/mixins.kami.json +++ b/src/main/resources/mixins.kami.json @@ -25,6 +25,7 @@ "MixinStateImplementation", "MixinAbstractClientPlayer", "MixinGuiNewChat", - "MixinLayerBipedArmor" + "MixinLayerBipedArmor", + "MixinNettyCompressionDecoder" ] }