Skip to content

Commit fbee7af

Browse files
committed
Patch Packet Custom Payload
1 parent 8c6d8f4 commit fbee7af

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package turniplabs.halplibe.mixin;
2+
3+
import net.minecraft.core.net.packet.PacketCustomPayload;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
import org.spongepowered.asm.mixin.Overwrite;
6+
import org.spongepowered.asm.mixin.Shadow;
7+
8+
import java.io.DataInputStream;
9+
import java.io.IOException;
10+
11+
import static net.minecraft.core.net.packet.Packet.readStringUTF8;
12+
13+
@Mixin(value = PacketCustomPayload.class, remap = false)
14+
public class PacketCustomPayloadMixin {
15+
@Shadow
16+
public String channel;
17+
18+
@Shadow
19+
public byte[] data;
20+
21+
/**
22+
* @author gungun974
23+
* @reason Make BTA read every byte of the PacketCustomPayload to prevent read misalignment
24+
*/
25+
@Overwrite
26+
public void read(DataInputStream in) throws IOException {
27+
this.channel = readStringUTF8(in, 128);
28+
int length = in.readInt();
29+
if (length > 0 && length < 32768) {
30+
this.data = new byte[length];
31+
in.readFully(this.data, 0, length);
32+
}
33+
}
34+
}

src/main/resources/halplibe.mixins.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"I18nMixin",
88
"ItemsMixin",
99
"MobCreeperMixin",
10+
"PacketCustomPayloadMixin",
1011
"accessors.BlockAccessor",
1112
"accessors.BlocksAccessor",
1213
"accessors.ItemsAccessor",
@@ -28,10 +29,10 @@
2829
"models.TileEntityRendererDispatcherMixin"
2930
],
3031
"server": [
31-
"accessors.PacketHandlerServerAccessor",
3232
"MinecraftServerMixin",
3333
"PacketHandlerLoginMixin",
34-
"PacketHandlerServerMixin"
34+
"PacketHandlerServerMixin",
35+
"accessors.PacketHandlerServerAccessor"
3536
],
3637
"injectors": {
3738
"defaultRequire": 1

0 commit comments

Comments
 (0)