(
modPath: string,
packReadingOptions: PackReadingOptions = { skipParsingTables: false },
)
| 2894 | }; |
| 2895 | export const matchDBFileRegex = /^db\\(.*?)\\/; |
| 2896 | export const readPack = async ( |
| 2897 | modPath: string, |
| 2898 | packReadingOptions: PackReadingOptions = { skipParsingTables: false }, |
| 2899 | ): Promise<Pack> => { |
| 2900 | const pack_files: PackedFile[] = []; |
| 2901 | let packHeader: PackHeader | undefined; |
| 2902 | const dependencyPacks: string[] = []; |
| 2903 | let lastChangedLocal = -1; |
| 2904 | let size = 0; |
| 2905 | try { |
| 2906 | const stats = await fsExtra.stat(modPath); |
| 2907 | lastChangedLocal = stats.mtimeMs; |
| 2908 | size = stats.size; |
| 2909 | } catch (e) { |
| 2910 | console.log(e); |
| 2911 | } |
| 2912 | // let file: BinaryFile | undefined; |
| 2913 | // eslint-disable-next-line @typescript-eslint/no-inferrable-types |
| 2914 | let fileId: number = -1; |
| 2915 | try { |
| 2916 | fileId = fs.openSync(modPath, "r"); |
| 2917 | // console.log(`${modPath} file opened`); |
| 2918 | // if (packReadingOptions.tablesToRead) |
| 2919 | // console.log(`NUM OF TABLES TO READ:`, packReadingOptions.tablesToRead.length); |
| 2920 | // header 4 |
| 2921 | // byteMask 4 |
| 2922 | // refFileCount 4 |
| 2923 | // pack_file_index_size 4 |
| 2924 | // pack_file_count 4 |
| 2925 | // packed_file_index_size 4 |
| 2926 | // headerBuffer 4 |
| 2927 | // header_buffer_len 4; |
| 2928 | const packedFileHeaderSize = 8 * 4; |
| 2929 | const packedFileHeader = Buffer.allocUnsafe(packedFileHeaderSize); |
| 2930 | fs.readSync(fileId, packedFileHeader, 0, packedFileHeader.length, 0); |
| 2931 | let packedFileHeaderPosition = 0; |
| 2932 | const header = await packedFileHeader.subarray(packedFileHeaderPosition, packedFileHeaderPosition + 4); |
| 2933 | packedFileHeaderPosition += 4; |
| 2934 | if (header === null) throw new Error("header missing"); |
| 2935 | if (appData.currentGame == "attila" && header.toString("hex") == "50464835") { |
| 2936 | throw new Error("WRONG HEADER: WH3 HEADER FOR WHEN CURRENT GAME IS ATTILA"); |
| 2937 | } |
| 2938 | const byteMask = await packedFileHeader.readInt32LE(packedFileHeaderPosition); |
| 2939 | packedFileHeaderPosition += 4; |
| 2940 | const refFileCount = await packedFileHeader.readInt32LE(packedFileHeaderPosition); |
| 2941 | packedFileHeaderPosition += 4; |
| 2942 | const pack_file_index_size = await packedFileHeader.readInt32LE(packedFileHeaderPosition); |
| 2943 | packedFileHeaderPosition += 4; |
| 2944 | const pack_file_count = await packedFileHeader.readInt32LE(packedFileHeaderPosition); |
| 2945 | packedFileHeaderPosition += 4; |
| 2946 | const packed_file_index_size = await packedFileHeader.readInt32LE(packedFileHeaderPosition); |
| 2947 | packedFileHeaderPosition += 4; |
| 2948 | const header_buffer_len = 4; |
| 2949 | const header_buffer = await packedFileHeader.subarray( |
| 2950 | packedFileHeaderPosition, |
| 2951 | packedFileHeaderPosition + header_buffer_len, |
| 2952 | ); |
| 2953 | packedFileHeaderPosition += header_buffer_len; |
no test coverage detected