@d2runewizard/d2s 2.0.125 → 2.0.126
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/lib/binary/bitreader.d.ts +23 -23
- package/lib/binary/bitreader.js +107 -107
- package/lib/binary/bitwriter.d.ts +21 -21
- package/lib/binary/bitwriter.js +117 -117
- package/lib/binary/constants.d.ts +4 -4
- package/lib/binary/constants.js +8 -8
- package/lib/binary/seekToSequence.d.ts +2 -2
- package/lib/binary/seekToSequence.js +12 -12
- package/lib/d2/attribute_enhancer.d.ts +5 -5
- package/lib/d2/attribute_enhancer.js +595 -595
- package/lib/d2/attributes.d.ts +4 -4
- package/lib/d2/attributes.js +98 -98
- package/lib/d2/constants.d.ts +4 -4
- package/lib/d2/constants.js +15 -15
- package/lib/d2/d2s.d.ts +10 -10
- package/lib/d2/d2s.js +115 -115
- package/lib/d2/header.d.ts +8 -8
- package/lib/d2/header.js +94 -94
- package/lib/d2/items.d.ts +19 -19
- package/lib/d2/items.js +869 -831
- package/lib/d2/items.js.map +1 -1
- package/lib/d2/skills.d.ts +4 -4
- package/lib/d2/skills.js +45 -45
- package/lib/d2/stash.d.ts +3 -3
- package/lib/d2/stash.js +243 -243
- package/lib/d2/types.d.ts +438 -420
- package/lib/d2/types.js +14 -14
- package/lib/d2/versions/default_header.d.ts +5 -5
- package/lib/d2/versions/default_header.js +750 -750
- package/lib/data/parser.d.ts +3 -3
- package/lib/data/parser.js +626 -626
- package/lib/data/versions/105_constant_data.d.ts +16150 -16150
- package/lib/data/versions/105_constant_data.js +24316 -24316
- package/lib/data/versions/96_constant_data.d.ts +14427 -14427
- package/lib/data/versions/96_constant_data.js +4 -4
- package/lib/data/versions/99_constant_data.d.ts +15572 -15572
- package/lib/data/versions/99_constant_data.js +4 -4
- package/lib/index.d.ts +8 -8
- package/lib/index.js +46 -46
- package/package.json +46 -46
package/lib/d2/attributes.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as types from "./types";
|
|
2
|
-
import { BitReader } from "../binary/bitreader";
|
|
3
|
-
export declare function readAttributes(char: types.ID2S, reader: BitReader, constants: types.IConstantData): Promise<void>;
|
|
4
|
-
export declare function writeAttributes(char: types.ID2S, constants: types.IConstantData): Promise<Uint8Array>;
|
|
1
|
+
import * as types from "./types";
|
|
2
|
+
import { BitReader } from "../binary/bitreader";
|
|
3
|
+
export declare function readAttributes(char: types.ID2S, reader: BitReader, constants: types.IConstantData): Promise<void>;
|
|
4
|
+
export declare function writeAttributes(char: types.ID2S, constants: types.IConstantData): Promise<Uint8Array>;
|
package/lib/d2/attributes.js
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeAttributes = exports.readAttributes = void 0;
|
|
4
|
-
const bitwriter_1 = require("../binary/bitwriter");
|
|
5
|
-
//todo use constants.magical_properties and csvBits
|
|
6
|
-
async function readAttributes(char, reader, constants) {
|
|
7
|
-
char.attributes = {};
|
|
8
|
-
const header = reader.ReadString(2); //0x0000 [attributes header = 0x67, 0x66 "gf"]
|
|
9
|
-
if (header != "gf") {
|
|
10
|
-
// header is not present in first save after char is created
|
|
11
|
-
if (char.header.level === 1) {
|
|
12
|
-
const classData = constants.classes.find((c) => c.n === char.header.class).a;
|
|
13
|
-
char.attributes = {
|
|
14
|
-
strength: +classData.str,
|
|
15
|
-
energy: +classData.int,
|
|
16
|
-
dexterity: +classData.dex,
|
|
17
|
-
vitality: +classData.vit,
|
|
18
|
-
unused_stats: 0,
|
|
19
|
-
unused_skill_points: 0,
|
|
20
|
-
current_hp: +classData.vit + +classData.hpadd,
|
|
21
|
-
max_hp: +classData.vit + +classData.hpadd,
|
|
22
|
-
current_mana: +classData.int,
|
|
23
|
-
max_mana: +classData.int,
|
|
24
|
-
current_stamina: +classData.stam,
|
|
25
|
-
max_stamina: +classData.stam,
|
|
26
|
-
level: 1,
|
|
27
|
-
experience: 0,
|
|
28
|
-
gold: 0,
|
|
29
|
-
stashed_gold: 0,
|
|
30
|
-
};
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
throw new Error(`Attribute header 'gf' not found at position ${reader.offset - 2 * 8}`);
|
|
34
|
-
}
|
|
35
|
-
let bitoffset = 0;
|
|
36
|
-
let id = reader.ReadUInt16(9);
|
|
37
|
-
//read till 0x1ff end of attributes is found
|
|
38
|
-
while (id != 0x1ff) {
|
|
39
|
-
bitoffset += 9;
|
|
40
|
-
const field = constants.magical_properties[id];
|
|
41
|
-
if (field === undefined) {
|
|
42
|
-
throw new Error(`Invalid attribute id: ${id}`);
|
|
43
|
-
}
|
|
44
|
-
const size = field.cB;
|
|
45
|
-
char.attributes[Attributes[field.s]] = reader.ReadUInt32(size);
|
|
46
|
-
//current_hp - max_stamina need to be bit shifted
|
|
47
|
-
if (id >= 6 && id <= 11) {
|
|
48
|
-
char.attributes[Attributes[field.s]] >>>= 8;
|
|
49
|
-
}
|
|
50
|
-
bitoffset += size;
|
|
51
|
-
id = reader.ReadUInt16(9);
|
|
52
|
-
}
|
|
53
|
-
reader.Align();
|
|
54
|
-
}
|
|
55
|
-
exports.readAttributes = readAttributes;
|
|
56
|
-
async function writeAttributes(char, constants) {
|
|
57
|
-
const writer = new bitwriter_1.BitWriter();
|
|
58
|
-
writer.WriteString("gf", 2); //0x0000 [attributes header = 0x67, 0x66 "gf"]
|
|
59
|
-
for (let i = 0; i < 16; i++) {
|
|
60
|
-
const property = constants.magical_properties[i];
|
|
61
|
-
if (property === undefined) {
|
|
62
|
-
throw new Error(`Invalid attribute: ${property}`);
|
|
63
|
-
}
|
|
64
|
-
let value = char.attributes[Attributes[property.s]];
|
|
65
|
-
if (!value) {
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
const size = property.cB;
|
|
69
|
-
if (i >= 6 && i <= 11) {
|
|
70
|
-
value <<= 8;
|
|
71
|
-
}
|
|
72
|
-
writer.WriteUInt16(i, 9);
|
|
73
|
-
writer.WriteUInt32(value, size);
|
|
74
|
-
}
|
|
75
|
-
writer.WriteUInt16(0x1ff, 9);
|
|
76
|
-
writer.Align();
|
|
77
|
-
return writer.ToArray();
|
|
78
|
-
}
|
|
79
|
-
exports.writeAttributes = writeAttributes;
|
|
80
|
-
//nokkas names
|
|
81
|
-
const Attributes = {
|
|
82
|
-
strength: "strength",
|
|
83
|
-
energy: "energy",
|
|
84
|
-
dexterity: "dexterity",
|
|
85
|
-
vitality: "vitality",
|
|
86
|
-
statpts: "unused_stats",
|
|
87
|
-
newskills: "unused_skill_points",
|
|
88
|
-
hitpoints: "current_hp",
|
|
89
|
-
maxhp: "max_hp",
|
|
90
|
-
mana: "current_mana",
|
|
91
|
-
maxmana: "max_mana",
|
|
92
|
-
stamina: "current_stamina",
|
|
93
|
-
maxstamina: "max_stamina",
|
|
94
|
-
level: "level",
|
|
95
|
-
experience: "experience",
|
|
96
|
-
gold: "gold",
|
|
97
|
-
goldbank: "stashed_gold",
|
|
98
|
-
};
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeAttributes = exports.readAttributes = void 0;
|
|
4
|
+
const bitwriter_1 = require("../binary/bitwriter");
|
|
5
|
+
//todo use constants.magical_properties and csvBits
|
|
6
|
+
async function readAttributes(char, reader, constants) {
|
|
7
|
+
char.attributes = {};
|
|
8
|
+
const header = reader.ReadString(2); //0x0000 [attributes header = 0x67, 0x66 "gf"]
|
|
9
|
+
if (header != "gf") {
|
|
10
|
+
// header is not present in first save after char is created
|
|
11
|
+
if (char.header.level === 1) {
|
|
12
|
+
const classData = constants.classes.find((c) => c.n === char.header.class).a;
|
|
13
|
+
char.attributes = {
|
|
14
|
+
strength: +classData.str,
|
|
15
|
+
energy: +classData.int,
|
|
16
|
+
dexterity: +classData.dex,
|
|
17
|
+
vitality: +classData.vit,
|
|
18
|
+
unused_stats: 0,
|
|
19
|
+
unused_skill_points: 0,
|
|
20
|
+
current_hp: +classData.vit + +classData.hpadd,
|
|
21
|
+
max_hp: +classData.vit + +classData.hpadd,
|
|
22
|
+
current_mana: +classData.int,
|
|
23
|
+
max_mana: +classData.int,
|
|
24
|
+
current_stamina: +classData.stam,
|
|
25
|
+
max_stamina: +classData.stam,
|
|
26
|
+
level: 1,
|
|
27
|
+
experience: 0,
|
|
28
|
+
gold: 0,
|
|
29
|
+
stashed_gold: 0,
|
|
30
|
+
};
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
throw new Error(`Attribute header 'gf' not found at position ${reader.offset - 2 * 8}`);
|
|
34
|
+
}
|
|
35
|
+
let bitoffset = 0;
|
|
36
|
+
let id = reader.ReadUInt16(9);
|
|
37
|
+
//read till 0x1ff end of attributes is found
|
|
38
|
+
while (id != 0x1ff) {
|
|
39
|
+
bitoffset += 9;
|
|
40
|
+
const field = constants.magical_properties[id];
|
|
41
|
+
if (field === undefined) {
|
|
42
|
+
throw new Error(`Invalid attribute id: ${id}`);
|
|
43
|
+
}
|
|
44
|
+
const size = field.cB;
|
|
45
|
+
char.attributes[Attributes[field.s]] = reader.ReadUInt32(size);
|
|
46
|
+
//current_hp - max_stamina need to be bit shifted
|
|
47
|
+
if (id >= 6 && id <= 11) {
|
|
48
|
+
char.attributes[Attributes[field.s]] >>>= 8;
|
|
49
|
+
}
|
|
50
|
+
bitoffset += size;
|
|
51
|
+
id = reader.ReadUInt16(9);
|
|
52
|
+
}
|
|
53
|
+
reader.Align();
|
|
54
|
+
}
|
|
55
|
+
exports.readAttributes = readAttributes;
|
|
56
|
+
async function writeAttributes(char, constants) {
|
|
57
|
+
const writer = new bitwriter_1.BitWriter();
|
|
58
|
+
writer.WriteString("gf", 2); //0x0000 [attributes header = 0x67, 0x66 "gf"]
|
|
59
|
+
for (let i = 0; i < 16; i++) {
|
|
60
|
+
const property = constants.magical_properties[i];
|
|
61
|
+
if (property === undefined) {
|
|
62
|
+
throw new Error(`Invalid attribute: ${property}`);
|
|
63
|
+
}
|
|
64
|
+
let value = char.attributes[Attributes[property.s]];
|
|
65
|
+
if (!value) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
const size = property.cB;
|
|
69
|
+
if (i >= 6 && i <= 11) {
|
|
70
|
+
value <<= 8;
|
|
71
|
+
}
|
|
72
|
+
writer.WriteUInt16(i, 9);
|
|
73
|
+
writer.WriteUInt32(value, size);
|
|
74
|
+
}
|
|
75
|
+
writer.WriteUInt16(0x1ff, 9);
|
|
76
|
+
writer.Align();
|
|
77
|
+
return writer.ToArray();
|
|
78
|
+
}
|
|
79
|
+
exports.writeAttributes = writeAttributes;
|
|
80
|
+
//nokkas names
|
|
81
|
+
const Attributes = {
|
|
82
|
+
strength: "strength",
|
|
83
|
+
energy: "energy",
|
|
84
|
+
dexterity: "dexterity",
|
|
85
|
+
vitality: "vitality",
|
|
86
|
+
statpts: "unused_stats",
|
|
87
|
+
newskills: "unused_skill_points",
|
|
88
|
+
hitpoints: "current_hp",
|
|
89
|
+
maxhp: "max_hp",
|
|
90
|
+
mana: "current_mana",
|
|
91
|
+
maxmana: "max_mana",
|
|
92
|
+
stamina: "current_stamina",
|
|
93
|
+
maxstamina: "max_stamina",
|
|
94
|
+
level: "level",
|
|
95
|
+
experience: "experience",
|
|
96
|
+
gold: "gold",
|
|
97
|
+
goldbank: "stashed_gold",
|
|
98
|
+
};
|
|
99
99
|
//# sourceMappingURL=attributes.js.map
|
package/lib/d2/constants.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as types from "./types";
|
|
2
|
-
declare function getConstantData(version: number): types.IConstantData;
|
|
3
|
-
declare function setConstantData(version: number, data: types.IConstantData): void;
|
|
4
|
-
export { getConstantData, setConstantData };
|
|
1
|
+
import * as types from "./types";
|
|
2
|
+
declare function getConstantData(version: number): types.IConstantData;
|
|
3
|
+
declare function setConstantData(version: number, data: types.IConstantData): void;
|
|
4
|
+
export { getConstantData, setConstantData };
|
package/lib/d2/constants.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setConstantData = exports.getConstantData = void 0;
|
|
4
|
-
const versionedConstants = new Map();
|
|
5
|
-
function getConstantData(version) {
|
|
6
|
-
if (!(version in versionedConstants)) {
|
|
7
|
-
throw new Error(`No constant data found for this version ${version}`);
|
|
8
|
-
}
|
|
9
|
-
return versionedConstants[version];
|
|
10
|
-
}
|
|
11
|
-
exports.getConstantData = getConstantData;
|
|
12
|
-
function setConstantData(version, data) {
|
|
13
|
-
versionedConstants[version] = data;
|
|
14
|
-
}
|
|
15
|
-
exports.setConstantData = setConstantData;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setConstantData = exports.getConstantData = void 0;
|
|
4
|
+
const versionedConstants = new Map();
|
|
5
|
+
function getConstantData(version) {
|
|
6
|
+
if (!(version in versionedConstants)) {
|
|
7
|
+
throw new Error(`No constant data found for this version ${version}`);
|
|
8
|
+
}
|
|
9
|
+
return versionedConstants[version];
|
|
10
|
+
}
|
|
11
|
+
exports.getConstantData = getConstantData;
|
|
12
|
+
function setConstantData(version, data) {
|
|
13
|
+
versionedConstants[version] = data;
|
|
14
|
+
}
|
|
15
|
+
exports.setConstantData = setConstantData;
|
|
16
16
|
//# sourceMappingURL=constants.js.map
|
package/lib/d2/d2s.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as types from "./types";
|
|
2
|
-
import { BitReader } from "../binary/bitreader";
|
|
3
|
-
import { BitWriter } from "../binary/bitwriter";
|
|
4
|
-
declare function reader(buffer: Uint8Array): BitReader;
|
|
5
|
-
declare function read(buffer: Uint8Array, constants?: types.IConstantData, userConfig?: types.IConfig): Promise<types.ID2S>;
|
|
6
|
-
declare function readItem(buffer: Uint8Array, version: number, constants?: types.IConstantData, userConfig?: types.IConfig): Promise<types.IItem>;
|
|
7
|
-
declare function writer(buffer: Uint8Array): BitWriter;
|
|
8
|
-
declare function write(data: types.ID2S, constants?: types.IConstantData, userConfig?: types.IConfig): Promise<Uint8Array>;
|
|
9
|
-
declare function writeItem(item: types.IItem, version: number, constants?: types.IConstantData, userConfig?: types.IConfig): Promise<Uint8Array>;
|
|
10
|
-
export { reader, writer, read, write, readItem, writeItem };
|
|
1
|
+
import * as types from "./types";
|
|
2
|
+
import { BitReader } from "../binary/bitreader";
|
|
3
|
+
import { BitWriter } from "../binary/bitwriter";
|
|
4
|
+
declare function reader(buffer: Uint8Array): BitReader;
|
|
5
|
+
declare function read(buffer: Uint8Array, constants?: types.IConstantData, userConfig?: types.IConfig): Promise<types.ID2S>;
|
|
6
|
+
declare function readItem(buffer: Uint8Array, version: number, constants?: types.IConstantData, userConfig?: types.IConfig): Promise<types.IItem>;
|
|
7
|
+
declare function writer(buffer: Uint8Array): BitWriter;
|
|
8
|
+
declare function write(data: types.ID2S, constants?: types.IConstantData, userConfig?: types.IConfig): Promise<Uint8Array>;
|
|
9
|
+
declare function writeItem(item: types.IItem, version: number, constants?: types.IConstantData, userConfig?: types.IConfig): Promise<Uint8Array>;
|
|
10
|
+
export { reader, writer, read, write, readItem, writeItem };
|
package/lib/d2/d2s.js
CHANGED
|
@@ -1,116 +1,116 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.writeItem = exports.readItem = exports.write = exports.read = exports.writer = exports.reader = void 0;
|
|
23
|
-
const header_1 = require("./header");
|
|
24
|
-
const attributes_1 = require("./attributes");
|
|
25
|
-
const bitreader_1 = require("../binary/bitreader");
|
|
26
|
-
const bitwriter_1 = require("../binary/bitwriter");
|
|
27
|
-
const skills_1 = require("./skills");
|
|
28
|
-
const items = __importStar(require("./items"));
|
|
29
|
-
const constants_1 = require("./constants");
|
|
30
|
-
const attribute_enhancer_1 = require("./attribute_enhancer");
|
|
31
|
-
const defaultConfig = {
|
|
32
|
-
extendedStash: false,
|
|
33
|
-
sortProperties: true,
|
|
34
|
-
disableItemEnhancements: false,
|
|
35
|
-
};
|
|
36
|
-
function reader(buffer) {
|
|
37
|
-
return new bitreader_1.BitReader(buffer);
|
|
38
|
-
}
|
|
39
|
-
exports.reader = reader;
|
|
40
|
-
async function read(buffer, constants, userConfig) {
|
|
41
|
-
const char = {};
|
|
42
|
-
const reader = new bitreader_1.BitReader(buffer);
|
|
43
|
-
const config = Object.assign(defaultConfig, userConfig);
|
|
44
|
-
await header_1.readHeader(char, reader);
|
|
45
|
-
//could load constants based on version here
|
|
46
|
-
if (!constants) {
|
|
47
|
-
constants = constants_1.getConstantData(char.header.version);
|
|
48
|
-
}
|
|
49
|
-
await header_1.readHeaderData(char, reader, constants);
|
|
50
|
-
await attributes_1.readAttributes(char, reader, constants);
|
|
51
|
-
await skills_1.readSkills(char, reader, constants);
|
|
52
|
-
await items.readCharItems(char, reader, constants, config);
|
|
53
|
-
/*if (char.header.version === 0x69) {
|
|
54
|
-
reader.SeekSequence("01010010 10110010".replace(/ /g, ""));
|
|
55
|
-
}*/
|
|
56
|
-
await items.readCorpseItems(char, reader, constants, config);
|
|
57
|
-
if (char.header.status.expansion || char.header.version === 0x69) {
|
|
58
|
-
await items.readMercItems(char, reader, constants, config);
|
|
59
|
-
await items.readGolemItems(char, reader, constants, config);
|
|
60
|
-
}
|
|
61
|
-
if (char.header.version === 0x69) {
|
|
62
|
-
await items.readDemon(char, reader, constants, config);
|
|
63
|
-
}
|
|
64
|
-
await attribute_enhancer_1.enhanceAttributes(char, constants, config);
|
|
65
|
-
return char;
|
|
66
|
-
}
|
|
67
|
-
exports.read = read;
|
|
68
|
-
async function readItem(buffer, version, constants, userConfig) {
|
|
69
|
-
const reader = new bitreader_1.BitReader(buffer);
|
|
70
|
-
const config = Object.assign(defaultConfig, userConfig);
|
|
71
|
-
if (!constants) {
|
|
72
|
-
constants = constants_1.getConstantData(version);
|
|
73
|
-
}
|
|
74
|
-
const item = await items.readItem(reader, version, constants, config);
|
|
75
|
-
await attribute_enhancer_1.enhanceItems([item], constants);
|
|
76
|
-
return item;
|
|
77
|
-
}
|
|
78
|
-
exports.readItem = readItem;
|
|
79
|
-
function writer(buffer) {
|
|
80
|
-
return new bitwriter_1.BitWriter();
|
|
81
|
-
}
|
|
82
|
-
exports.writer = writer;
|
|
83
|
-
async function write(data, constants, userConfig) {
|
|
84
|
-
const config = Object.assign(defaultConfig, userConfig);
|
|
85
|
-
const writer = new bitwriter_1.BitWriter();
|
|
86
|
-
writer.WriteArray(await header_1.writeHeader(data));
|
|
87
|
-
if (!constants) {
|
|
88
|
-
constants = constants_1.getConstantData(data.header.version);
|
|
89
|
-
}
|
|
90
|
-
writer.WriteArray(await header_1.writeHeaderData(data, constants));
|
|
91
|
-
writer.WriteArray(await attributes_1.writeAttributes(data, constants));
|
|
92
|
-
writer.WriteArray(await skills_1.writeSkills(data, constants));
|
|
93
|
-
writer.WriteArray(await items.writeCharItems(data, constants, config));
|
|
94
|
-
writer.WriteArray(await items.writeCorpseItem(data, constants, config));
|
|
95
|
-
if (data.header.status.expansion || data.header.version === 0x69) {
|
|
96
|
-
writer.WriteArray(await items.writeMercItems(data, constants, config));
|
|
97
|
-
writer.WriteArray(await items.writeGolemItems(data, constants, config));
|
|
98
|
-
}
|
|
99
|
-
if (data.header.version === 0x69) {
|
|
100
|
-
writer.WriteArray(await items.writeDemon(data, constants, config));
|
|
101
|
-
}
|
|
102
|
-
await header_1.fixHeader(writer);
|
|
103
|
-
return writer.ToArray();
|
|
104
|
-
}
|
|
105
|
-
exports.write = write;
|
|
106
|
-
async function writeItem(item, version, constants, userConfig) {
|
|
107
|
-
const config = Object.assign(defaultConfig, userConfig);
|
|
108
|
-
const writer = new bitwriter_1.BitWriter();
|
|
109
|
-
if (!constants) {
|
|
110
|
-
constants = constants_1.getConstantData(version);
|
|
111
|
-
}
|
|
112
|
-
writer.WriteArray(await items.writeItem(item, version, constants, config));
|
|
113
|
-
return writer.ToArray();
|
|
114
|
-
}
|
|
115
|
-
exports.writeItem = writeItem;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.writeItem = exports.readItem = exports.write = exports.read = exports.writer = exports.reader = void 0;
|
|
23
|
+
const header_1 = require("./header");
|
|
24
|
+
const attributes_1 = require("./attributes");
|
|
25
|
+
const bitreader_1 = require("../binary/bitreader");
|
|
26
|
+
const bitwriter_1 = require("../binary/bitwriter");
|
|
27
|
+
const skills_1 = require("./skills");
|
|
28
|
+
const items = __importStar(require("./items"));
|
|
29
|
+
const constants_1 = require("./constants");
|
|
30
|
+
const attribute_enhancer_1 = require("./attribute_enhancer");
|
|
31
|
+
const defaultConfig = {
|
|
32
|
+
extendedStash: false,
|
|
33
|
+
sortProperties: true,
|
|
34
|
+
disableItemEnhancements: false,
|
|
35
|
+
};
|
|
36
|
+
function reader(buffer) {
|
|
37
|
+
return new bitreader_1.BitReader(buffer);
|
|
38
|
+
}
|
|
39
|
+
exports.reader = reader;
|
|
40
|
+
async function read(buffer, constants, userConfig) {
|
|
41
|
+
const char = {};
|
|
42
|
+
const reader = new bitreader_1.BitReader(buffer);
|
|
43
|
+
const config = Object.assign(defaultConfig, userConfig);
|
|
44
|
+
await header_1.readHeader(char, reader);
|
|
45
|
+
//could load constants based on version here
|
|
46
|
+
if (!constants) {
|
|
47
|
+
constants = constants_1.getConstantData(char.header.version);
|
|
48
|
+
}
|
|
49
|
+
await header_1.readHeaderData(char, reader, constants);
|
|
50
|
+
await attributes_1.readAttributes(char, reader, constants);
|
|
51
|
+
await skills_1.readSkills(char, reader, constants);
|
|
52
|
+
await items.readCharItems(char, reader, constants, config);
|
|
53
|
+
/*if (char.header.version === 0x69) {
|
|
54
|
+
reader.SeekSequence("01010010 10110010".replace(/ /g, ""));
|
|
55
|
+
}*/
|
|
56
|
+
await items.readCorpseItems(char, reader, constants, config);
|
|
57
|
+
if (char.header.status.expansion || char.header.version === 0x69) {
|
|
58
|
+
await items.readMercItems(char, reader, constants, config);
|
|
59
|
+
await items.readGolemItems(char, reader, constants, config);
|
|
60
|
+
}
|
|
61
|
+
if (char.header.version === 0x69) {
|
|
62
|
+
await items.readDemon(char, reader, constants, config);
|
|
63
|
+
}
|
|
64
|
+
await attribute_enhancer_1.enhanceAttributes(char, constants, config);
|
|
65
|
+
return char;
|
|
66
|
+
}
|
|
67
|
+
exports.read = read;
|
|
68
|
+
async function readItem(buffer, version, constants, userConfig) {
|
|
69
|
+
const reader = new bitreader_1.BitReader(buffer);
|
|
70
|
+
const config = Object.assign(defaultConfig, userConfig);
|
|
71
|
+
if (!constants) {
|
|
72
|
+
constants = constants_1.getConstantData(version);
|
|
73
|
+
}
|
|
74
|
+
const item = await items.readItem(reader, version, constants, config);
|
|
75
|
+
await attribute_enhancer_1.enhanceItems([item], constants);
|
|
76
|
+
return item;
|
|
77
|
+
}
|
|
78
|
+
exports.readItem = readItem;
|
|
79
|
+
function writer(buffer) {
|
|
80
|
+
return new bitwriter_1.BitWriter();
|
|
81
|
+
}
|
|
82
|
+
exports.writer = writer;
|
|
83
|
+
async function write(data, constants, userConfig) {
|
|
84
|
+
const config = Object.assign(defaultConfig, userConfig);
|
|
85
|
+
const writer = new bitwriter_1.BitWriter();
|
|
86
|
+
writer.WriteArray(await header_1.writeHeader(data));
|
|
87
|
+
if (!constants) {
|
|
88
|
+
constants = constants_1.getConstantData(data.header.version);
|
|
89
|
+
}
|
|
90
|
+
writer.WriteArray(await header_1.writeHeaderData(data, constants));
|
|
91
|
+
writer.WriteArray(await attributes_1.writeAttributes(data, constants));
|
|
92
|
+
writer.WriteArray(await skills_1.writeSkills(data, constants));
|
|
93
|
+
writer.WriteArray(await items.writeCharItems(data, constants, config));
|
|
94
|
+
writer.WriteArray(await items.writeCorpseItem(data, constants, config));
|
|
95
|
+
if (data.header.status.expansion || data.header.version === 0x69) {
|
|
96
|
+
writer.WriteArray(await items.writeMercItems(data, constants, config));
|
|
97
|
+
writer.WriteArray(await items.writeGolemItems(data, constants, config));
|
|
98
|
+
}
|
|
99
|
+
if (data.header.version === 0x69) {
|
|
100
|
+
writer.WriteArray(await items.writeDemon(data, constants, config));
|
|
101
|
+
}
|
|
102
|
+
await header_1.fixHeader(writer);
|
|
103
|
+
return writer.ToArray();
|
|
104
|
+
}
|
|
105
|
+
exports.write = write;
|
|
106
|
+
async function writeItem(item, version, constants, userConfig) {
|
|
107
|
+
const config = Object.assign(defaultConfig, userConfig);
|
|
108
|
+
const writer = new bitwriter_1.BitWriter();
|
|
109
|
+
if (!constants) {
|
|
110
|
+
constants = constants_1.getConstantData(version);
|
|
111
|
+
}
|
|
112
|
+
writer.WriteArray(await items.writeItem(item, version, constants, config));
|
|
113
|
+
return writer.ToArray();
|
|
114
|
+
}
|
|
115
|
+
exports.writeItem = writeItem;
|
|
116
116
|
//# sourceMappingURL=d2s.js.map
|
package/lib/d2/header.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as types from "./types";
|
|
2
|
-
import { BitReader } from "../binary/bitreader";
|
|
3
|
-
import { BitWriter } from "../binary/bitwriter";
|
|
4
|
-
export declare function readHeader(char: types.ID2S, reader: BitReader): Promise<void>;
|
|
5
|
-
export declare function readHeaderData(char: types.ID2S, reader: BitReader, constants: types.IConstantData): Promise<void>;
|
|
6
|
-
export declare function writeHeader(char: types.ID2S): Promise<Uint8Array>;
|
|
7
|
-
export declare function writeHeaderData(char: types.ID2S, constants: types.IConstantData): Promise<Uint8Array>;
|
|
8
|
-
export declare function fixHeader(writer: BitWriter): Promise<void>;
|
|
1
|
+
import * as types from "./types";
|
|
2
|
+
import { BitReader } from "../binary/bitreader";
|
|
3
|
+
import { BitWriter } from "../binary/bitwriter";
|
|
4
|
+
export declare function readHeader(char: types.ID2S, reader: BitReader): Promise<void>;
|
|
5
|
+
export declare function readHeaderData(char: types.ID2S, reader: BitReader, constants: types.IConstantData): Promise<void>;
|
|
6
|
+
export declare function writeHeader(char: types.ID2S): Promise<Uint8Array>;
|
|
7
|
+
export declare function writeHeaderData(char: types.ID2S, constants: types.IConstantData): Promise<Uint8Array>;
|
|
8
|
+
export declare function fixHeader(writer: BitWriter): Promise<void>;
|