From 0b9b6cb661c085241edfcfb92119a38a524929a2 Mon Sep 17 00:00:00 2001 From: Vitaly Date: Fri, 8 Aug 2025 01:56:04 +0300 Subject: [PATCH 1/3] part 1 --- README.MD | 2 +- src/index.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.MD b/README.MD index e9127a73..7978cee5 100644 --- a/README.MD +++ b/README.MD @@ -54,7 +54,7 @@ Howerver, it's known that these browsers have issues: ### Versions Support -Server versions 1.8 - 1.21.4 are supported. +Server versions 1.8 - 1.21.5 are supported. First class versions (most of the features are tested on these versions): - 1.19.4 diff --git a/src/index.ts b/src/index.ts index d28261f4..c0213f56 100644 --- a/src/index.ts +++ b/src/index.ts @@ -231,8 +231,12 @@ export async function connect (connectOptions: ConnectOptions) { bot.emit('end', '') bot.removeAllListeners() bot._client.removeAllListeners() - //@ts-expect-error TODO? - bot._client = undefined + bot._client = { + //@ts-expect-error + write (packetName) { + console.warn('Tried to write packet', packetName, 'after bot was destroyed') + } + } //@ts-expect-error window.bot = bot = undefined } From 9a8c840d35a91b2e54c1b47eef2ca51b232c3999 Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Fri, 8 Aug 2025 02:03:37 +0300 Subject: [PATCH 2/3] up proto --- package.json | 4 +- patches/minecraft-protocol.patch | 77 +++++++++----------------------- pnpm-lock.yaml | 16 +++---- 3 files changed, 31 insertions(+), 66 deletions(-) diff --git a/package.json b/package.json index 257fff7c..347353d6 100644 --- a/package.json +++ b/package.json @@ -219,8 +219,8 @@ ] }, "patchedDependencies": { - "pixelarticons@1.8.1": "patches/pixelarticons@1.8.1.patch", - "mineflayer-item-map-downloader@1.2.0": "patches/mineflayer-item-map-downloader@1.2.0.patch", + "pixelarticons@1.8.1": "/Users/vit/Documents/prismarine-web-client/patches/pixelarticons@1.8.1.patch", + "mineflayer-item-map-downloader@1.2.0": "/Users/vit/Documents/prismarine-web-client/patches/mineflayer-item-map-downloader@1.2.0.patch", "minecraft-protocol": "patches/minecraft-protocol.patch" }, "ignoredBuiltDependencies": [ diff --git a/patches/minecraft-protocol.patch b/patches/minecraft-protocol.patch index e74f7e1d..5dec44d7 100644 --- a/patches/minecraft-protocol.patch +++ b/patches/minecraft-protocol.patch @@ -1,8 +1,8 @@ diff --git a/src/client/chat.js b/src/client/chat.js -index a50f4b988ad9fb29d5eb9e1633b498615aa9cd28..b8b819eef0762a77d9db5c0fb06be648303628c7 100644 +index 0021870994fc59a82f0ac8aba0a65a8be43ef2f4..a53fceb843105ea2a1d88722b3fc7c3b43cb102a 100644 --- a/src/client/chat.js +++ b/src/client/chat.js -@@ -110,7 +110,7 @@ module.exports = function (client, options) { +@@ -116,7 +116,7 @@ module.exports = function (client, options) { for (const player of packet.data) { if (player.chatSession) { client._players[player.uuid] = { @@ -11,8 +11,8 @@ index a50f4b988ad9fb29d5eb9e1633b498615aa9cd28..b8b819eef0762a77d9db5c0fb06be648 publicKeyDER: player.chatSession.publicKey.keyBytes, sessionUuid: player.chatSession.uuid } -@@ -120,7 +120,7 @@ module.exports = function (client, options) { - +@@ -126,7 +126,7 @@ module.exports = function (client, options) { + if (player.crypto) { client._players[player.uuid] = { - publicKey: crypto.createPublicKey({ key: player.crypto.publicKey, format: 'der', type: 'spki' }), @@ -20,7 +20,7 @@ index a50f4b988ad9fb29d5eb9e1633b498615aa9cd28..b8b819eef0762a77d9db5c0fb06be648 publicKeyDER: player.crypto.publicKey, signature: player.crypto.signature, displayName: player.displayName || player.name -@@ -190,7 +190,7 @@ module.exports = function (client, options) { +@@ -196,7 +196,7 @@ module.exports = function (client, options) { if (mcData.supportFeature('useChatSessions')) { const tsDelta = BigInt(Date.now()) - packet.timestamp const expired = !packet.timestamp || tsDelta > messageExpireTime || tsDelta < 0 @@ -29,16 +29,16 @@ index a50f4b988ad9fb29d5eb9e1633b498615aa9cd28..b8b819eef0762a77d9db5c0fb06be648 if (verified) client._signatureCache.push(packet.signature) client.emit('playerChat', { globalIndex: packet.globalIndex, -@@ -356,7 +356,7 @@ module.exports = function (client, options) { +@@ -362,7 +362,7 @@ module.exports = function (client, options) { } } - + - client._signedChat = (message, options = {}) => { + client._signedChat = async (message, options = {}) => { options.timestamp = options.timestamp || BigInt(Date.now()) options.salt = options.salt || 1n - -@@ -401,7 +401,7 @@ module.exports = function (client, options) { + +@@ -407,7 +407,7 @@ module.exports = function (client, options) { message, timestamp: options.timestamp, salt: options.salt, @@ -47,7 +47,7 @@ index a50f4b988ad9fb29d5eb9e1633b498615aa9cd28..b8b819eef0762a77d9db5c0fb06be648 offset: client._lastSeenMessages.pending, checksum: computeChatChecksum(client._lastSeenMessages), // 1.21.5+ acknowledged -@@ -416,7 +416,7 @@ module.exports = function (client, options) { +@@ -422,7 +422,7 @@ module.exports = function (client, options) { message, timestamp: options.timestamp, salt: options.salt, @@ -71,10 +71,10 @@ index 63cc2bd9615100bd2fd63dfe14c094aa6b8cd1c9..36df57d1196af9761d920fa285ac48f8 + // clearTimeout(loginTimeout) + // }) } - + function onJoinServerResponse (err) { diff --git a/src/client.js b/src/client.js -index e369e77d055ba919e8f9da7b8e8b5dc879c74cf4..11c6bff299f1186ab1ecb6744f53ff0c648ab192 100644 +index e369e77d055ba919e8f9da7b8e8b5dc879c74cf4..54bb9e6644388e9b6bd42b3012951875989cdf0c 100644 --- a/src/client.js +++ b/src/client.js @@ -111,7 +111,13 @@ class Client extends EventEmitter { @@ -94,7 +94,7 @@ index e369e77d055ba919e8f9da7b8e8b5dc879c74cf4..11c6bff299f1186ab1ecb6744f53ff0c } @@ -169,7 +175,10 @@ class Client extends EventEmitter { } - + const onFatalError = (err) => { - this.emit('error', err) + // todo find out what is trying to write after client disconnect @@ -103,58 +103,23 @@ index e369e77d055ba919e8f9da7b8e8b5dc879c74cf4..11c6bff299f1186ab1ecb6744f53ff0c + } endSocket() } - -@@ -198,6 +207,8 @@ class Client extends EventEmitter { + +@@ -198,6 +207,10 @@ class Client extends EventEmitter { serializer -> framer -> socket -> splitter -> deserializer */ if (this.serializer) { this.serializer.end() -+ this.socket?.end() -+ this.socket?.emit('end') ++ setTimeout(() => { ++ this.socket?.end() ++ this.socket?.emit('end') ++ }, 2000) // allow the serializer to finish writing } else { if (this.socket) this.socket.end() } -@@ -243,6 +254,7 @@ class Client extends EventEmitter { +@@ -243,6 +256,7 @@ class Client extends EventEmitter { debug('writing packet ' + this.state + '.' + name) debug(params) } + this.emit('writePacket', name, params) this.serializer.write({ name, params }) } - -diff --git a/src/client.js.rej b/src/client.js.rej -new file mode 100644 -index 0000000000000000000000000000000000000000..1101e2477adfdc004381b78e7d70953dacb7b484 ---- /dev/null -+++ b/src/client.js.rej -@@ -0,0 +1,31 @@ -+@@ -89,10 +89,12 @@ -+ parsed.metadata.name = parsed.data.name -+ parsed.data = parsed.data.params -+ parsed.metadata.state = state -+- debug('read packet ' + state + '.' + parsed.metadata.name) -+- if (debug.enabled) { -+- const s = JSON.stringify(parsed.data, null, 2) -+- debug(s && s.length > 10000 ? parsed.data : s) -++ if (!globalThis.excludeCommunicationDebugEvents?.includes(parsed.metadata.name)) { -++ debug('read packet ' + state + '.' + parsed.metadata.name) -++ if (debug.enabled) { -++ const s = JSON.stringify(parsed.data, null, 2) -++ debug(s && s.length > 10000 ? parsed.data : s) -++ } -+ } -+ if (this._hasBundlePacket && parsed.metadata.name === 'bundle_delimiter') { -+ if (this._mcBundle.length) { // End bundle -+@@ -239,8 +252,11 @@ -+ -+ write (name, params) { -+ if (!this.serializer.writable) { return } -+- debug('writing packet ' + this.state + '.' + name) -+- debug(params) -++ if (!globalThis.excludeCommunicationDebugEvents?.includes(name)) { -++ debug(`[${this.state}] from ${this.isServer ? 'server' : 'client'}: ` + name) -++ debug(params) -++ } -++ this.emit('writePacket', name, params) -+ this.serializer.write({ name, params }) -+ } -+ + diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index db095f5b..132ef32c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -22,7 +22,7 @@ overrides: patchedDependencies: minecraft-protocol: - hash: b417b3b7c5fd96e59abab5c1075b86b88bada2c980e4b54df13ca69b8f0091d9 + hash: 2a88e61fea1825d9fa5f1584fde810421d553d23e45e6dc829c3697ee3358bea path: patches/minecraft-protocol.patch mineflayer-item-map-downloader@1.2.0: hash: a731ebbace2d8790c973ab3a5ba33494a6e9658533a9710dd8ba36f86db061ad @@ -142,7 +142,7 @@ importers: version: 3.92.0 minecraft-protocol: specifier: github:PrismarineJS/node-minecraft-protocol#master - version: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/b404bcaed4c039c5558e889c8617aa866cd7bddb(patch_hash=b417b3b7c5fd96e59abab5c1075b86b88bada2c980e4b54df13ca69b8f0091d9)(encoding@0.1.13) + version: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/b404bcaed4c039c5558e889c8617aa866cd7bddb(patch_hash=2a88e61fea1825d9fa5f1584fde810421d553d23e45e6dc829c3697ee3358bea)(encoding@0.1.13) mineflayer-item-map-downloader: specifier: github:zardoy/mineflayer-item-map-downloader version: https://codeload.github.com/zardoy/mineflayer-item-map-downloader/tar.gz/a8d210ecdcf78dd082fa149a96e1612cc9747824(patch_hash=a731ebbace2d8790c973ab3a5ba33494a6e9658533a9710dd8ba36f86db061ad)(encoding@0.1.13) @@ -13078,7 +13078,7 @@ snapshots: flatmap: 0.0.3 long: 5.3.1 minecraft-data: 3.92.0 - minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/b404bcaed4c039c5558e889c8617aa866cd7bddb(patch_hash=b417b3b7c5fd96e59abab5c1075b86b88bada2c980e4b54df13ca69b8f0091d9)(encoding@0.1.13) + minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/b404bcaed4c039c5558e889c8617aa866cd7bddb(patch_hash=2a88e61fea1825d9fa5f1584fde810421d553d23e45e6dc829c3697ee3358bea)(encoding@0.1.13) mkdirp: 2.1.6 node-gzip: 1.1.2 node-rsa: 1.1.1 @@ -13114,7 +13114,7 @@ snapshots: flatmap: 0.0.3 long: 5.3.1 minecraft-data: 3.92.0 - minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/b404bcaed4c039c5558e889c8617aa866cd7bddb(patch_hash=b417b3b7c5fd96e59abab5c1075b86b88bada2c980e4b54df13ca69b8f0091d9)(encoding@0.1.13) + minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/b404bcaed4c039c5558e889c8617aa866cd7bddb(patch_hash=2a88e61fea1825d9fa5f1584fde810421d553d23e45e6dc829c3697ee3358bea)(encoding@0.1.13) mkdirp: 2.1.6 node-gzip: 1.1.2 node-rsa: 1.1.1 @@ -16961,7 +16961,7 @@ snapshots: dependencies: '@zardoy/flying-squid': 0.0.49(encoding@0.1.13) exit-hook: 2.2.1 - minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/b404bcaed4c039c5558e889c8617aa866cd7bddb(patch_hash=b417b3b7c5fd96e59abab5c1075b86b88bada2c980e4b54df13ca69b8f0091d9)(encoding@0.1.13) + minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/b404bcaed4c039c5558e889c8617aa866cd7bddb(patch_hash=2a88e61fea1825d9fa5f1584fde810421d553d23e45e6dc829c3697ee3358bea)(encoding@0.1.13) mineflayer: https://codeload.github.com/zardoy/mineflayer/tar.gz/c9c77d6511e37c452ebe48790724da165d6ad448(encoding@0.1.13) prismarine-item: 1.17.0 ws: 8.18.1 @@ -17280,7 +17280,7 @@ snapshots: - '@types/react' - react - minecraft-protocol@https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/b404bcaed4c039c5558e889c8617aa866cd7bddb(patch_hash=b417b3b7c5fd96e59abab5c1075b86b88bada2c980e4b54df13ca69b8f0091d9)(encoding@0.1.13): + minecraft-protocol@https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/b404bcaed4c039c5558e889c8617aa866cd7bddb(patch_hash=2a88e61fea1825d9fa5f1584fde810421d553d23e45e6dc829c3697ee3358bea)(encoding@0.1.13): dependencies: '@types/node-rsa': 1.1.4 '@types/readable-stream': 4.0.18 @@ -17360,7 +17360,7 @@ snapshots: mineflayer@4.31.0(encoding@0.1.13): dependencies: minecraft-data: 3.92.0 - minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/b404bcaed4c039c5558e889c8617aa866cd7bddb(patch_hash=b417b3b7c5fd96e59abab5c1075b86b88bada2c980e4b54df13ca69b8f0091d9)(encoding@0.1.13) + minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/b404bcaed4c039c5558e889c8617aa866cd7bddb(patch_hash=2a88e61fea1825d9fa5f1584fde810421d553d23e45e6dc829c3697ee3358bea)(encoding@0.1.13) prismarine-biome: 1.3.0(minecraft-data@3.92.0)(prismarine-registry@1.11.0) prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9 prismarine-chat: 1.11.0 @@ -17384,7 +17384,7 @@ snapshots: dependencies: '@nxg-org/mineflayer-physics-util': 1.8.10 minecraft-data: 3.92.0 - minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/b404bcaed4c039c5558e889c8617aa866cd7bddb(patch_hash=b417b3b7c5fd96e59abab5c1075b86b88bada2c980e4b54df13ca69b8f0091d9)(encoding@0.1.13) + minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/b404bcaed4c039c5558e889c8617aa866cd7bddb(patch_hash=2a88e61fea1825d9fa5f1584fde810421d553d23e45e6dc829c3697ee3358bea)(encoding@0.1.13) prismarine-biome: 1.3.0(minecraft-data@3.92.0)(prismarine-registry@1.11.0) prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9 prismarine-chat: 1.11.0 From 9e1aaceb07d021482713180f35fd248dfe392ad9 Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Fri, 8 Aug 2025 02:06:57 +0300 Subject: [PATCH 3/3] fix patches path --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 347353d6..257fff7c 100644 --- a/package.json +++ b/package.json @@ -219,8 +219,8 @@ ] }, "patchedDependencies": { - "pixelarticons@1.8.1": "/Users/vit/Documents/prismarine-web-client/patches/pixelarticons@1.8.1.patch", - "mineflayer-item-map-downloader@1.2.0": "/Users/vit/Documents/prismarine-web-client/patches/mineflayer-item-map-downloader@1.2.0.patch", + "pixelarticons@1.8.1": "patches/pixelarticons@1.8.1.patch", + "mineflayer-item-map-downloader@1.2.0": "patches/mineflayer-item-map-downloader@1.2.0.patch", "minecraft-protocol": "patches/minecraft-protocol.patch" }, "ignoredBuiltDependencies": [