Skip to content

Commit

Permalink
Add support for Minecraft 1.19.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Feb 24, 2023
1 parent a95b3a7 commit eeb4702
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,17 @@ class ConnectionModule(reactContext: ReactApplicationContext)
val is117 = protocolVersion >= PROTOCOL_VERSION_117
val is119 = protocolVersion >= PROTOCOL_VERSION_119
val is1191 = protocolVersion >= PROTOCOL_VERSION_1191
val is1193 = protocolVersion >= PROTOCOL_VERSION_1193
val keepAliveClientBoundId =
if (is1191) 0x20
if (is1193) 0x1f
else if (is1191) 0x20
else if (is119) 0x1e
else if (is117) 0x21
else if (is1164) 0x1f
else 0x1f
val keepAliveServerBoundId =
if (is1191) 0x12
if (is1193) 0x11
else if (is1191) 0x12
else if (is119) 0x11
else if (is117) 0x0f
else if (is1164) 0x10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const val PROTOCOL_VERSION_1164 = 754
const val PROTOCOL_VERSION_117 = 755
const val PROTOCOL_VERSION_119 = 759
const val PROTOCOL_VERSION_1191 = 760
const val PROTOCOL_VERSION_1193 = 761

fun compressData(bytes: ByteArray): ByteArray {
ByteArrayOutputStream(bytes.size).use {
Expand Down
1 change: 1 addition & 0 deletions src/components/servers/EditServerDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const EditServerDialog = ({
dropdownIconColor={darkMode ? '#ffffff' : '#000000'}
>
<Picker.Item label='Auto' value='auto' />
<Picker.Item label='1.19.3 (WIP)' value='1.19.3' />
<Picker.Item label='1.19.1/1.19.2 (WIP)' value='1.19.1' />
<Picker.Item label='1.19 (WIP)' value='1.19' />
<Picker.Item label='1.18.2' value='1.18.2' />
Expand Down
4 changes: 1 addition & 3 deletions src/minecraft/connection/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from '../packet'
import { ServerConnection, ConnectionOptions } from '.'
import { getLoginPacket, handleEncryptionRequest } from './shared'
import { readVarInt, writeVarInt, resolveHostname, protocolMap } from '../utils'
import { readVarInt, writeVarInt, resolveHostname } from '../utils'
import packetIds from '../packets/ids'

export declare interface JavaScriptServerConnection {
Expand Down Expand Up @@ -46,7 +46,6 @@ export class JavaScriptServerConnection
disconnectReason?: string
aesDecipher?: Decipher
aesCipher?: Cipher
msgSalt?: Buffer

constructor(socket: net.Socket, options: ConnectionOptions) {
super()
Expand Down Expand Up @@ -180,7 +179,6 @@ const initiateJavaScriptConnection = async (opts: ConnectionOptions) => {
accessToken,
selectedProfile,
conn,
version >= protocolMap['1.19'],
async (secret: Buffer, response: Buffer) => {
const AES_ALG = 'aes-128-cfb8'
conn.aesDecipher = createDecipheriv(AES_ALG, secret, secret)
Expand Down
3 changes: 1 addition & 2 deletions src/minecraft/connection/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import events from 'events'
import { ServerConnection, ConnectionOptions } from '.'
import { concatPacketData, Packet } from '../packet'
import { getLoginPacket, handleEncryptionRequest } from './shared'
import { readVarInt, writeVarInt, resolveHostname, protocolMap } from '../utils'
import { readVarInt, writeVarInt, resolveHostname } from '../utils'
import packetIds from '../packets/ids'

const { ConnectionModule } = NativeModules
Expand Down Expand Up @@ -120,7 +120,6 @@ export class NativeServerConnection
accessToken,
selectedProfile,
this,
version >= protocolMap['1.19'],
async (secret: Buffer, response: Buffer) => {
const eSecret = secret.toString('base64')
const eResp = response.toString('base64')
Expand Down
25 changes: 14 additions & 11 deletions src/minecraft/connection/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export const parseEncryptionRequestPacket = (packet: Packet) => {

export const getLoginPacket = (opts: ConnectionOptions) => {
const data: PacketDataTypes[] = [opts.username]
if (opts.protocolVersion >= protocolMap[1.19]) {
if (
opts.protocolVersion >= protocolMap[1.19] &&
opts.protocolVersion < protocolMap['1.19.3']
) {
data.push(false)
/* TODO: Support chat signing properly.
data.push(!!opts.certificate)
Expand All @@ -49,13 +52,13 @@ export const getLoginPacket = (opts: ConnectionOptions) => {
data.push(writeVarInt(buf.byteLength))
data.push(buf)
} */
if (opts.protocolVersion >= protocolMap['1.19.1']) {
if (opts.selectedProfile) {
const msb = Buffer.from(opts.selectedProfile.substring(0, 16), 'hex')
const lsb = Buffer.from(opts.selectedProfile.substring(16), 'hex')
data.push(concatPacketData([true, msb, lsb]))
} else data.push(concatPacketData([false]))
}
}
if (opts.protocolVersion >= protocolMap['1.19.1']) {
if (opts.selectedProfile) {
const msb = Buffer.from(opts.selectedProfile.substring(0, 16), 'hex')
const lsb = Buffer.from(opts.selectedProfile.substring(16), 'hex')
data.push(concatPacketData([true, msb, lsb]))
} else data.push(concatPacketData([false]))
}
return concatPacketData(data)
}
Expand All @@ -65,7 +68,6 @@ export const handleEncryptionRequest = (
accessToken: string,
selectedProfile: string,
connection: ServerConnection,
is119: boolean,
callback: (secret: Buffer, response: Buffer) => Promise<void>
) => {
// https://wiki.vg/Protocol_Encryption
Expand Down Expand Up @@ -100,9 +102,10 @@ export const handleEncryptionRequest = (
writeVarInt(encryptedVerifyToken.byteLength),
encryptedVerifyToken
]
if (is119) {
const { protocolVersion } = connection.options
if (protocolVersion >= protocolMap['1.19']) {
connection.msgSalt = await getRandomBytes(8)
response.splice(2, 0, true)
if (protocolVersion < protocolMap['1.19.3']) response.splice(2, 0, true)
}
// This callback will send the response and enable the ciphers.
await callback(secret, concatPacketData(response))
Expand Down
2 changes: 2 additions & 0 deletions src/minecraft/packets/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const makeChatMessagePacket = (
): [number, Buffer] => {
const is119 = protocolVersion >= protocolMap[1.19]
const is1191 = protocolVersion >= protocolMap['1.19.1']
const is1193 = protocolVersion >= protocolMap['1.19.3']
if (!is119) {
const id = packetIds.SERVERBOUND_CHAT_MESSAGE(protocolVersion)
return [id ?? 0, concatPacketData([msg])]
Expand All @@ -28,6 +29,7 @@ export const makeChatMessagePacket = (
false
]
if (is1191) data.push(writeVarInt(0), writeVarInt(0))
if (is1193) data.push(writeVarInt(0))
return [id ?? 0, concatPacketData(data)]
}
}
13 changes: 13 additions & 0 deletions src/minecraft/packets/ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,48 @@ const packetIds = {

// Clientbound (play)
CLIENTBOUND_KEEP_ALIVE: generateIdFunction([
[protocolMap['1.19.3'], 0x1f],
[protocolMap['1.19.1'], 0x20],
[protocolMap['1.19'], 0x1e],
[protocolMap['1.17'], 0x21],
[protocolMap['1.16.4'], 0x1f]
]),
CLIENTBOUND_DISCONNECT_PLAY: generateIdFunction([
[protocolMap['1.19.3'], 0x17],
[protocolMap['1.19.1'], 0x19],
[protocolMap['1.19'], 0x17],
[protocolMap['1.17'], 0x1a],
[protocolMap['1.16.4'], 0x19]
]),
CLIENTBOUND_LOGIN_PLAY: generateIdFunction([
[protocolMap['1.19.3'], 0x24],
[protocolMap['1.19.1'], 0x25],
[protocolMap['1.19'], 0x23],
[protocolMap['1.17'], 0x26],
[protocolMap['1.16.4'], 0x24]
]),
CLIENTBOUND_RESPAWN: generateIdFunction([
[protocolMap['1.19.3'], 0x3d],
[protocolMap['1.19.1'], 0x3e],
[protocolMap['1.19'], 0x3b],
[protocolMap['1.17'], 0x3d],
[protocolMap['1.16.4'], 0x39]
]),
CLIENTBOUND_UPDATE_HEALTH: generateIdFunction([
[protocolMap['1.19.3'], 0x53],
[protocolMap['1.19.1'], 0x55],
[protocolMap['1.17'], 0x52],
[protocolMap['1.16.4'], 0x49]
]),
CLIENTBOUND_DEATH_COMBAT_EVENT: generateIdFunction([
[protocolMap['1.19.3'], 0x34],
[protocolMap['1.19.1'], 0x36],
[protocolMap['1.19'], 0x33],
[protocolMap['1.17'], 0x35],
[protocolMap['1.16.4'], 0x31]
]),
CLIENTBOUND_OPEN_WINDOW: generateIdFunction([
[protocolMap['1.19.3'], 0x2c],
[protocolMap['1.19.1'], 0x2d],
[protocolMap['1.19'], 0x2b],
[protocolMap['1.16.4'], 0x2e]
Expand All @@ -73,33 +80,39 @@ const packetIds = {
[protocolMap['1.16.4'], 0x0e]
]),
CLIENTBOUND_PLAYER_CHAT_MESSAGE: generateIdFunction([
[protocolMap['1.19.3'], 0x31],
[protocolMap['1.19.1'], 0x33],
[protocolMap['1.19'], 0x30]
]),
CLIENTBOUND_SYSTEM_CHAT_MESSAGE: generateIdFunction([
[protocolMap['1.19.3'], 0x60],
[protocolMap['1.19.1'], 0x62],
[protocolMap['1.19'], 0x5f]
]),

// Serverbound (play)
SERVERBOUND_KEEP_ALIVE: generateIdFunction([
[protocolMap['1.19.3'], 0x11],
[protocolMap['1.19.1'], 0x12],
[protocolMap['1.19'], 0x11],
[protocolMap['1.17'], 0x0f],
[protocolMap['1.16.4'], 0x10]
]),
SERVERBOUND_CLOSE_WINDOW: generateIdFunction([
[protocolMap['1.19.3'], 0x0f],
[protocolMap['1.19.1'], 0x0c],
[protocolMap['1.19'], 0x0b],
[protocolMap['1.17'], 0x09],
[protocolMap['1.16.4'], 0x0a]
]),
SERVERBOUND_CLIENT_SETTINGS: generateIdFunction([
[protocolMap['1.19.3'], 0x07],
[protocolMap['1.19.1'], 0x08],
[protocolMap['1.19'], 0x07],
[protocolMap['1.16.4'], 0x05]
]),
SERVERBOUND_CLIENT_STATUS: generateIdFunction([
[protocolMap['1.19.3'], 0x06],
[protocolMap['1.19.1'], 0x07],
[protocolMap['1.19'], 0x06],
[protocolMap['1.16.4'], 0x04]
Expand Down
2 changes: 2 additions & 0 deletions src/minecraft/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export const protocolMap = {
1.19: 759,
'1.19.1': 760,
'1.19.2': 760,
'1.19.3': 761,
latest: 761,
auto: -1
}

Expand Down
5 changes: 2 additions & 3 deletions src/screens/ServerScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,10 @@ const ServerScreen = (props: Props) => {

const connectToServer = (serverName: string) => {
let version = protocolMap[servers[serverName].version]
const latestVersion = '1.19.1'
if (version === -1) {
const ping = pingResponses[servers[serverName].address]
// Try the latest.
if (!ping) version = protocolMap[latestVersion]
if (!ping) version = protocolMap.latest
else if (typeof ping.version === 'object') {
version = ping.version.protocol
} else version = (ping as LegacyPing).protocol
Expand All @@ -105,7 +104,7 @@ const ServerScreen = (props: Props) => {
server: serverName,
reason: 'EnderChat only supports 1.16.4 and newer (for now).'
})
} else if (version > protocolMap[latestVersion]) {
} else if (version > protocolMap.latest) {
return setDisconnectReason({
server: serverName,
reason:
Expand Down

0 comments on commit eeb4702

Please sign in to comment.