UNPKG

@kobold/core

Version:

Kobold core

68 lines (62 loc) 2.65 kB
"use strict"; var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property"); _Object$defineProperty(exports, "__esModule", { value: true }); exports.sqPackIndex2Parser = exports.sqPackIndexParser = void 0; var _binaryParser = require("binary-parser"); const sqPackHeaderParser = new _binaryParser.Parser().endianess('little').saveOffset('__start').array('magic', { type: 'uint8', length: 8 }).uint8('platformId').seek(3) // unknown .uint32('size').uint32('version').uint32('type') // Skip the remainder of the size .saveOffset('__current').seek(function () { return this.size - (this.__current - this.__start); }); const lsdParser = new _binaryParser.Parser().endianess('little').uint32('location').uint32('size').buffer('digest', { length: 64 }); const sqPackIndexHeaderParser = new _binaryParser.Parser().endianess('little').saveOffset('__start').uint32('size').uint32('version').nest('indexData', { type: lsdParser }).uint32('dataFileCount').nest('synonymData', { type: lsdParser }).nest('emptyBlockData', { type: lsdParser }).nest('dirIndexData', { type: lsdParser }).uint32('indexType').seek(656) // reserved .buffer('selfHash', { length: 64 }).saveOffset('__current').seek(function () { return this.size - (this.__current - this.__start); }); const hashTablePackedOffsetParser = new _binaryParser.Parser().endianess('little').uint32('data'); const indexHashTableEntryParser = new _binaryParser.Parser().endianess('little').uint64('hash').nest({ type: hashTablePackedOffsetParser }).seek(4); // padding const index2HashTableEntryParser = new _binaryParser.Parser().endianess('little').uint32('hash').nest({ type: hashTablePackedOffsetParser }); const sqPackIndexParser = new _binaryParser.Parser().nest('sqPackHeader', { type: sqPackHeaderParser }).nest('sqPackIndexHeader', { type: sqPackIndexHeaderParser }).saveOffset('__current').seek(function () { return this.sqPackIndexHeader.indexData.location - this.__current; }).array('indexes', { type: indexHashTableEntryParser, // TODO: would be nice to type this properly lengthInBytes: 'sqPackIndexHeader.indexData.size' }); exports.sqPackIndexParser = sqPackIndexParser; const sqPackIndex2Parser = new _binaryParser.Parser().nest('sqPackHeader', { type: sqPackHeaderParser }).nest('sqPackIndexHeader', { type: sqPackIndexHeaderParser }).saveOffset('__current').seek(function () { return this.sqPackIndexHeader.indexData.location - this.__current; }).array('indexes', { type: index2HashTableEntryParser, lengthInBytes: 'sqPackIndexHeader.indexData.size' }); exports.sqPackIndex2Parser = sqPackIndex2Parser;