Skip to content

Commit 1d7d91a

Browse files
author
tonimatasdev
committed
Fix String too big
1 parent 7f58e80 commit 1d7d91a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

common/src/main/java/dev/tonimatas/packetfixer/mixins/FriendlyByteBufMixin.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,14 @@ private long newSize(long value) {
3232
private String readLong$size(String constant) {
3333
return "VarInt too big. Packet Fixer configured to " + Config.getVarLong() + ". You can modify it in the Packet Fixer config.";
3434
}
35+
36+
@ModifyConstant(method = "readUtf()Ljava/lang/String;", constant = @Constant(intValue = 32767))
37+
private int readUtf$size(int value) {
38+
return Config.getStringSize();
39+
}
40+
41+
@ModifyConstant(method = "writeUtf(Ljava/lang/String;)Lnet/minecraft/network/FriendlyByteBuf;", constant = @Constant(intValue = 32767))
42+
private int writeUtf$size(int value) {
43+
return Config.getStringSize();
44+
}
3545
}

common/src/main/java/dev/tonimatas/packetfixer/util/Config.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public static void runProperties() {
3030
properties.setProperty("varInt21", Integer.toString(3));
3131
properties.setProperty("varInt", Integer.toString(5));
3232
properties.setProperty("varLong", Integer.toString(10));
33+
properties.setProperty("stringSize", Integer.toString(32767));
3334
checkVariable("chunkPacketData", Integer.toString(2097152));
3435
properties.setProperty("timeout", Integer.toString(90));
3536

@@ -45,6 +46,7 @@ public static void runProperties() {
4546
checkVariable("varInt21", Integer.toString(3));
4647
checkVariable("varInt", Integer.toString(5));
4748
checkVariable("varLong", Integer.toString(10));
49+
checkVariable("stringSize", Integer.toString(32767));
4850
checkVariable("chunkPacketData", Integer.toString(2097152));
4951
checkVariable("timeout", Integer.toString(90));
5052
save(propertiesFile);
@@ -88,6 +90,11 @@ public static int getVarLong() {
8890
return getUnlimitedPacketSize() ? (Integer.MAX_VALUE / 2 - 1) : Integer.parseInt(properties.getProperty("varLong"));
8991
}
9092

93+
public static int getStringSize() {
94+
if (properties == null) runProperties();
95+
return getUnlimitedPacketSize() ? Integer.MAX_VALUE : Integer.parseInt(properties.getProperty("stringSize"));
96+
}
97+
9198
public static int getChunkPacketData() {
9299
if (properties == null) runProperties();
93100
return getUnlimitedPacketSize() ? Integer.MAX_VALUE : Integer.parseInt(properties.getProperty("chunkPacketData"));

0 commit comments

Comments
 (0)