@rhyster/wow-casc-dbc 2.4.0 → 2.5.0
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/dist/index.cjs +54 -22
- package/dist/index.mjs +54 -22
- package/package.json +8 -7
package/dist/index.cjs
CHANGED
|
@@ -912,14 +912,10 @@ const readBitpackedValue = (buffer, fieldOffsetBits, fieldSizeBits, signed = fal
|
|
|
912
912
|
signed ? BigInt.asIntN(fieldSizeBits, BigInt(rawValue >>> bitOffset)) : BigInt.asUintN(fieldSizeBits, BigInt(rawValue >>> bitOffset))
|
|
913
913
|
);
|
|
914
914
|
}
|
|
915
|
-
let remain = sizeBytes;
|
|
916
915
|
let value = 0n;
|
|
917
|
-
|
|
918
|
-
const
|
|
919
|
-
|
|
920
|
-
const rawValue = buffer.readUIntLE(offset, byteLength);
|
|
921
|
-
value = value << BigInt(byteLength * 8) | BigInt(rawValue);
|
|
922
|
-
remain -= byteLength;
|
|
916
|
+
for (let i = sizeBytes - 1; i >= 0; i -= 1) {
|
|
917
|
+
const byte = buffer.readUInt8(offsetBytes + i);
|
|
918
|
+
value = value << 8n | BigInt(byte);
|
|
923
919
|
}
|
|
924
920
|
return signed ? BigInt.asIntN(fieldSizeBits, value >> BigInt(bitOffset)) : BigInt.asUintN(fieldSizeBits, value >> BigInt(bitOffset));
|
|
925
921
|
};
|
|
@@ -1740,6 +1736,15 @@ const castBigInt64 = (value, srcSigned, dstSigned) => {
|
|
|
1740
1736
|
}
|
|
1741
1737
|
return dstSigned ? castBuffer.readBigInt64LE(0) : castBuffer.readBigUInt64LE(0);
|
|
1742
1738
|
};
|
|
1739
|
+
const getCastBuffer = (value, srcSize, dstSize) => {
|
|
1740
|
+
const castBuffer = Buffer.alloc(dstSize);
|
|
1741
|
+
let remain = value;
|
|
1742
|
+
for (let i = 0; i < srcSize && remain > 0n; i += 1, remain >>= 8n) {
|
|
1743
|
+
const byte = Number(BigInt.asUintN(8, remain));
|
|
1744
|
+
castBuffer.writeUInt8(byte, i);
|
|
1745
|
+
}
|
|
1746
|
+
return castBuffer;
|
|
1747
|
+
};
|
|
1743
1748
|
class DBDParser {
|
|
1744
1749
|
constructor(wdc) {
|
|
1745
1750
|
__publicField$1(this, "wdc");
|
|
@@ -1867,9 +1872,12 @@ class DBDParser {
|
|
|
1867
1872
|
}
|
|
1868
1873
|
} else if (column.type === "float") {
|
|
1869
1874
|
if (column.arraySize) {
|
|
1870
|
-
|
|
1875
|
+
const castBuffer = getCastBuffer(
|
|
1876
|
+
typeof cell.data === "number" ? BigInt(cell.data) : cell.data,
|
|
1877
|
+
srcSize,
|
|
1878
|
+
4 * column.arraySize
|
|
1879
|
+
);
|
|
1871
1880
|
const values = [];
|
|
1872
|
-
const castBuffer = Buffer.from(cell.data.toString(16).padStart(8 * column.arraySize, "0"), "hex");
|
|
1873
1881
|
for (let i = 0; i < column.arraySize; i += 1) {
|
|
1874
1882
|
const value = castBuffer.readFloatLE(i * 4);
|
|
1875
1883
|
values.push(Math.round(value * 100) / 100);
|
|
@@ -1879,25 +1887,49 @@ class DBDParser {
|
|
|
1879
1887
|
assert__default(typeof cell.data === "number", `Invalid data type for float column ${column.name}`);
|
|
1880
1888
|
data[column.name] = castFloat(cell.data, srcSize, srcSigned);
|
|
1881
1889
|
}
|
|
1882
|
-
} else if (
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1890
|
+
} else if (column.type === "int") {
|
|
1891
|
+
if (column.arraySize) {
|
|
1892
|
+
assert__default(dstSize, `Missing size for int array column ${column.name}`);
|
|
1893
|
+
const castBuffer = getCastBuffer(
|
|
1894
|
+
typeof cell.data === "number" ? BigInt(cell.data) : cell.data,
|
|
1895
|
+
srcSize,
|
|
1896
|
+
4 * column.arraySize
|
|
1897
|
+
);
|
|
1898
|
+
const values = [];
|
|
1899
|
+
if (column.isSigned) {
|
|
1900
|
+
for (let i = 0; i < column.arraySize; i += 1) {
|
|
1901
|
+
const value = castBuffer.readIntLE(i * dstSize, dstSize);
|
|
1902
|
+
values.push(value);
|
|
1903
|
+
}
|
|
1904
|
+
} else {
|
|
1905
|
+
for (let i = 0; i < column.arraySize; i += 1) {
|
|
1906
|
+
const value = castBuffer.readUIntLE(i * dstSize, dstSize);
|
|
1907
|
+
values.push(value);
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1910
|
+
data[column.name] = values;
|
|
1911
|
+
} else if (typeof cell.data === "number") {
|
|
1912
|
+
data[column.name] = castIntegerBySize(
|
|
1894
1913
|
cell.data,
|
|
1914
|
+
srcSize,
|
|
1895
1915
|
srcSigned,
|
|
1916
|
+
dstSize ?? srcSize,
|
|
1896
1917
|
column.isSigned
|
|
1897
1918
|
);
|
|
1898
1919
|
} else {
|
|
1899
|
-
|
|
1920
|
+
assert__default(!column.size || column.size === 64, `Unexpected size ${column.size?.toString() ?? ""} for column ${column.name}`);
|
|
1921
|
+
if (srcSigned !== column.isSigned) {
|
|
1922
|
+
data[column.name] = castBigInt64(
|
|
1923
|
+
cell.data,
|
|
1924
|
+
srcSigned,
|
|
1925
|
+
column.isSigned
|
|
1926
|
+
);
|
|
1927
|
+
} else {
|
|
1928
|
+
data[column.name] = cell.data;
|
|
1929
|
+
}
|
|
1900
1930
|
}
|
|
1931
|
+
} else {
|
|
1932
|
+
throw new Error(`Unsupported column type ${column.type} for column ${column.name}`);
|
|
1901
1933
|
}
|
|
1902
1934
|
fieldIndex += 1;
|
|
1903
1935
|
} else if (column.isRelation) {
|
package/dist/index.mjs
CHANGED
|
@@ -900,14 +900,10 @@ const readBitpackedValue = (buffer, fieldOffsetBits, fieldSizeBits, signed = fal
|
|
|
900
900
|
signed ? BigInt.asIntN(fieldSizeBits, BigInt(rawValue >>> bitOffset)) : BigInt.asUintN(fieldSizeBits, BigInt(rawValue >>> bitOffset))
|
|
901
901
|
);
|
|
902
902
|
}
|
|
903
|
-
let remain = sizeBytes;
|
|
904
903
|
let value = 0n;
|
|
905
|
-
|
|
906
|
-
const
|
|
907
|
-
|
|
908
|
-
const rawValue = buffer.readUIntLE(offset, byteLength);
|
|
909
|
-
value = value << BigInt(byteLength * 8) | BigInt(rawValue);
|
|
910
|
-
remain -= byteLength;
|
|
904
|
+
for (let i = sizeBytes - 1; i >= 0; i -= 1) {
|
|
905
|
+
const byte = buffer.readUInt8(offsetBytes + i);
|
|
906
|
+
value = value << 8n | BigInt(byte);
|
|
911
907
|
}
|
|
912
908
|
return signed ? BigInt.asIntN(fieldSizeBits, value >> BigInt(bitOffset)) : BigInt.asUintN(fieldSizeBits, value >> BigInt(bitOffset));
|
|
913
909
|
};
|
|
@@ -1728,6 +1724,15 @@ const castBigInt64 = (value, srcSigned, dstSigned) => {
|
|
|
1728
1724
|
}
|
|
1729
1725
|
return dstSigned ? castBuffer.readBigInt64LE(0) : castBuffer.readBigUInt64LE(0);
|
|
1730
1726
|
};
|
|
1727
|
+
const getCastBuffer = (value, srcSize, dstSize) => {
|
|
1728
|
+
const castBuffer = Buffer.alloc(dstSize);
|
|
1729
|
+
let remain = value;
|
|
1730
|
+
for (let i = 0; i < srcSize && remain > 0n; i += 1, remain >>= 8n) {
|
|
1731
|
+
const byte = Number(BigInt.asUintN(8, remain));
|
|
1732
|
+
castBuffer.writeUInt8(byte, i);
|
|
1733
|
+
}
|
|
1734
|
+
return castBuffer;
|
|
1735
|
+
};
|
|
1731
1736
|
class DBDParser {
|
|
1732
1737
|
constructor(wdc) {
|
|
1733
1738
|
__publicField$1(this, "wdc");
|
|
@@ -1855,9 +1860,12 @@ class DBDParser {
|
|
|
1855
1860
|
}
|
|
1856
1861
|
} else if (column.type === "float") {
|
|
1857
1862
|
if (column.arraySize) {
|
|
1858
|
-
|
|
1863
|
+
const castBuffer = getCastBuffer(
|
|
1864
|
+
typeof cell.data === "number" ? BigInt(cell.data) : cell.data,
|
|
1865
|
+
srcSize,
|
|
1866
|
+
4 * column.arraySize
|
|
1867
|
+
);
|
|
1859
1868
|
const values = [];
|
|
1860
|
-
const castBuffer = Buffer.from(cell.data.toString(16).padStart(8 * column.arraySize, "0"), "hex");
|
|
1861
1869
|
for (let i = 0; i < column.arraySize; i += 1) {
|
|
1862
1870
|
const value = castBuffer.readFloatLE(i * 4);
|
|
1863
1871
|
values.push(Math.round(value * 100) / 100);
|
|
@@ -1867,25 +1875,49 @@ class DBDParser {
|
|
|
1867
1875
|
assert(typeof cell.data === "number", `Invalid data type for float column ${column.name}`);
|
|
1868
1876
|
data[column.name] = castFloat(cell.data, srcSize, srcSigned);
|
|
1869
1877
|
}
|
|
1870
|
-
} else if (
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1878
|
+
} else if (column.type === "int") {
|
|
1879
|
+
if (column.arraySize) {
|
|
1880
|
+
assert(dstSize, `Missing size for int array column ${column.name}`);
|
|
1881
|
+
const castBuffer = getCastBuffer(
|
|
1882
|
+
typeof cell.data === "number" ? BigInt(cell.data) : cell.data,
|
|
1883
|
+
srcSize,
|
|
1884
|
+
4 * column.arraySize
|
|
1885
|
+
);
|
|
1886
|
+
const values = [];
|
|
1887
|
+
if (column.isSigned) {
|
|
1888
|
+
for (let i = 0; i < column.arraySize; i += 1) {
|
|
1889
|
+
const value = castBuffer.readIntLE(i * dstSize, dstSize);
|
|
1890
|
+
values.push(value);
|
|
1891
|
+
}
|
|
1892
|
+
} else {
|
|
1893
|
+
for (let i = 0; i < column.arraySize; i += 1) {
|
|
1894
|
+
const value = castBuffer.readUIntLE(i * dstSize, dstSize);
|
|
1895
|
+
values.push(value);
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
data[column.name] = values;
|
|
1899
|
+
} else if (typeof cell.data === "number") {
|
|
1900
|
+
data[column.name] = castIntegerBySize(
|
|
1882
1901
|
cell.data,
|
|
1902
|
+
srcSize,
|
|
1883
1903
|
srcSigned,
|
|
1904
|
+
dstSize ?? srcSize,
|
|
1884
1905
|
column.isSigned
|
|
1885
1906
|
);
|
|
1886
1907
|
} else {
|
|
1887
|
-
|
|
1908
|
+
assert(!column.size || column.size === 64, `Unexpected size ${column.size?.toString() ?? ""} for column ${column.name}`);
|
|
1909
|
+
if (srcSigned !== column.isSigned) {
|
|
1910
|
+
data[column.name] = castBigInt64(
|
|
1911
|
+
cell.data,
|
|
1912
|
+
srcSigned,
|
|
1913
|
+
column.isSigned
|
|
1914
|
+
);
|
|
1915
|
+
} else {
|
|
1916
|
+
data[column.name] = cell.data;
|
|
1917
|
+
}
|
|
1888
1918
|
}
|
|
1919
|
+
} else {
|
|
1920
|
+
throw new Error(`Unsupported column type ${column.type} for column ${column.name}`);
|
|
1889
1921
|
}
|
|
1890
1922
|
fieldIndex += 1;
|
|
1891
1923
|
} else if (column.isRelation) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rhyster/wow-casc-dbc",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Fetch World of Warcraft data files from CASC and parse DBC/DB2 files.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -40,20 +40,21 @@
|
|
|
40
40
|
"@types/async": "^3.2.24",
|
|
41
41
|
"@types/cli-progress": "^3.11.5",
|
|
42
42
|
"@types/jest": "^29.5.12",
|
|
43
|
-
"@types/node": "^20.
|
|
44
|
-
"@typescript-eslint/eslint-plugin": "^7.
|
|
45
|
-
"@typescript-eslint/parser": "^7.
|
|
43
|
+
"@types/node": "^20.13.0",
|
|
44
|
+
"@typescript-eslint/eslint-plugin": "^7.11.0",
|
|
45
|
+
"@typescript-eslint/parser": "^7.11.0",
|
|
46
46
|
"eslint": "^8.57.0",
|
|
47
47
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
48
48
|
"eslint-config-airbnb-typescript": "^18.0.0",
|
|
49
49
|
"jest": "^29.7.0",
|
|
50
|
-
"ts-jest": "^29.1.
|
|
51
|
-
"tsx": "^4.
|
|
50
|
+
"ts-jest": "^29.1.4",
|
|
51
|
+
"tsx": "^4.11.0",
|
|
52
52
|
"typescript": "^5.4.5",
|
|
53
53
|
"unbuild": "^2.0.0"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"async": "^3.2.5",
|
|
57
57
|
"cli-progress": "^3.12.0"
|
|
58
|
-
}
|
|
58
|
+
},
|
|
59
|
+
"packageManager": "pnpm@9.1.4+sha512.9df9cf27c91715646c7d675d1c9c8e41f6fce88246f1318c1aa6a1ed1aeb3c4f032fcdf4ba63cc69c4fe6d634279176b5358727d8f2cc1e65b65f43ce2f8bfb0"
|
|
59
60
|
}
|