Skip to content

Commit ff34bcd

Browse files
committed
feat: fix packet differences across versions
1 parent 87a45cd commit ff34bcd

File tree

1 file changed

+51
-8
lines changed

1 file changed

+51
-8
lines changed

src/proxy.ts

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ enum State {
2323
Play = 0x03,
2424
}
2525

26+
enum PacketType {
27+
SERVERBOUND,
28+
CLIENTBOUND
29+
}
30+
2631
// EAG_ prefixed are nonstandard
2732
enum Serverbound {
2833
/* ==HANDSHAKING== */
@@ -38,9 +43,17 @@ enum Serverbound {
3843
LoginStart = 0x00,
3944
EncryptionResponse = 0x01,
4045
/* ==PLAY== */
46+
PluginMessage = -0x00,
47+
}
48+
49+
enum Serverbound_1_8 {
4150
PluginMessage = 0x17,
4251
}
4352

53+
enum Serverbound_1_12 {
54+
PluginMessage = 0x09,
55+
}
56+
4457
enum Clientbound {
4558
/* ==HANDSHAKING== */
4659
EAG_ServerVersion = 0x02,
@@ -57,9 +70,17 @@ enum Clientbound {
5770
SetCompression = 0x03,
5871
/* ==PLAY== */
5972
SetCompressionPlay = 0x46,
73+
PluginMessage = -0x00,
74+
}
75+
76+
enum Clientbound_1_8 {
6077
PluginMessage = 0x3f,
6178
}
6279

80+
enum Clientbound_1_12 {
81+
PluginMessage = 0x18,
82+
}
83+
6384
class Packet extends Buffer {
6485
constructor(packetType: number) {
6586
super(new Uint8Array());
@@ -131,6 +152,26 @@ function createProtocolArray(pvn: number): number[] {
131152
}
132153
}
133154

155+
function getVersionPluginMessage(protocol: number, type: PacketType): number {
156+
if (type == PacketType.SERVERBOUND) {
157+
if (protocol == 47) {
158+
return Serverbound_1_8.PluginMessage;
159+
} else if (protocol == 340) {
160+
return Serverbound_1_12.PluginMessage;
161+
} else {
162+
return Serverbound.PluginMessage
163+
}
164+
} else {
165+
if (protocol == 47) {
166+
return Clientbound_1_8.PluginMessage;
167+
} else if (protocol == 340) {
168+
return Clientbound_1_12.PluginMessage;
169+
} else {
170+
return Clientbound.PluginMessage
171+
}
172+
}
173+
}
174+
134175
export class EaglerProxy {
135176
loggedIn: boolean = false;
136177
handshook: boolean = false;
@@ -236,7 +277,7 @@ export class EaglerProxy {
236277
case State.Play:
237278
let pk = packet.readVarInt(false)!;
238279
switch (pk) {
239-
case Serverbound.PluginMessage:
280+
case getVersionPluginMessage(this.protocol, PacketType.SERVERBOUND):
240281
let fard = packet.copy();
241282
fard.readVarInt();
242283
let tag = fard.readString();
@@ -248,7 +289,7 @@ export class EaglerProxy {
248289
if (buf.length == 0) {
249290
return;
250291
}
251-
let resp = new Packet(Clientbound.PluginMessage);
292+
let resp = new Packet(getVersionPluginMessage(this.protocol, PacketType.CLIENTBOUND));
252293
resp.writeString(tag);
253294
resp.extend(buf);
254295
this.eagler.write(resp);
@@ -407,12 +448,14 @@ export class EaglerProxy {
407448
case State.Play:
408449
switch (packet.readVarInt(false)) {
409450
case Clientbound.SetCompressionPlay:
410-
packet.readVarInt();
411-
let threshold = packet.readVarInt();
412-
this.decompressor.compressionThresh = threshold;
413-
this.compressor.compressionThresh = threshold;
414-
break;
415-
case Clientbound.PluginMessage:
451+
if (this.protocol <= 47) {
452+
packet.readVarInt();
453+
let threshold = packet.readVarInt();
454+
this.decompressor.compressionThresh = threshold;
455+
this.compressor.compressionThresh = threshold;
456+
break;
457+
}
458+
case getVersionPluginMessage(this.protocol, PacketType.CLIENTBOUND):
416459
let pk = packet.copy();
417460
pk.readVarInt();
418461
let tag = pk.readString();

0 commit comments

Comments
 (0)