@d2runewizard/d2s 2.0.36
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 +59 -0
- package/lib/binary/bitreader.d.ts +22 -0
- package/lib/binary/bitreader.js +100 -0
- package/lib/binary/bitreader.js.map +1 -0
- package/lib/binary/bitwriter.d.ts +21 -0
- package/lib/binary/bitwriter.js +118 -0
- package/lib/binary/bitwriter.js.map +1 -0
- package/lib/binary/constants.d.ts +4 -0
- package/lib/binary/constants.js +9 -0
- package/lib/binary/constants.js.map +1 -0
- package/lib/d2/attribute_enhancer.d.ts +5 -0
- package/lib/d2/attribute_enhancer.js +593 -0
- package/lib/d2/attribute_enhancer.js.map +1 -0
- package/lib/d2/attributes.d.ts +4 -0
- package/lib/d2/attributes.js +99 -0
- package/lib/d2/attributes.js.map +1 -0
- package/lib/d2/constants.d.ts +4 -0
- package/lib/d2/constants.js +16 -0
- package/lib/d2/constants.js.map +1 -0
- package/lib/d2/d2s.d.ts +10 -0
- package/lib/d2/d2s.js +106 -0
- package/lib/d2/d2s.js.map +1 -0
- package/lib/d2/header.d.ts +8 -0
- package/lib/d2/header.js +95 -0
- package/lib/d2/header.js.map +1 -0
- package/lib/d2/items.d.ts +17 -0
- package/lib/d2/items.js +728 -0
- package/lib/d2/items.js.map +1 -0
- package/lib/d2/skills.d.ts +4 -0
- package/lib/d2/skills.js +45 -0
- package/lib/d2/skills.js.map +1 -0
- package/lib/d2/stash.d.ts +3 -0
- package/lib/d2/stash.js +196 -0
- package/lib/d2/stash.js.map +1 -0
- package/lib/d2/types.d.ts +402 -0
- package/lib/d2/types.js +15 -0
- package/lib/d2/types.js.map +1 -0
- package/lib/d2/versions/default_header.d.ts +5 -0
- package/lib/d2/versions/default_header.js +721 -0
- package/lib/d2/versions/default_header.js.map +1 -0
- package/lib/data/parser.d.ts +3 -0
- package/lib/data/parser.js +627 -0
- package/lib/data/parser.js.map +1 -0
- package/lib/data/versions/96_constant_data.d.ts +14427 -0
- package/lib/data/versions/96_constant_data.js +5 -0
- package/lib/data/versions/96_constant_data.js.map +1 -0
- package/lib/data/versions/99_constant_data.d.ts +15572 -0
- package/lib/data/versions/99_constant_data.js +5 -0
- package/lib/data/versions/99_constant_data.js.map +1 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +47 -0
- package/lib/index.js.map +1 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
### d2s
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
The goal of this project is to create an es6 compliant reader/writer of Diablo II save files. Additionally, the library should be able to consume files generated by nokka's Go implementation [d2s](https://github.com/nokka/d2s), therefore the output of reading a save will closely mirror the Go's output.
|
|
6
|
+
|
|
7
|
+
##### Examples
|
|
8
|
+
* [Viewer](https://dschu012.github.io/d2s/) [[Source](docs/index.html)]
|
|
9
|
+
* [Editor](https://d2s.dschu012.dev/) [[Source](https://github.com/dschu012/d2s-editor)]
|
|
10
|
+
|
|
11
|
+
Using [d2s-ui](https://github.com/dschu012/d2s-ui) for a frontend:
|
|
12
|
+
* https://diablo.dannyschumacher.com/#/
|
|
13
|
+
* https://resurgence.dannyschumacher.com/#/
|
|
14
|
+
|
|
15
|
+
##### API/General Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
/**
|
|
19
|
+
* @see constants.bundle.min.js for an already parsed version of 1.13c data
|
|
20
|
+
* @param buffers: object of ALL txt files. example: {
|
|
21
|
+
* "ItemStatCost.txt": "Stat\tIDt\Send...",
|
|
22
|
+
* "string.txt": "WarrivAct1IntroGossip1\t45}Greetings,...",
|
|
23
|
+
* ...
|
|
24
|
+
* }
|
|
25
|
+
* @return constants: constant data required for parsing built from the txt files.
|
|
26
|
+
**/
|
|
27
|
+
function readConstantData(buffers: any): types.IConstantData
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @param buffer: Uint8Array representation of the file
|
|
31
|
+
* @param constants: constant data used for reading the files. @see readConstantData or constants.bundle.min.js
|
|
32
|
+
* @param userConfig: optional configuration. used for if there is a dll edit to allow larger stash sizes. example: {
|
|
33
|
+
* extendedStash: true
|
|
34
|
+
* }
|
|
35
|
+
* @return d2s: the parsed save information
|
|
36
|
+
**/
|
|
37
|
+
function read(buffer: Uint8Array, constants: types.IConstantData, userConfig?: types.IConfig): Promise<types.ID2S>;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param d2s: the parsed save information
|
|
41
|
+
* @param constants: constant data used for reading the files. @see readConstantData or constants.bundle.min.js
|
|
42
|
+
* @param userConfig: optional configuration. used for if there is a dll edit to allow larger stash sizes. example: {
|
|
43
|
+
* extendedStash: true
|
|
44
|
+
* }
|
|
45
|
+
* @return buffer: Uint8Array representation of the file
|
|
46
|
+
**/
|
|
47
|
+
function write(data: types.ID2S, constants: types.IConstantData, userConfig?: types.IConfig): Promise<Uint8Array>;
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
##### Useful Links:
|
|
51
|
+
* https://github.com/d07RiV/d07riv.github.io/blob/master/d2r.html (credits to d07riv for reversing the item code on D2R)
|
|
52
|
+
* https://github.com/dschu012/D2SLib (c# version of this library)
|
|
53
|
+
* https://github.com/nokka/d2s (go d2s parser)
|
|
54
|
+
* https://github.com/krisives/d2s-format
|
|
55
|
+
* http://paul.siramy.free.fr/d2ref/eng/
|
|
56
|
+
* http://user.xmission.com/~trevin/DiabloIIv1.09_File_Format.shtml
|
|
57
|
+
* https://github.com/nickshanks/Alkor
|
|
58
|
+
* https://github.com/HarpyWar/d2s-character-editor
|
|
59
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare class BitReader {
|
|
2
|
+
littleEndian: boolean;
|
|
3
|
+
bits: Uint8Array;
|
|
4
|
+
offset: number;
|
|
5
|
+
constructor(arrBuffer: ArrayBuffer);
|
|
6
|
+
ReadBit(): number;
|
|
7
|
+
ReadBitArray(count: number): Uint8Array;
|
|
8
|
+
ReadBits(bytes: Uint8Array, count: number): Uint8Array;
|
|
9
|
+
ReadBytes(bytes: number): Uint8Array;
|
|
10
|
+
ReadArray(bytes: number): Uint8Array;
|
|
11
|
+
ReadByte(bits?: number): number;
|
|
12
|
+
ReadUInt8(bits?: number): number;
|
|
13
|
+
ReadUInt16(bits?: number): number;
|
|
14
|
+
ReadUInt32(bits?: number): number;
|
|
15
|
+
ReadString(bytes: number): string;
|
|
16
|
+
ReadNullTerminatedString(): string;
|
|
17
|
+
SkipBits(number: number): BitReader;
|
|
18
|
+
SkipBytes(number: number): BitReader;
|
|
19
|
+
SeekBit(offset: number): BitReader;
|
|
20
|
+
SeekByte(offset: number): BitReader;
|
|
21
|
+
Align(): BitReader;
|
|
22
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BitReader = void 0;
|
|
4
|
+
class BitReader {
|
|
5
|
+
constructor(arrBuffer) {
|
|
6
|
+
this.littleEndian = true;
|
|
7
|
+
this.offset = 0;
|
|
8
|
+
const typedArray = new Uint8Array(arrBuffer);
|
|
9
|
+
this.bits = new Uint8Array(typedArray.length * 8);
|
|
10
|
+
typedArray.reduce((acc, c) => {
|
|
11
|
+
const b = c
|
|
12
|
+
.toString(2)
|
|
13
|
+
.padStart(8, "0")
|
|
14
|
+
.split("")
|
|
15
|
+
.reverse()
|
|
16
|
+
.map((e) => parseInt(e, 2));
|
|
17
|
+
b.forEach((bit) => (this.bits[acc++] = bit));
|
|
18
|
+
return acc;
|
|
19
|
+
}, 0);
|
|
20
|
+
}
|
|
21
|
+
ReadBit() {
|
|
22
|
+
return this.bits[this.offset++];
|
|
23
|
+
}
|
|
24
|
+
ReadBitArray(count) {
|
|
25
|
+
const bits = new Uint8Array(count);
|
|
26
|
+
for (let i = 0; i < count; i++) {
|
|
27
|
+
bits[i] = this.bits[this.offset++];
|
|
28
|
+
}
|
|
29
|
+
return bits;
|
|
30
|
+
}
|
|
31
|
+
ReadBits(bytes, count) {
|
|
32
|
+
let byteIndex = 0;
|
|
33
|
+
let bitIndex = 0;
|
|
34
|
+
for (let i = 0; i < count; i++) {
|
|
35
|
+
if (this.bits[this.offset + i]) {
|
|
36
|
+
bytes[byteIndex] |= (1 << bitIndex) & 0xff;
|
|
37
|
+
}
|
|
38
|
+
bitIndex++;
|
|
39
|
+
if (bitIndex == 8) {
|
|
40
|
+
byteIndex++;
|
|
41
|
+
bitIndex = 0;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
this.offset += count;
|
|
45
|
+
return bytes;
|
|
46
|
+
}
|
|
47
|
+
ReadBytes(bytes) {
|
|
48
|
+
return this.ReadBits(new Uint8Array(bytes), bytes * 8);
|
|
49
|
+
}
|
|
50
|
+
ReadArray(bytes) {
|
|
51
|
+
return this.ReadBytes(bytes);
|
|
52
|
+
}
|
|
53
|
+
ReadByte(bits = 8) {
|
|
54
|
+
const dataview = new DataView(this.ReadBits(new Uint8Array(1), bits).buffer);
|
|
55
|
+
return dataview.getUint8(0);
|
|
56
|
+
}
|
|
57
|
+
ReadUInt8(bits = 8) {
|
|
58
|
+
return this.ReadByte(bits);
|
|
59
|
+
}
|
|
60
|
+
ReadUInt16(bits = 8 * 2) {
|
|
61
|
+
const dataview = new DataView(this.ReadBits(new Uint8Array(2), bits).buffer);
|
|
62
|
+
return dataview.getUint16(0, this.littleEndian);
|
|
63
|
+
}
|
|
64
|
+
ReadUInt32(bits = 8 * 4) {
|
|
65
|
+
const dataview = new DataView(this.ReadBits(new Uint8Array(4), bits).buffer);
|
|
66
|
+
return dataview.getUint32(0, this.littleEndian);
|
|
67
|
+
}
|
|
68
|
+
ReadString(bytes) {
|
|
69
|
+
const buffer = this.ReadBytes(bytes).buffer;
|
|
70
|
+
return new TextDecoder().decode(buffer);
|
|
71
|
+
}
|
|
72
|
+
ReadNullTerminatedString() {
|
|
73
|
+
const start = this.offset;
|
|
74
|
+
while (this.ReadByte()) { }
|
|
75
|
+
const end = this.offset - 8;
|
|
76
|
+
const buffer = this.SeekBit(start).ReadBytes((end - start) / 8);
|
|
77
|
+
this.SeekBit(end + 8);
|
|
78
|
+
return new TextDecoder().decode(buffer);
|
|
79
|
+
}
|
|
80
|
+
SkipBits(number) {
|
|
81
|
+
this.offset += number;
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
SkipBytes(number) {
|
|
85
|
+
return this.SkipBits(number * 8);
|
|
86
|
+
}
|
|
87
|
+
SeekBit(offset) {
|
|
88
|
+
this.offset = offset;
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
SeekByte(offset) {
|
|
92
|
+
return this.SeekBit(offset * 8);
|
|
93
|
+
}
|
|
94
|
+
Align() {
|
|
95
|
+
this.offset = (this.offset + 7) & ~7;
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.BitReader = BitReader;
|
|
100
|
+
//# sourceMappingURL=bitreader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitreader.js","sourceRoot":"","sources":["../../src/binary/bitreader.ts"],"names":[],"mappings":";;;AAAA,MAAa,SAAS;IAKpB,YAAY,SAAsB;QAJ3B,iBAAY,GAAG,IAAI,CAAC;QAEpB,WAAM,GAAG,CAAC,CAAC;QAGhB,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,CAAC;QAC7C,IAAI,CAAC,IAAI,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAClD,UAAU,CAAC,MAAM,CAAC,CAAC,GAAW,EAAE,CAAS,EAAE,EAAE;YAC3C,MAAM,CAAC,GAAG,CAAC;iBACR,QAAQ,CAAC,CAAC,CAAC;iBACX,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;iBAChB,KAAK,CAAC,EAAE,CAAC;iBACT,OAAO,EAAE;iBACT,GAAG,CAAC,CAAC,CAAC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|
+
bits: Uint8Array;
|
|
4
|
+
offset: number;
|
|
5
|
+
length: number;
|
|
6
|
+
constructor(capacity?: number);
|
|
7
|
+
WriteBit(value: number): BitWriter;
|
|
8
|
+
WriteBits(bits: Uint8Array, numberOfBits: number): BitWriter;
|
|
9
|
+
WriteBytes(bytes: Uint8Array, numberOfBits?: number): BitWriter;
|
|
10
|
+
WriteArray(bytes: Uint8Array, numberOfBits?: number): BitWriter;
|
|
11
|
+
WriteByte(value: number, numberOfBits?: number): BitWriter;
|
|
12
|
+
WriteUInt8(value: number, numberOfBits?: number): BitWriter;
|
|
13
|
+
WriteUInt16(value: number, numberOfBits?: number): BitWriter;
|
|
14
|
+
WriteUInt32(value: number, numberOfBits?: number): BitWriter;
|
|
15
|
+
WriteString(value: string, numberOfBytes: number): BitWriter;
|
|
16
|
+
SeekBit(offset: number): BitWriter;
|
|
17
|
+
SeekByte(offset: number): BitWriter;
|
|
18
|
+
PeekBytes(count: number): Uint8Array;
|
|
19
|
+
Align(): BitWriter;
|
|
20
|
+
ToArray(): Uint8Array;
|
|
21
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BitWriter = void 0;
|
|
4
|
+
class BitWriter {
|
|
5
|
+
constructor(capacity = 8192) {
|
|
6
|
+
this.littleEndian = true;
|
|
7
|
+
this.offset = 0;
|
|
8
|
+
this.length = 0;
|
|
9
|
+
this.bits = new Uint8Array(capacity);
|
|
10
|
+
}
|
|
11
|
+
WriteBit(value) {
|
|
12
|
+
if (this.offset >= this.bits.length) {
|
|
13
|
+
const resized = new Uint8Array(this.bits.length + 8192);
|
|
14
|
+
resized.set(this.bits, 0);
|
|
15
|
+
this.bits = resized;
|
|
16
|
+
}
|
|
17
|
+
this.bits[this.offset++] = value;
|
|
18
|
+
if (this.offset > this.length)
|
|
19
|
+
this.length++;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
WriteBits(bits, numberOfBits) {
|
|
23
|
+
for (let i = 0; i < numberOfBits; i++) {
|
|
24
|
+
this.WriteBit(bits[i]);
|
|
25
|
+
}
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
WriteBytes(bytes, numberOfBits = bytes.length * 8) {
|
|
29
|
+
const toWrite = new Uint8Array(numberOfBits);
|
|
30
|
+
bytes.reduce((acc, c) => {
|
|
31
|
+
const b = c
|
|
32
|
+
.toString(2)
|
|
33
|
+
.padStart(8, "0")
|
|
34
|
+
.split("")
|
|
35
|
+
.reverse()
|
|
36
|
+
.map((e) => parseInt(e, 2));
|
|
37
|
+
b.forEach((bit) => (toWrite[acc++] = bit));
|
|
38
|
+
return acc;
|
|
39
|
+
}, 0);
|
|
40
|
+
return this.WriteBits(toWrite, numberOfBits);
|
|
41
|
+
}
|
|
42
|
+
WriteArray(bytes, numberOfBits = bytes.length * 8) {
|
|
43
|
+
return this.WriteBytes(bytes, numberOfBits);
|
|
44
|
+
}
|
|
45
|
+
WriteByte(value, numberOfBits = 8) {
|
|
46
|
+
const buffer = new Uint8Array(1);
|
|
47
|
+
new DataView(buffer.buffer).setUint8(0, value);
|
|
48
|
+
return this.WriteBytes(buffer, numberOfBits);
|
|
49
|
+
}
|
|
50
|
+
WriteUInt8(value, numberOfBits = 8) {
|
|
51
|
+
return this.WriteByte(value, numberOfBits);
|
|
52
|
+
}
|
|
53
|
+
WriteUInt16(value, numberOfBits = 8 * 2) {
|
|
54
|
+
const buffer = new Uint8Array(2);
|
|
55
|
+
new DataView(buffer.buffer).setUint16(0, value, this.littleEndian);
|
|
56
|
+
return this.WriteBytes(buffer, numberOfBits);
|
|
57
|
+
}
|
|
58
|
+
WriteUInt32(value, numberOfBits = 8 * 4) {
|
|
59
|
+
const buffer = new Uint8Array(4);
|
|
60
|
+
new DataView(buffer.buffer).setUint32(0, value, this.littleEndian);
|
|
61
|
+
return this.WriteBytes(buffer, numberOfBits);
|
|
62
|
+
}
|
|
63
|
+
WriteString(value, numberOfBytes) {
|
|
64
|
+
const buffer = new TextEncoder().encode(value);
|
|
65
|
+
return this.WriteBytes(buffer, numberOfBytes * 8);
|
|
66
|
+
}
|
|
67
|
+
SeekBit(offset) {
|
|
68
|
+
this.offset = offset;
|
|
69
|
+
if (this.offset > this.length) {
|
|
70
|
+
this.length = this.offset;
|
|
71
|
+
}
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
SeekByte(offset) {
|
|
75
|
+
return this.SeekBit(offset * 8);
|
|
76
|
+
}
|
|
77
|
+
PeekBytes(count) {
|
|
78
|
+
const buffer = new Uint8Array(count);
|
|
79
|
+
let byteIndex = 0;
|
|
80
|
+
let bitIndex = 0;
|
|
81
|
+
for (let i = 0; i < count * 8; ++i) {
|
|
82
|
+
if (this.bits[this.offset + i]) {
|
|
83
|
+
buffer[byteIndex] |= (1 << bitIndex) & 0xff;
|
|
84
|
+
}
|
|
85
|
+
++bitIndex;
|
|
86
|
+
if (bitIndex >= 8) {
|
|
87
|
+
++byteIndex;
|
|
88
|
+
bitIndex = 0;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return buffer;
|
|
92
|
+
}
|
|
93
|
+
Align() {
|
|
94
|
+
this.offset = (this.offset + 7) & ~7;
|
|
95
|
+
if (this.offset > this.length) {
|
|
96
|
+
this.length = this.offset;
|
|
97
|
+
}
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
ToArray() {
|
|
101
|
+
const buffer = new Uint8Array((this.length - 1) / 8 + 1);
|
|
102
|
+
let byteIndex = 0;
|
|
103
|
+
let bitIndex = 0;
|
|
104
|
+
for (let i = 0; i < this.length; ++i) {
|
|
105
|
+
if (this.bits[i]) {
|
|
106
|
+
buffer[byteIndex] |= (1 << bitIndex) & 0xff;
|
|
107
|
+
}
|
|
108
|
+
++bitIndex;
|
|
109
|
+
if (bitIndex >= 8) {
|
|
110
|
+
++byteIndex;
|
|
111
|
+
bitIndex = 0;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return buffer;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.BitWriter = BitWriter;
|
|
118
|
+
//# sourceMappingURL=bitwriter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitwriter.js","sourceRoot":"","sources":["../../src/binary/bitwriter.ts"],"names":[],"mappings":";;;AAAA,MAAa,SAAS;IAMpB,YAAY,QAAQ,GAAG,IAAI;QALpB,iBAAY,GAAG,IAAI,CAAC;QAEpB,WAAM,GAAG,CAAC,CAAC;QACX,WAAM,GAAG,CAAC,CAAC;QAGhB,IAAI,CAAC,IAAI,GAAG,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC;IACvC,CAAC;IAEM,QAAQ,CAAC,KAAa;QAC3B,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YACnC,MAAM,OAAO,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;YACxD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YAC1B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;SACrB;QACD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC;QACjC,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM;YAAE,IAAI,CAAC,MAAM,EAAE,CAAC;QAC7C,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,SAAS,CAAC,IAAgB,EAAE,YAAoB;QACrD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,EAAE,CAAC,EAAE,EAAE;YACrC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SACxB;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,UAAU,CAA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IAAI,QAAQ,CAAC,GAAG,IAAI,CAAC;aAC7C;YACD,EAAE,QAAQ,CAAC;YACX,IAAI,QAAQ,IAAI,CAAC,EAAE;gBACjB,EAAE,SAAS,CAAC;gBACZ,QAAQ,GAAG,CAAC,CAAC;aACd;SACF;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA/HD,8BA+HC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Endianness = void 0;
|
|
4
|
+
var Endianness;
|
|
5
|
+
(function (Endianness) {
|
|
6
|
+
Endianness[Endianness["be"] = 0] = "be";
|
|
7
|
+
Endianness[Endianness["le"] = 1] = "le";
|
|
8
|
+
})(Endianness = exports.Endianness || (exports.Endianness = {}));
|
|
9
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/binary/constants.ts"],"names":[],"mappings":";;;AAAA,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,uCAAQ,CAAA;IACR,uCAAQ,CAAA;AACV,CAAC,EAHW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QAGrB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as types from "./types";
|
|
2
|
+
export declare function enhanceAttributes(char: types.ID2S, constants: types.IConstantData, config?: types.IConfig): Promise<void>;
|
|
3
|
+
export declare function enhancePlayerAttributes(char: types.ID2S, constants: types.IConstantData, config?: types.IConfig): Promise<void>;
|
|
4
|
+
export declare function enhanceItems(items: types.IItem[], constants: types.IConstantData, level?: number, config?: types.IConfig, parent?: types.IItem): Promise<void>;
|
|
5
|
+
export declare function enhanceItem(item: types.IItem, constants: types.IConstantData, level?: number, config?: types.IConfig, parent?: types.IItem): void;
|