Skip to content

Commit

Permalink
Fix things
Browse files Browse the repository at this point in the history
  • Loading branch information
TonimatasDEV committed Aug 31, 2023
1 parent 657a761 commit 8040bdc
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 15 deletions.
2 changes: 2 additions & 0 deletions fabric/src/main/resources/packetfixer.mixins.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"required": true,
"minVersion": "0.8",
"package": "net.tonimatasdev.packetfixerfabric.mixin",
"compatibilityLevel": "JAVA_17",
"refmap": "packetfixer.refmap.json",
"mixins": [
"CustomPayloadC2SPacketMixin",
"CustomPayloadS2CPacketMixin",
Expand Down
2 changes: 1 addition & 1 deletion forge/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ dependencies {


tasks.withType<ProcessResources> {
val replaceProperties = mapOf("forgeVersionRange" to forgeVersionRange, "version" to modVersion, "minecraftVersion" to minecraftVersion)
val replaceProperties = mapOf("forgeVersionRange" to forgeVersionRange, "modVersion" to modVersion, "minecraftVersion" to minecraftVersion)

inputs.properties(replaceProperties)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import net.minecraft.network.CompressionDecoder;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(value = CompressionDecoder.class, priority = 9999)
public class CompressionDecoderMixin {
@ModifyConstant(method = "decode", constant = @Constant(intValue = 8388608), require = 0)
@ModifyConstant(method = "decode", constant = @Constant(intValue = 8388608))
private int newSize(int value) {
return Integer.MAX_VALUE;
}
Expand Down
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();
}
}
}
6 changes: 3 additions & 3 deletions forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
modLoader="javafml"
loaderVersion="${forgeVersionRange}"
loaderVersion="[${forgeVersionRange},)"
license="MIT"
issueTrackerURL="https://github.com/TonimatasDEV/PacketFixer"

[[mods]]
modId="packetfixer"
version="${version}"
version="${modVersion}"
displayName="PacketFixer"
icon="icon.png"

Expand All @@ -17,7 +17,7 @@ A simple mod to solve various problems with packets.
[[dependencies.packetfixer]]
modId="forge"
mandatory=true
versionRange="${forgeVersionRange}"
versionRange="[${forgeVersionRange},)"
ordering="NONE"
side="BOTH"

Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ modVersion=1.1.5
minecraftVersion=1.20.1

# Forge properties
forgeVersion=47.1.1
forgeVersionRange=[46,48)
forgeVersion=47.1.44
forgeVersionRange=47

# Fabric properties
loaderVersion=0.14.21
yarnMappings=1.20.1+build.9
loaderVersion=0.14.22
yarnMappings=1.20.1+build.10

0 comments on commit 8040bdc

Please sign in to comment.