@rhyster/wow-casc-dbc 2.11.60 → 2.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -53,6 +53,18 @@ const parser = await DBDParser.parse(reader);
53
53
  // ...
54
54
  ```
55
55
 
56
+ If you download DB2 files from wago.tools, you need to set `detectIsZeroedByData` to let `WDCReader` detect the undecrypted blocks and ignore them.
57
+
58
+ ```javascript
59
+ // ...
60
+
61
+ const file = await fs.readFile('/path/to/db2/file.db2');
62
+ const reader = new WDCReader(file, { detectIsZeroedByData: true });
63
+ const parser = await DBDParser.parse(reader);
64
+
65
+ // ...
66
+ ```
67
+
56
68
  ### Hotfix
57
69
 
58
70
  Applying hotfix requires `DBCache.bin` file from the client, and it seems the only way to get this is from the client. So, you need to search for `DBCache.bin` yourself, like `<WoWPath>/_retail_/Cache/ADB/enUS/DBCache.bin` or download it somewhere.
package/dist/index.cjs CHANGED
@@ -1096,6 +1096,15 @@ const readBitpackedValue = (buffer, fieldOffsetBits, fieldSizeBits, signed = fal
1096
1096
  }
1097
1097
  return signed ? BigInt.asIntN(fieldSizeBits, value >> BigInt(bitOffset)) : BigInt.asUintN(fieldSizeBits, value >> BigInt(bitOffset));
1098
1098
  };
1099
+ const isDataRangeAllZero = (buffer, offset, length) => {
1100
+ const end = offset + length;
1101
+ for (let pointer = offset; pointer < end; pointer += 1) {
1102
+ if (buffer[pointer] !== 0) {
1103
+ return false;
1104
+ }
1105
+ }
1106
+ return true;
1107
+ };
1099
1108
  class WDCReader {
1100
1109
  tableHash;
1101
1110
  layoutHash;
@@ -1108,7 +1117,28 @@ class WDCReader {
1108
1117
  relationships = /* @__PURE__ */ new Map();
1109
1118
  copyTable = /* @__PURE__ */ new Map();
1110
1119
  hotfixes = /* @__PURE__ */ new Map();
1111
- constructor(buffer, blocks = [], adb) {
1120
+ constructor(buffer, blocksOrOption, adbInput) {
1121
+ const options = blocksOrOption === void 0 || Array.isArray(blocksOrOption) ? { blocks: blocksOrOption, adb: adbInput } : blocksOrOption;
1122
+ const blocks = options.blocks ?? [];
1123
+ const adb = options.adb ?? adbInput;
1124
+ const detectIsZeroedByData = options.detectIsZeroedByData ?? false;
1125
+ const mergedBlocks = [];
1126
+ if (!detectIsZeroedByData) {
1127
+ blocks.sort((a, b) => a.offset - b.offset).forEach(({ offset, size }) => {
1128
+ const lastBlock = mergedBlocks[mergedBlocks.length - 1];
1129
+ if (mergedBlocks.length > 0 && lastBlock.offset + lastBlock.size >= offset) {
1130
+ lastBlock.size = Math.max(
1131
+ lastBlock.offset + lastBlock.size,
1132
+ offset + size
1133
+ ) - lastBlock.offset;
1134
+ } else {
1135
+ mergedBlocks.push({
1136
+ offset,
1137
+ size
1138
+ });
1139
+ }
1140
+ });
1141
+ }
1112
1142
  const magic = buffer.readUInt32BE(0);
1113
1143
  const version = buffer.readUInt32LE(4);
1114
1144
  const fieldCount = buffer.readUInt32LE(140);
@@ -1301,7 +1331,7 @@ class WDCReader {
1301
1331
  const sectionRecordSize = isNormal ? sectionHeader.recordCount * recordSize + sectionHeader.stringTableSize : sectionHeader.offsetRecordsEnd - sectionPointer;
1302
1332
  const sectionSize = sectionRecordSize + sectionHeader.idListSize + sectionHeader.copyTableCount * 8 + sectionHeader.offsetMapIDCount * 10 + sectionHeader.relationshipDataSize;
1303
1333
  const recordDataSize = isNormal ? recordSize * sectionHeader.recordCount : sectionHeader.offsetRecordsEnd - sectionHeader.fileOffset;
1304
- const isZeroed = blocks.some((block) => {
1334
+ const isZeroed = detectIsZeroedByData ? sectionHeader.tactKeyHash !== 0n && isDataRangeAllZero(buffer, sectionHeader.fileOffset, recordDataSize) : mergedBlocks.some((block) => {
1305
1335
  const sectionStart = sectionHeader.fileOffset;
1306
1336
  const sectionEnd = sectionStart + sectionSize;
1307
1337
  const blockStart = block.offset;