Skip to content

Commit eeb4702

Browse files
committed
Add support for Minecraft 1.19.3.
1 parent a95b3a7 commit eeb4702

File tree

10 files changed

+42
-21
lines changed

10 files changed

+42
-21
lines changed

android/app/src/main/java/com/enderchat/modules/connection/ConnectionModule.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -194,14 +194,17 @@ class ConnectionModule(reactContext: ReactApplicationContext)
194194
val is117 = protocolVersion >= PROTOCOL_VERSION_117
195195
val is119 = protocolVersion >= PROTOCOL_VERSION_119
196196
val is1191 = protocolVersion >= PROTOCOL_VERSION_1191
197+
val is1193 = protocolVersion >= PROTOCOL_VERSION_1193
197198
val keepAliveClientBoundId =
198-
if (is1191) 0x20
199+
if (is1193) 0x1f
200+
else if (is1191) 0x20
199201
else if (is119) 0x1e
200202
else if (is117) 0x21
201203
else if (is1164) 0x1f
202204
else 0x1f
203205
val keepAliveServerBoundId =
204-
if (is1191) 0x12
206+
if (is1193) 0x11
207+
else if (is1191) 0x12
205208
else if (is119) 0x11
206209
else if (is117) 0x0f
207210
else if (is1164) 0x10

android/app/src/main/java/com/enderchat/modules/connection/Utils.kt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const val PROTOCOL_VERSION_1164 = 754
88
const val PROTOCOL_VERSION_117 = 755
99
const val PROTOCOL_VERSION_119 = 759
1010
const val PROTOCOL_VERSION_1191 = 760
11+
const val PROTOCOL_VERSION_1193 = 761
1112

1213
fun compressData(bytes: ByteArray): ByteArray {
1314
ByteArrayOutputStream(bytes.size).use {

src/components/servers/EditServerDialog.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ const EditServerDialog = ({
106106
dropdownIconColor={darkMode ? '#ffffff' : '#000000'}
107107
>
108108
<Picker.Item label='Auto' value='auto' />
109+
<Picker.Item label='1.19.3 (WIP)' value='1.19.3' />
109110
<Picker.Item label='1.19.1/1.19.2 (WIP)' value='1.19.1' />
110111
<Picker.Item label='1.19 (WIP)' value='1.19' />
111112
<Picker.Item label='1.18.2' value='1.18.2' />

src/minecraft/connection/javascript.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from '../packet'
1919
import { ServerConnection, ConnectionOptions } from '.'
2020
import { getLoginPacket, handleEncryptionRequest } from './shared'
21-
import { readVarInt, writeVarInt, resolveHostname, protocolMap } from '../utils'
21+
import { readVarInt, writeVarInt, resolveHostname } from '../utils'
2222
import packetIds from '../packets/ids'
2323

2424
export declare interface JavaScriptServerConnection {
@@ -46,7 +46,6 @@ export class JavaScriptServerConnection
4646
disconnectReason?: string
4747
aesDecipher?: Decipher
4848
aesCipher?: Cipher
49-
msgSalt?: Buffer
5049

5150
constructor(socket: net.Socket, options: ConnectionOptions) {
5251
super()
@@ -180,7 +179,6 @@ const initiateJavaScriptConnection = async (opts: ConnectionOptions) => {
180179
accessToken,
181180
selectedProfile,
182181
conn,
183-
version >= protocolMap['1.19'],
184182
async (secret: Buffer, response: Buffer) => {
185183
const AES_ALG = 'aes-128-cfb8'
186184
conn.aesDecipher = createDecipheriv(AES_ALG, secret, secret)

src/minecraft/connection/native.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import events from 'events'
77
import { ServerConnection, ConnectionOptions } from '.'
88
import { concatPacketData, Packet } from '../packet'
99
import { getLoginPacket, handleEncryptionRequest } from './shared'
10-
import { readVarInt, writeVarInt, resolveHostname, protocolMap } from '../utils'
10+
import { readVarInt, writeVarInt, resolveHostname } from '../utils'
1111
import packetIds from '../packets/ids'
1212

1313
const { ConnectionModule } = NativeModules
@@ -120,7 +120,6 @@ export class NativeServerConnection
120120
accessToken,
121121
selectedProfile,
122122
this,
123-
version >= protocolMap['1.19'],
124123
async (secret: Buffer, response: Buffer) => {
125124
const eSecret = secret.toString('base64')
126125
const eResp = response.toString('base64')

src/minecraft/connection/shared.ts

+14-11
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ export const parseEncryptionRequestPacket = (packet: Packet) => {
2929

3030
export const getLoginPacket = (opts: ConnectionOptions) => {
3131
const data: PacketDataTypes[] = [opts.username]
32-
if (opts.protocolVersion >= protocolMap[1.19]) {
32+
if (
33+
opts.protocolVersion >= protocolMap[1.19] &&
34+
opts.protocolVersion < protocolMap['1.19.3']
35+
) {
3336
data.push(false)
3437
/* TODO: Support chat signing properly.
3538
data.push(!!opts.certificate)
@@ -49,13 +52,13 @@ export const getLoginPacket = (opts: ConnectionOptions) => {
4952
data.push(writeVarInt(buf.byteLength))
5053
data.push(buf)
5154
} */
52-
if (opts.protocolVersion >= protocolMap['1.19.1']) {
53-
if (opts.selectedProfile) {
54-
const msb = Buffer.from(opts.selectedProfile.substring(0, 16), 'hex')
55-
const lsb = Buffer.from(opts.selectedProfile.substring(16), 'hex')
56-
data.push(concatPacketData([true, msb, lsb]))
57-
} else data.push(concatPacketData([false]))
58-
}
55+
}
56+
if (opts.protocolVersion >= protocolMap['1.19.1']) {
57+
if (opts.selectedProfile) {
58+
const msb = Buffer.from(opts.selectedProfile.substring(0, 16), 'hex')
59+
const lsb = Buffer.from(opts.selectedProfile.substring(16), 'hex')
60+
data.push(concatPacketData([true, msb, lsb]))
61+
} else data.push(concatPacketData([false]))
5962
}
6063
return concatPacketData(data)
6164
}
@@ -65,7 +68,6 @@ export const handleEncryptionRequest = (
6568
accessToken: string,
6669
selectedProfile: string,
6770
connection: ServerConnection,
68-
is119: boolean,
6971
callback: (secret: Buffer, response: Buffer) => Promise<void>
7072
) => {
7173
// https://wiki.vg/Protocol_Encryption
@@ -100,9 +102,10 @@ export const handleEncryptionRequest = (
100102
writeVarInt(encryptedVerifyToken.byteLength),
101103
encryptedVerifyToken
102104
]
103-
if (is119) {
105+
const { protocolVersion } = connection.options
106+
if (protocolVersion >= protocolMap['1.19']) {
104107
connection.msgSalt = await getRandomBytes(8)
105-
response.splice(2, 0, true)
108+
if (protocolVersion < protocolMap['1.19.3']) response.splice(2, 0, true)
106109
}
107110
// This callback will send the response and enable the ciphers.
108111
await callback(secret, concatPacketData(response))

src/minecraft/packets/chat.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const makeChatMessagePacket = (
99
): [number, Buffer] => {
1010
const is119 = protocolVersion >= protocolMap[1.19]
1111
const is1191 = protocolVersion >= protocolMap['1.19.1']
12+
const is1193 = protocolVersion >= protocolMap['1.19.3']
1213
if (!is119) {
1314
const id = packetIds.SERVERBOUND_CHAT_MESSAGE(protocolVersion)
1415
return [id ?? 0, concatPacketData([msg])]
@@ -28,6 +29,7 @@ export const makeChatMessagePacket = (
2829
false
2930
]
3031
if (is1191) data.push(writeVarInt(0), writeVarInt(0))
32+
if (is1193) data.push(writeVarInt(0))
3133
return [id ?? 0, concatPacketData(data)]
3234
}
3335
}

src/minecraft/packets/ids.ts

+13
Original file line numberDiff line numberDiff line change
@@ -28,41 +28,48 @@ const packetIds = {
2828

2929
// Clientbound (play)
3030
CLIENTBOUND_KEEP_ALIVE: generateIdFunction([
31+
[protocolMap['1.19.3'], 0x1f],
3132
[protocolMap['1.19.1'], 0x20],
3233
[protocolMap['1.19'], 0x1e],
3334
[protocolMap['1.17'], 0x21],
3435
[protocolMap['1.16.4'], 0x1f]
3536
]),
3637
CLIENTBOUND_DISCONNECT_PLAY: generateIdFunction([
38+
[protocolMap['1.19.3'], 0x17],
3739
[protocolMap['1.19.1'], 0x19],
3840
[protocolMap['1.19'], 0x17],
3941
[protocolMap['1.17'], 0x1a],
4042
[protocolMap['1.16.4'], 0x19]
4143
]),
4244
CLIENTBOUND_LOGIN_PLAY: generateIdFunction([
45+
[protocolMap['1.19.3'], 0x24],
4346
[protocolMap['1.19.1'], 0x25],
4447
[protocolMap['1.19'], 0x23],
4548
[protocolMap['1.17'], 0x26],
4649
[protocolMap['1.16.4'], 0x24]
4750
]),
4851
CLIENTBOUND_RESPAWN: generateIdFunction([
52+
[protocolMap['1.19.3'], 0x3d],
4953
[protocolMap['1.19.1'], 0x3e],
5054
[protocolMap['1.19'], 0x3b],
5155
[protocolMap['1.17'], 0x3d],
5256
[protocolMap['1.16.4'], 0x39]
5357
]),
5458
CLIENTBOUND_UPDATE_HEALTH: generateIdFunction([
59+
[protocolMap['1.19.3'], 0x53],
5560
[protocolMap['1.19.1'], 0x55],
5661
[protocolMap['1.17'], 0x52],
5762
[protocolMap['1.16.4'], 0x49]
5863
]),
5964
CLIENTBOUND_DEATH_COMBAT_EVENT: generateIdFunction([
65+
[protocolMap['1.19.3'], 0x34],
6066
[protocolMap['1.19.1'], 0x36],
6167
[protocolMap['1.19'], 0x33],
6268
[protocolMap['1.17'], 0x35],
6369
[protocolMap['1.16.4'], 0x31]
6470
]),
6571
CLIENTBOUND_OPEN_WINDOW: generateIdFunction([
72+
[protocolMap['1.19.3'], 0x2c],
6673
[protocolMap['1.19.1'], 0x2d],
6774
[protocolMap['1.19'], 0x2b],
6875
[protocolMap['1.16.4'], 0x2e]
@@ -73,33 +80,39 @@ const packetIds = {
7380
[protocolMap['1.16.4'], 0x0e]
7481
]),
7582
CLIENTBOUND_PLAYER_CHAT_MESSAGE: generateIdFunction([
83+
[protocolMap['1.19.3'], 0x31],
7684
[protocolMap['1.19.1'], 0x33],
7785
[protocolMap['1.19'], 0x30]
7886
]),
7987
CLIENTBOUND_SYSTEM_CHAT_MESSAGE: generateIdFunction([
88+
[protocolMap['1.19.3'], 0x60],
8089
[protocolMap['1.19.1'], 0x62],
8190
[protocolMap['1.19'], 0x5f]
8291
]),
8392

8493
// Serverbound (play)
8594
SERVERBOUND_KEEP_ALIVE: generateIdFunction([
95+
[protocolMap['1.19.3'], 0x11],
8696
[protocolMap['1.19.1'], 0x12],
8797
[protocolMap['1.19'], 0x11],
8898
[protocolMap['1.17'], 0x0f],
8999
[protocolMap['1.16.4'], 0x10]
90100
]),
91101
SERVERBOUND_CLOSE_WINDOW: generateIdFunction([
102+
[protocolMap['1.19.3'], 0x0f],
92103
[protocolMap['1.19.1'], 0x0c],
93104
[protocolMap['1.19'], 0x0b],
94105
[protocolMap['1.17'], 0x09],
95106
[protocolMap['1.16.4'], 0x0a]
96107
]),
97108
SERVERBOUND_CLIENT_SETTINGS: generateIdFunction([
109+
[protocolMap['1.19.3'], 0x07],
98110
[protocolMap['1.19.1'], 0x08],
99111
[protocolMap['1.19'], 0x07],
100112
[protocolMap['1.16.4'], 0x05]
101113
]),
102114
SERVERBOUND_CLIENT_STATUS: generateIdFunction([
115+
[protocolMap['1.19.3'], 0x06],
103116
[protocolMap['1.19.1'], 0x07],
104117
[protocolMap['1.19'], 0x06],
105118
[protocolMap['1.16.4'], 0x04]

src/minecraft/utils.ts

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ export const protocolMap = {
1313
1.19: 759,
1414
'1.19.1': 760,
1515
'1.19.2': 760,
16+
'1.19.3': 761,
17+
latest: 761,
1618
auto: -1
1719
}
1820

src/screens/ServerScreen.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,10 @@ const ServerScreen = (props: Props) => {
9191

9292
const connectToServer = (serverName: string) => {
9393
let version = protocolMap[servers[serverName].version]
94-
const latestVersion = '1.19.1'
9594
if (version === -1) {
9695
const ping = pingResponses[servers[serverName].address]
9796
// Try the latest.
98-
if (!ping) version = protocolMap[latestVersion]
97+
if (!ping) version = protocolMap.latest
9998
else if (typeof ping.version === 'object') {
10099
version = ping.version.protocol
101100
} else version = (ping as LegacyPing).protocol
@@ -105,7 +104,7 @@ const ServerScreen = (props: Props) => {
105104
server: serverName,
106105
reason: 'EnderChat only supports 1.16.4 and newer (for now).'
107106
})
108-
} else if (version > protocolMap[latestVersion]) {
107+
} else if (version > protocolMap.latest) {
109108
return setDisconnectReason({
110109
server: serverName,
111110
reason:

0 commit comments

Comments
 (0)