-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
657a761
commit 8040bdc
Showing
6 changed files
with
64 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
56 changes: 51 additions & 5 deletions
56
forge/src/main/java/net/tonimatasdev/packetfixerforge/mixin/CompressionEncoderMixin.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,60 @@ | ||
package net.tonimatasdev.packetfixerforge.mixin; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import net.minecraft.network.CompressionEncoder; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import org.apache.logging.log4j.Logger; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import java.util.zip.Deflater; | ||
|
||
@Mixin(value = CompressionEncoder.class, priority = 9999) | ||
public class CompressionEncoderMixin { | ||
@Redirect(method = "encode(Lio/netty/channel/ChannelHandlerContext;Lio/netty/buffer/ByteBuf;Lio/netty/buffer/ByteBuf;)V", at = @At(value = "FIELD", target = "Lnet/minecraft/network/CompressionEncoder;DISABLE_PACKET_DEBUG:Z")) | ||
public boolean injected() { | ||
return true; | ||
@Shadow private int threshold; | ||
|
||
@Shadow @Final private static boolean DISABLE_PACKET_DEBUG; | ||
|
||
@Shadow @Final private static Logger LOGGER; | ||
|
||
@Shadow @Final private Deflater deflater; | ||
|
||
@Shadow @Final private byte[] encodeBuf; | ||
|
||
/** | ||
* @author TonimatasDEV | ||
* @reason Infinite packet size | ||
*/ | ||
@SuppressWarnings("PointlessBooleanExpression") | ||
@Overwrite | ||
protected void encode(ChannelHandlerContext p_129452_, ByteBuf p_129453_, ByteBuf p_129454_) { | ||
int i = p_129453_.readableBytes(); | ||
FriendlyByteBuf friendlybytebuf = new FriendlyByteBuf(p_129454_); | ||
if (i < this.threshold) { | ||
friendlybytebuf.writeVarInt(0); | ||
friendlybytebuf.writeBytes(p_129453_); | ||
} else { | ||
if (!DISABLE_PACKET_DEBUG && i > net.minecraft.network.CompressionDecoder.MAXIMUM_UNCOMPRESSED_LENGTH || true) { | ||
p_129453_.markReaderIndex(); | ||
LOGGER.error("Attempted to send packet over maximum protocol size: {} > {}\nData:\n{}", i, net.minecraft.network.CompressionDecoder.MAXIMUM_UNCOMPRESSED_LENGTH, | ||
net.minecraftforge.logging.PacketDump.getContentDump(p_129453_)); | ||
p_129453_.resetReaderIndex(); | ||
} | ||
byte[] abyte = new byte[i]; | ||
p_129453_.readBytes(abyte); | ||
friendlybytebuf.writeVarInt(abyte.length); | ||
this.deflater.setInput(abyte, 0, i); | ||
this.deflater.finish(); | ||
|
||
while(!this.deflater.finished()) { | ||
int j = this.deflater.deflate(this.encodeBuf); | ||
friendlybytebuf.writeBytes(this.encodeBuf, 0, j); | ||
} | ||
|
||
this.deflater.reset(); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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