diff --git a/utils/parse-text-dump.mjs b/utils/parse-text-dump.mjs index bc163a0..cbfb980 100644 --- a/utils/parse-text-dump.mjs +++ b/utils/parse-text-dump.mjs @@ -1,4 +1,4 @@ -import { Utils, NiimbotPacket, RequestCommandId, ResponseCommandId } from "../dist/index.js"; +import { Utils, NiimbotPacket, RequestCommandId, ResponseCommandId, PacketParser } from "../dist/index.js"; import fs from "fs"; // usage: yarn parse-text-dump <path> [data | min | min-out | print-task] @@ -29,8 +29,8 @@ for (const line of lines) { let comment = ""; try { - const data = Utils.hexToBuf(hexData); - const packets = NiimbotPacket.fromBytesMultiPacket(data); + const data = Utils.hexToBuf(hexData.startsWith("03") ? hexData.substring(2) : hexData); + const packets = PacketParser.parsePacketBundle(data); if (packets.length === 0) { comment = "Parse error (no packets found)"; diff --git a/utils/parse-wireshark-dump.mjs b/utils/parse-wireshark-dump.mjs index 9b17f4c..dc6b4d4 100644 --- a/utils/parse-wireshark-dump.mjs +++ b/utils/parse-wireshark-dump.mjs @@ -1,4 +1,4 @@ -import { Utils, NiimbotPacket, RequestCommandId, ResponseCommandId } from "../dist/index.js"; +import { Utils, NiimbotPacket, RequestCommandId, ResponseCommandId, PacketParser } from "../dist/index.js"; import { spawn } from "child_process"; const TSHARK_PATH = "C:\\Program Files\\Wireshark\\tshark.exe"; @@ -54,8 +54,8 @@ spawned.on("close", (code) => { let comment = ""; try { - const data = Utils.hexToBuf(hexData); - const packets = NiimbotPacket.fromBytesMultiPacket(data); + const data = Utils.hexToBuf(hexData.startsWith("03") ? hexData.substring(2) : hexData); + const packets = PacketParser.parsePacketBundle(data); if (packets.length === 0) { comment = "Parse error (no packets found)"; @@ -79,7 +79,7 @@ spawned.on("close", (code) => { } else { comment += ResponseCommandId[packet.command] ?? "???"; } - + if (display === "data") { comment += `(${packet.dataLength}: ${Utils.bufToHex(packet.data)}); `; } else {