( packReadingOptions: PackReadingOptions, dbPackFiles: PackedFile[], buffer: Buffer, startPos: number, modPath: string, )
| 2666 | } as Pack; |
| 2667 | }; |
| 2668 | const readDBPackedFiles = async ( |
| 2669 | packReadingOptions: PackReadingOptions, |
| 2670 | dbPackFiles: PackedFile[], |
| 2671 | buffer: Buffer, |
| 2672 | startPos: number, |
| 2673 | modPath: string, |
| 2674 | ) => { |
| 2675 | let currentPos = 0; |
| 2676 | for (const pack_file of dbPackFiles) { |
| 2677 | if ( |
| 2678 | packReadingOptions.tablesToRead && |
| 2679 | !packReadingOptions.tablesToRead.some((tableToRead) => pack_file.name.startsWith(tableToRead)) |
| 2680 | ) |
| 2681 | continue; |
| 2682 | // if (packReadingOptions.tablesToRead) { |
| 2683 | // console.log("READING TABLE ", pack_file.name); |
| 2684 | // } |
| 2685 | currentPos = pack_file.start_pos - startPos; |
| 2686 | const dbNameMatch = pack_file.name.match(matchDBFileRegex); |
| 2687 | if (dbNameMatch == null) continue; |
| 2688 | const dbName = dbNameMatch[1]; |
| 2689 | if (dbName == null) continue; |
| 2690 | const dbversions = DBNameToDBVersions[appData.currentGame][dbName]; |
| 2691 | if (!dbversions) continue; |
| 2692 | let packBuffer = buffer.subarray(currentPos, currentPos + pack_file.file_size); |
| 2693 | if (pack_file.is_compressed) { |
| 2694 | // console.log("dbbuffer before: currentPos", currentPos, "len", pack_file.file_size); |
| 2695 | // fs.writeFileSync("dbbuffer_raw_" + pack_file.name.replaceAll("\\", "_"), packBuffer); |
| 2696 | packBuffer = Buffer.from(await decompressPackedPayload(packBuffer, pack_file.name)); |
| 2697 | // fs.writeFileSync("dbbuffer_" + pack_file.name.replaceAll("\\", "_"), packBuffer); |
| 2698 | } |
| 2699 | currentPos = 0; |
| 2700 | // console.log(`reading ${pack_file.name}`); |
| 2701 | let version: number | undefined; |
| 2702 | for (;;) { |
| 2703 | const marker = await packBuffer.subarray(currentPos, currentPos + 4); |
| 2704 | currentPos += 4; |
| 2705 | if (marker.toString("hex") === "fdfefcff") { |
| 2706 | const readUTF = readUTFStringFromBuffer(packBuffer, currentPos); |
| 2707 | // console.log("guid is " + readUTF[0]); |
| 2708 | pack_file.guid = readUTF[0]; |
| 2709 | currentPos = readUTF[1]; |
| 2710 | // console.log("current pos after guid is:", currentPos); |
| 2711 | } else if (marker.toString("hex") === "fcfdfeff") { |
| 2712 | // console.log("found version marker"); |
| 2713 | version = packBuffer.readInt32LE(currentPos); // await file.readInt32(); |
| 2714 | currentPos += 4; |
| 2715 | pack_file.version = version; |
| 2716 | // await file.read(1); |
| 2717 | } else { |
| 2718 | // console.log(marker.toString("hex")); |
| 2719 | currentPos -= 4; |
| 2720 | currentPos += 1; |
| 2721 | // file.seek(file.tell() - 4); |
| 2722 | break; |
| 2723 | } |
| 2724 | // if (pack_file.name === "db\\character_skill_nodes_tables\\mixu_ll_empire") { |
| 2725 | // console.log(pack_file.name); |
no test coverage detected