@d2runewizard/d2s 2.0.130 → 2.0.131

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.
Files changed (42) hide show
  1. package/lib/binary/bitreader.d.ts +23 -23
  2. package/lib/binary/bitreader.js +107 -107
  3. package/lib/binary/bitwriter.d.ts +21 -21
  4. package/lib/binary/bitwriter.js +117 -117
  5. package/lib/binary/constants.d.ts +4 -4
  6. package/lib/binary/constants.js +8 -8
  7. package/lib/binary/seekToSequence.d.ts +2 -2
  8. package/lib/binary/seekToSequence.js +12 -12
  9. package/lib/d2/attribute_enhancer.d.ts +5 -5
  10. package/lib/d2/attribute_enhancer.js +596 -595
  11. package/lib/d2/attribute_enhancer.js.map +1 -1
  12. package/lib/d2/attributes.d.ts +4 -4
  13. package/lib/d2/attributes.js +98 -98
  14. package/lib/d2/constants.d.ts +4 -4
  15. package/lib/d2/constants.js +15 -15
  16. package/lib/d2/d2s.d.ts +10 -10
  17. package/lib/d2/d2s.js +115 -115
  18. package/lib/d2/header.d.ts +8 -8
  19. package/lib/d2/header.js +94 -94
  20. package/lib/d2/items.d.ts +19 -19
  21. package/lib/d2/items.js +873 -873
  22. package/lib/d2/items.js.map +1 -1
  23. package/lib/d2/skills.d.ts +4 -4
  24. package/lib/d2/skills.js +45 -45
  25. package/lib/d2/stash.d.ts +3 -3
  26. package/lib/d2/stash.js +243 -243
  27. package/lib/d2/types.d.ts +439 -438
  28. package/lib/d2/types.js +14 -14
  29. package/lib/d2/types.js.map +1 -1
  30. package/lib/d2/versions/default_header.d.ts +5 -5
  31. package/lib/d2/versions/default_header.js +750 -750
  32. package/lib/data/parser.d.ts +3 -3
  33. package/lib/data/parser.js +626 -626
  34. package/lib/data/versions/105_constant_data.d.ts +16150 -16150
  35. package/lib/data/versions/105_constant_data.js +24316 -24316
  36. package/lib/data/versions/96_constant_data.d.ts +14427 -14427
  37. package/lib/data/versions/96_constant_data.js +4 -4
  38. package/lib/data/versions/99_constant_data.d.ts +15572 -15572
  39. package/lib/data/versions/99_constant_data.js +4 -4
  40. package/lib/index.d.ts +8 -8
  41. package/lib/index.js +46 -46
  42. package/package.json +50 -46
@@ -1,751 +1,751 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeHeader = exports.readHeader = void 0;
4
- const bitreader_1 = require("../../binary/bitreader");
5
- const bitwriter_1 = require("../../binary/bitwriter");
6
- const difficulties = ["normal", "nm", "hell"];
7
- function readHeader(char, reader, constants) {
8
- var _a, _b, _c, _d;
9
- char.header.filesize = reader.ReadUInt32(); //0x0008
10
- char.header.checksum = reader.ReadUInt32().toString(16).padStart(8, "0"); //0x000c
11
- reader.SkipBytes(4); //0x0010
12
- if (char.header.version > 0x61) {
13
- if (char.header.version === 0x69) {
14
- reader.SeekByte(299);
15
- }
16
- else {
17
- reader.SeekByte(267);
18
- }
19
- }
20
- char.header.name = reader.ReadString(16).replace(/\0/g, ""); //0x0014
21
- if (char.header.version > 0x61) {
22
- if (char.header.version === 0x69) {
23
- reader.SeekByte(20);
24
- }
25
- else {
26
- reader.SeekByte(36);
27
- }
28
- }
29
- char.header.status = _readStatus(reader.ReadUInt8()); //0x0024
30
- char.header.progression = reader.ReadUInt8(); //0x0025
31
- char.header.active_arms = reader.ReadUInt16(); //0x0026 [unk = 0x0, 0x0]
32
- char.header.class = constants.classes[reader.ReadUInt8()].n; //0x0028
33
- reader.SkipBytes(2); //0x0029 [unk = 0x10, 0x1E]
34
- char.header.level = reader.ReadUInt8(); //0x002b
35
- char.header.created = reader.ReadUInt32(); //0x002c
36
- char.header.last_played = reader.ReadUInt32(); //0x0030
37
- reader.SkipBytes(4); //0x0034 [unk = 0xff, 0xff, 0xff, 0xff]
38
- char.header.assigned_skills = _readAssignedSkills(reader.ReadArray(64), constants); //0x0038
39
- char.header.left_skill = (_a = constants.skills[reader.ReadUInt32()]) === null || _a === void 0 ? void 0 : _a.s; //0x0078
40
- char.header.right_skill = (_b = constants.skills[reader.ReadUInt32()]) === null || _b === void 0 ? void 0 : _b.s; //0x007c
41
- char.header.left_swap_skill = (_c = constants.skills[reader.ReadUInt32()]) === null || _c === void 0 ? void 0 : _c.s; //0x0080
42
- char.header.right_swap_skill = (_d = constants.skills[reader.ReadUInt32()]) === null || _d === void 0 ? void 0 : _d.s; //0x0084
43
- char.header.menu_appearance = _readCharMenuAppearance(reader.ReadArray(32), constants); //0x0088 [char menu appearance]
44
- char.header.difficulty = _readDifficulty(reader.ReadArray(3)); //0x00a8
45
- char.header.map_id = reader.ReadUInt32(); //0x00ab
46
- reader.SkipBytes(2); //0x00af [unk = 0x0, 0x0]
47
- char.header.dead_merc = reader.ReadUInt16(); //0x00b1
48
- char.header.merc_id = reader.ReadUInt32().toString(16); //0x00b3
49
- char.header.merc_name_id = reader.ReadUInt16(); //0x00b7
50
- char.header.merc_type = reader.ReadUInt16(); //0x00b9
51
- char.header.merc_experience = reader.ReadUInt32(); //0x00bb 175
52
- if (char.header.version === 0x69) {
53
- reader.SkipBytes(228); //0x00bf [unk]
54
- }
55
- else {
56
- reader.SkipBytes(144); //0x00bf [unk]
57
- }
58
- reader.SkipBytes(4); //0x014f [quests header identifier = 0x57, 0x6f, 0x6f, 0x21 "Woo!"]
59
- reader.SkipBytes(4); //0x0153 [version = 0x6, 0x0, 0x0, 0x0]
60
- reader.SkipBytes(2); //0x0153 [quests header length = 0x2a, 0x1]
61
- char.header.quests_normal = _readQuests(reader.ReadArray(96)); //0x0159
62
- char.header.quests_nm = _readQuests(reader.ReadArray(96)); //0x01b9
63
- char.header.quests_hell = _readQuests(reader.ReadArray(96)); //0x0219
64
- reader.SkipBytes(2); //0x0279 [waypoint header identifier = 0x57, 0x53 "WS"]
65
- reader.SkipBytes(4); //0x027b [waypoint header version = 0x1, 0x0, 0x0, 0x0]
66
- reader.SkipBytes(2); //0x027f [waypoint header length = 0x50, 0x0]
67
- char.header.waypoints = _readWaypointData(reader.ReadArray(0x48)); //0x0281
68
- reader.SkipBytes(2); //0x02c9 [npc header identifier = 0x01, 0x77 ".w"]
69
- reader.SkipBytes(2); //0x02ca [npc header length = 0x34]
70
- char.header.npcs = _readNPCData(reader.ReadArray(0x30)); //0x02cc
71
- }
72
- exports.readHeader = readHeader;
73
- function writeHeader(char, writer, constants) {
74
- writer
75
- .WriteUInt32(0x0) //0x0008 (filesize. needs to be writen after all data)
76
- .WriteUInt32(0x0); //0x000c (checksum. needs to be calculated after all data writer)
77
- if (char.header.version > 0x61) {
78
- if (char.header.version === 0x69) {
79
- writer.WriteArray(new Uint8Array([0x00, 0x00, 0x00, 0x00]));
80
- }
81
- else {
82
- writer.WriteArray(new Uint8Array(Array(20).fill(0))); // 0x0010
83
- }
84
- }
85
- else {
86
- writer
87
- .WriteArray(new Uint8Array([0x00, 0x00, 0x00, 0x00])) //0x0010
88
- .WriteString(char.header.name, 16); //0x0014
89
- }
90
- writer
91
- .WriteArray(_writeStatus(char.header.status)) //0x0024
92
- .WriteUInt8(char.header.progression) //0x0025
93
- .WriteUInt16(char.header.active_arms) //0x0026
94
- .WriteUInt8(_classId(char.header.class, constants)) //0x0028
95
- .WriteArray(new Uint8Array([0x10, 0x1e])) //0x0029
96
- .WriteUInt8(char.header.level) //0x002b
97
- .WriteArray(new Uint8Array([0x00, 0x00, 0x00, 0x00])) //0x002c
98
- .WriteUInt32(char.header.last_played) //0x0030
99
- .WriteArray(new Uint8Array([0xff, 0xff, 0xff, 0xff])) //0x0034
100
- .WriteArray(_writeAssignedSkills(char.header.assigned_skills, constants)) //0x0038
101
- .WriteUInt32(_skillId(char.header.left_skill, constants)) //0x0078
102
- .WriteUInt32(_skillId(char.header.right_skill, constants)) //0x007c
103
- .WriteUInt32(_skillId(char.header.left_swap_skill, constants)) //0x0080
104
- .WriteUInt32(_skillId(char.header.right_swap_skill, constants)) //0x0084
105
- .WriteArray(_writeCharMenuAppearance(char.header.menu_appearance, constants)) //0x0088 [char menu appearance]
106
- .WriteArray(_writeDifficulty(char.header.difficulty)) //0x00a8
107
- .WriteUInt32(char.header.map_id) //0x00ab
108
- .WriteArray(new Uint8Array([0x00, 0x00])) //0x00af [unk = 0x0, 0x0]
109
- .WriteUInt16(char.header.dead_merc) //0x00b1
110
- .WriteUInt32(parseInt(char.header.merc_id, 16)) //0x00b3
111
- .WriteUInt16(char.header.merc_name_id) //0x00b7
112
- .WriteUInt16(char.header.merc_type) //0x00b9
113
- .WriteUInt32(char.header.merc_experience); //0x00bb
114
- if (char.header.version > 0x61) {
115
- if (char.header.version === 0x69) {
116
- writer
117
- .WriteArray(new Uint8Array(73)) //175
118
- .WriteArray(new Uint8Array([0x03])) //248
119
- .WriteArray(new Uint8Array(50)) //248
120
- .WriteString(char.header.name, 16) //299
121
- .WriteArray(new Uint8Array(88)); //0x011b [unk]
122
- }
123
- else {
124
- writer
125
- .WriteArray(new Uint8Array(76)) //0x00bf [unk]
126
- .WriteString(char.header.name, 16) //0x010b
127
- .WriteArray(new Uint8Array(52)); //0x011b [unk]
128
- }
129
- }
130
- else {
131
- writer
132
- .WriteArray(new Uint8Array(140)) //0x00bf [unk]
133
- .WriteUInt32(0x1); //0x014b [unk = 0x1, 0x0, 0x0, 0x0]
134
- }
135
- writer
136
- .WriteString("Woo!", 4) //0x014f [quests = 0x57, 0x6f, 0x6f, 0x21 "Woo!"]
137
- .WriteArray(new Uint8Array([0x06, 0x00, 0x00, 0x00, 0x2a, 0x01])) //0x0153 [unk = 0x6, 0x0, 0x0, 0x0, 0x2a, 0x1]
138
- .WriteArray(_writeQuests(char.header.quests_normal)) //0x0159
139
- .WriteArray(_writeQuests(char.header.quests_nm)) //0x01b9
140
- .WriteArray(_writeQuests(char.header.quests_hell)) //0x0219
141
- .WriteString("WS", 2) //0x0279 [waypoint data = 0x57, 0x53 "WS"]
142
- .WriteArray(new Uint8Array([0x01, 0x00, 0x00, 0x00, 0x50, 0x00])) //0x027b [unk = 0x1, 0x0, 0x0, 0x0, 0x50, 0x0]
143
- .WriteArray(_writeWaypointData(char.header.waypoints)) //0x0281
144
- .WriteArray(new Uint8Array([0x01, 0x77])) //0x02c9 [npc header = 0x01, 0x77 ".w"]
145
- .WriteUInt16(0x34) //0x02ca [npc struct length]
146
- .WriteArray(_writeNPCData(char.header.npcs)); //0x02cc [npc introduction data... unk]
147
- }
148
- exports.writeHeader = writeHeader;
149
- function _classId(name, constants) {
150
- if (!name)
151
- return -1;
152
- return constants.classes.findIndex((c) => c && c.n == name);
153
- }
154
- function _skillId(name, constants) {
155
- //default to "attack" if empty string or can't find spellname.
156
- if (name === "")
157
- return 0;
158
- if (!name)
159
- return -1;
160
- const idx = constants.skills.findIndex((s) => s && s.s == name);
161
- return idx >= 0 ? idx : 0;
162
- }
163
- function _readStatus(byte) {
164
- const status = {};
165
- status.hardcore = ((byte >>> 2) & 1) === 1;
166
- status.died = ((byte >>> 3) & 1) === 1;
167
- status.expansion = ((byte >>> 5) & 1) === 1;
168
- status.ladder = ((byte >>> 6) & 1) === 1;
169
- return status;
170
- }
171
- function _writeStatus(status) {
172
- const arr = new Uint8Array(1);
173
- arr[0] |= status.hardcore ? 1 << 2 : 0;
174
- arr[0] |= status.died ? 1 << 3 : 0;
175
- arr[0] |= status.expansion ? 1 << 5 : 0;
176
- arr[0] |= status.ladder ? 1 << 6 : 0;
177
- return arr;
178
- }
179
- function _readCharMenuAppearance(bytes, constants) {
180
- const appearance = {};
181
- const reader = new bitreader_1.BitReader(bytes);
182
- const graphics = reader.ReadArray(16);
183
- const tints = reader.ReadArray(16);
184
- appearance.head = { graphic: graphics[0], tint: tints[0] };
185
- appearance.torso = { graphic: graphics[1], tint: tints[1] };
186
- appearance.legs = { graphic: graphics[2], tint: tints[2] };
187
- appearance.right_arm = { graphic: graphics[3], tint: tints[3] };
188
- appearance.left_arm = { graphic: graphics[4], tint: tints[4] };
189
- appearance.right_hand = { graphic: graphics[5], tint: tints[5] };
190
- appearance.left_hand = { graphic: graphics[6], tint: tints[6] };
191
- appearance.shield = { graphic: graphics[7], tint: tints[7] };
192
- appearance.special1 = { graphic: graphics[8], tint: tints[8] };
193
- appearance.special2 = { graphic: graphics[9], tint: tints[9] };
194
- appearance.special3 = { graphic: graphics[10], tint: tints[10] };
195
- appearance.special4 = { graphic: graphics[11], tint: tints[11] };
196
- appearance.special5 = { graphic: graphics[12], tint: tints[12] };
197
- appearance.special6 = { graphic: graphics[13], tint: tints[13] };
198
- appearance.special7 = { graphic: graphics[14], tint: tints[14] };
199
- appearance.special8 = { graphic: graphics[15], tint: tints[15] };
200
- return appearance;
201
- }
202
- function _writeCharMenuAppearance(appearance, constants) {
203
- const writer = new bitwriter_1.BitWriter(32);
204
- writer.length = 32 * 8;
205
- const graphics = [];
206
- graphics.push(appearance && appearance.head ? appearance.head.graphic : 0);
207
- graphics.push(appearance && appearance.torso ? appearance.torso.graphic : 0);
208
- graphics.push(appearance && appearance.legs ? appearance.legs.graphic : 0);
209
- graphics.push(appearance && appearance.right_arm ? appearance.right_arm.graphic : 0);
210
- graphics.push(appearance && appearance.left_arm ? appearance.left_arm.graphic : 0);
211
- graphics.push(appearance && appearance.right_hand ? appearance.right_hand.graphic : 0);
212
- graphics.push(appearance && appearance.left_hand ? appearance.left_hand.graphic : 0);
213
- graphics.push(appearance && appearance.shield ? appearance.shield.graphic : 0);
214
- graphics.push(appearance && appearance.special1 ? appearance.special1.graphic : 0);
215
- graphics.push(appearance && appearance.special2 ? appearance.special2.graphic : 0);
216
- graphics.push(appearance && appearance.special3 ? appearance.special3.graphic : 0);
217
- graphics.push(appearance && appearance.special4 ? appearance.special4.graphic : 0);
218
- graphics.push(appearance && appearance.special5 ? appearance.special5.graphic : 0);
219
- graphics.push(appearance && appearance.special6 ? appearance.special6.graphic : 0);
220
- graphics.push(appearance && appearance.special7 ? appearance.special7.graphic : 0);
221
- graphics.push(appearance && appearance.special8 ? appearance.special8.graphic : 0);
222
- for (const g of graphics) {
223
- writer.WriteUInt8(g);
224
- }
225
- const tints = [];
226
- tints.push(appearance && appearance.head ? appearance.head.tint : 0);
227
- tints.push(appearance && appearance.torso ? appearance.torso.tint : 0);
228
- tints.push(appearance && appearance.legs ? appearance.legs.tint : 0);
229
- tints.push(appearance && appearance.right_arm ? appearance.right_arm.tint : 0);
230
- tints.push(appearance && appearance.left_arm ? appearance.left_arm.tint : 0);
231
- tints.push(appearance && appearance.right_hand ? appearance.right_hand.tint : 0);
232
- tints.push(appearance && appearance.left_hand ? appearance.left_hand.tint : 0);
233
- tints.push(appearance && appearance.shield ? appearance.shield.tint : 0);
234
- tints.push(appearance && appearance.special1 ? appearance.special1.tint : 0);
235
- tints.push(appearance && appearance.special2 ? appearance.special2.tint : 0);
236
- tints.push(appearance && appearance.special3 ? appearance.special3.tint : 0);
237
- tints.push(appearance && appearance.special4 ? appearance.special4.tint : 0);
238
- tints.push(appearance && appearance.special5 ? appearance.special5.tint : 0);
239
- tints.push(appearance && appearance.special6 ? appearance.special6.tint : 0);
240
- tints.push(appearance && appearance.special7 ? appearance.special7.tint : 0);
241
- tints.push(appearance && appearance.special8 ? appearance.special8.tint : 0);
242
- for (const t of tints) {
243
- writer.WriteUInt8(t);
244
- }
245
- return writer.ToArray();
246
- }
247
- function _readAssignedSkills(bytes, constants) {
248
- const skills = [];
249
- const reader = new bitreader_1.BitReader(bytes);
250
- for (let i = 0; i < 16; i++) {
251
- const skillId = reader.ReadUInt32();
252
- const skill = constants.skills[skillId];
253
- if (skill) {
254
- skills.push(skill.s);
255
- }
256
- }
257
- return skills;
258
- }
259
- function _writeAssignedSkills(skills, constants) {
260
- const writer = new bitwriter_1.BitWriter(64);
261
- writer.length = 64 * 8;
262
- skills = skills || [];
263
- for (let i = 0; i < 16; i++) {
264
- const skillId = _skillId(skills[i], constants);
265
- if (skillId > 0) {
266
- writer.WriteUInt32(skillId);
267
- }
268
- else {
269
- writer.WriteUInt32(0xffff);
270
- }
271
- }
272
- return writer.ToArray();
273
- }
274
- function _readDifficulty(bytes) {
275
- const difficulty = {};
276
- difficulty.Normal = bytes[0];
277
- difficulty.Nightmare = bytes[1];
278
- difficulty.Hell = bytes[2];
279
- return difficulty;
280
- }
281
- function _writeDifficulty(difficulty) {
282
- const writer = new bitwriter_1.BitWriter(3);
283
- writer.length = 3 * 8;
284
- writer.WriteUInt8(difficulty.Normal);
285
- writer.WriteUInt8(difficulty.Nightmare);
286
- writer.WriteUInt8(difficulty.Hell);
287
- return writer.ToArray();
288
- }
289
- function _readQuests(bytes) {
290
- const quests = {};
291
- const reader = new bitreader_1.BitReader(bytes);
292
- quests.act_i = {};
293
- quests.act_i.introduced = reader.ReadUInt16() === 0x1; //0x0000
294
- quests.act_i.den_of_evil = _readQuest(reader.ReadArray(2)); //0x0002
295
- quests.act_i.sisters_burial_grounds = _readQuest(reader.ReadArray(2));
296
- quests.act_i.tools_of_the_trade = _readQuest(reader.ReadArray(2));
297
- quests.act_i.the_search_for_cain = _readQuest(reader.ReadArray(2));
298
- quests.act_i.the_forgotten_tower = _readQuest(reader.ReadArray(2));
299
- quests.act_i.sisters_to_the_slaughter = _readQuest(reader.ReadArray(2));
300
- quests.act_i.completed = reader.ReadUInt16() === 0x1;
301
- quests.act_ii = {};
302
- quests.act_ii.introduced = reader.ReadUInt16() === 0x1; //0x0010 [if jerhyn introduction = 0x01]
303
- quests.act_ii.radaments_lair = _readQuest(reader.ReadArray(2)); //0x0012
304
- quests.act_ii.the_horadric_staff = _readQuest(reader.ReadArray(2));
305
- quests.act_ii.tainted_sun = _readQuest(reader.ReadArray(2));
306
- quests.act_ii.arcane_sanctuary = _readQuest(reader.ReadArray(2));
307
- quests.act_ii.the_summoner = _readQuest(reader.ReadArray(2));
308
- quests.act_ii.the_seven_tombs = _readQuest(reader.ReadArray(2));
309
- quests.act_ii.completed = reader.ReadUInt16() === 0x1; //0x001e
310
- quests.act_iii = {};
311
- quests.act_iii.introduced = reader.ReadUInt16() === 0x1; //0x0020 [if hratli introduction = 0x01]
312
- quests.act_iii.lam_esens_tome = _readQuest(reader.ReadArray(2)); //0x0022
313
- quests.act_iii.khalims_will = _readQuest(reader.ReadArray(2));
314
- quests.act_iii.blade_of_the_old_religion = _readQuest(reader.ReadArray(2));
315
- quests.act_iii.the_golden_bird = _readQuest(reader.ReadArray(2));
316
- quests.act_iii.the_blackened_temple = _readQuest(reader.ReadArray(2));
317
- quests.act_iii.the_guardian = _readQuest(reader.ReadArray(2));
318
- quests.act_iii.completed = reader.ReadUInt16() === 0x1; //0x002e
319
- quests.act_iv = {};
320
- quests.act_iv.introduced = reader.ReadUInt16() === 0x1; //0x0030 [if activ introduction = 0x01]
321
- quests.act_iv.the_fallen_angel = _readQuest(reader.ReadArray(2)); //0x0032
322
- quests.act_iv.terrors_end = _readQuest(reader.ReadArray(2));
323
- quests.act_iv.hellforge = _readQuest(reader.ReadArray(2));
324
- quests.act_iv.completed = reader.ReadUInt16() === 0x1; //0x0038
325
- reader.SkipBytes(10); //0x003a
326
- quests.act_v = {};
327
- quests.act_v.introduced = reader.ReadUInt16() === 0x1;
328
- quests.act_v.siege_on_harrogath = _readQuest(reader.ReadArray(2)); //0x0046
329
- quests.act_v.rescue_on_mount_arreat = _readQuest(reader.ReadArray(2));
330
- quests.act_v.prison_of_ice = _readQuest(reader.ReadArray(2));
331
- quests.act_v.betrayal_of_harrogath = _readQuest(reader.ReadArray(2));
332
- quests.act_v.rite_of_passage = _readQuest(reader.ReadArray(2));
333
- quests.act_v.eve_of_destruction = _readQuest(reader.ReadArray(2));
334
- quests.act_v.completed = reader.ReadUInt16() === 0x1;
335
- reader.SkipBytes(12);
336
- return quests; //sizeof [0x0060]
337
- }
338
- function _writeQuests(quests) {
339
- const writer = new bitwriter_1.BitWriter(96);
340
- writer.length = 96 * 8;
341
- const difficultyCompleted = +quests.act_v.completed || +quests.act_v.eve_of_destruction.is_completed;
342
- return writer
343
- .WriteUInt16(+quests.act_i.introduced)
344
- .WriteArray(_writeQuest(quests.act_i.den_of_evil))
345
- .WriteArray(_writeQuest(quests.act_i.sisters_burial_grounds))
346
- .WriteArray(_writeQuest(quests.act_i.tools_of_the_trade))
347
- .WriteArray(_writeQuest(quests.act_i.the_search_for_cain))
348
- .WriteArray(_writeQuest(quests.act_i.the_forgotten_tower))
349
- .WriteArray(_writeQuest(quests.act_i.sisters_to_the_slaughter))
350
- .WriteUInt16(+quests.act_i.completed || +quests.act_i.sisters_to_the_slaughter.is_completed)
351
- .WriteUInt16(+quests.act_ii.introduced || +quests.act_i.sisters_to_the_slaughter.is_completed)
352
- .WriteArray(_writeQuest(quests.act_ii.radaments_lair))
353
- .WriteArray(_writeQuest(quests.act_ii.the_horadric_staff))
354
- .WriteArray(_writeQuest(quests.act_ii.tainted_sun))
355
- .WriteArray(_writeQuest(quests.act_ii.arcane_sanctuary))
356
- .WriteArray(_writeQuest(quests.act_ii.the_summoner))
357
- .WriteArray(_writeQuest(quests.act_ii.the_seven_tombs))
358
- .WriteUInt16(+quests.act_ii.completed || +quests.act_ii.the_seven_tombs.is_completed)
359
- .WriteUInt16(+quests.act_iii.introduced || +quests.act_ii.the_seven_tombs.is_completed)
360
- .WriteArray(_writeQuest(quests.act_iii.lam_esens_tome))
361
- .WriteArray(_writeQuest(quests.act_iii.khalims_will))
362
- .WriteArray(_writeQuest(quests.act_iii.blade_of_the_old_religion))
363
- .WriteArray(_writeQuest(quests.act_iii.the_golden_bird))
364
- .WriteArray(_writeQuest(quests.act_iii.the_blackened_temple))
365
- .WriteArray(_writeQuest(quests.act_iii.the_guardian))
366
- .WriteUInt16(+quests.act_iii.completed || +quests.act_iii.the_guardian.is_completed)
367
- .WriteUInt16(+quests.act_iv.introduced || +quests.act_iii.the_guardian.is_completed)
368
- .WriteArray(_writeQuest(quests.act_iv.the_fallen_angel))
369
- .WriteArray(_writeQuest(quests.act_iv.terrors_end))
370
- .WriteArray(_writeQuest(quests.act_iv.hellforge))
371
- .WriteUInt16(+quests.act_iv.completed || +quests.act_iv.terrors_end.is_completed)
372
- .WriteArray(new Uint8Array(6))
373
- .WriteUInt16(+quests.act_v.introduced || +quests.act_iv.terrors_end.is_completed)
374
- .WriteArray(new Uint8Array(4))
375
- .WriteArray(_writeQuest(quests.act_v.siege_on_harrogath))
376
- .WriteArray(_writeQuest(quests.act_v.rescue_on_mount_arreat))
377
- .WriteArray(_writeQuest(quests.act_v.prison_of_ice))
378
- .WriteArray(_writeQuest(quests.act_v.betrayal_of_harrogath))
379
- .WriteArray(_writeQuest(quests.act_v.rite_of_passage))
380
- .WriteArray(_writeQuest(quests.act_v.eve_of_destruction))
381
- .WriteUInt8(difficultyCompleted)
382
- .WriteUInt8(difficultyCompleted ? 0x80 : 0x0) //is this right?
383
- .WriteArray(new Uint8Array(12))
384
- .ToArray();
385
- }
386
- function _readQuest(bytes) {
387
- const quest = {};
388
- const reader = new bitreader_1.BitReader(bytes);
389
- quest.is_completed = reader.ReadBit() === 1;
390
- quest.is_requirement_completed = reader.ReadBit() === 1;
391
- quest.is_received = reader.ReadBit() === 1;
392
- if (reader.ReadBit() === 1)
393
- quest.unk3 = true;
394
- if (reader.ReadBit() === 1)
395
- quest.unk4 = true;
396
- if (reader.ReadBit() === 1)
397
- quest.unk5 = true;
398
- if (reader.ReadBit() === 1)
399
- quest.unk6 = true;
400
- if (reader.ReadBit() === 1)
401
- quest.consumed_scroll = true;
402
- if (reader.ReadBit() === 1)
403
- quest.unk8 = true;
404
- if (reader.ReadBit() === 1)
405
- quest.unk9 = true;
406
- if (reader.ReadBit() === 1)
407
- quest.unk10 = true;
408
- if (reader.ReadBit() === 1)
409
- quest.unk11 = true;
410
- quest.closed = reader.ReadBit() === 1;
411
- quest.done_recently = reader.ReadBit() === 1;
412
- if (reader.ReadBit() === 1)
413
- quest.unk14 = true;
414
- if (reader.ReadBit() === 1)
415
- quest.unk15 = true;
416
- return quest;
417
- }
418
- function _writeQuest(quest) {
419
- const writer = new bitwriter_1.BitWriter(2);
420
- writer.length = 2 * 8;
421
- writer.WriteBit(+quest.is_completed);
422
- writer.WriteBit(+quest.is_requirement_completed);
423
- writer.WriteBit(+quest.is_received);
424
- writer.WriteBit(+quest.unk3);
425
- writer.WriteBit(+quest.unk4);
426
- writer.WriteBit(+quest.unk5);
427
- writer.WriteBit(+quest.unk6);
428
- writer.WriteBit(+quest.consumed_scroll);
429
- writer.WriteBit(+quest.unk8);
430
- writer.WriteBit(+quest.unk9);
431
- writer.WriteBit(+quest.unk10);
432
- writer.WriteBit(+quest.unk11);
433
- writer.WriteBit(+quest.closed);
434
- writer.WriteBit(+quest.done_recently);
435
- writer.WriteBit(+quest.unk14);
436
- writer.WriteBit(+quest.unk15);
437
- return writer.ToArray();
438
- }
439
- function _readWaypointData(bytes) {
440
- const waypoints = {};
441
- const reader = new bitreader_1.BitReader(bytes);
442
- for (let i = 0; i < difficulties.length; i++) {
443
- waypoints[difficulties[i]] = _readWaypoints(reader.ReadArray(24));
444
- }
445
- return waypoints;
446
- }
447
- function _readWaypoints(bytes) {
448
- const waypoints = {};
449
- const reader = new bitreader_1.BitReader(bytes);
450
- reader.SkipBytes(2); //unk = 0x2, 0x
451
- waypoints.act_i = {};
452
- waypoints.act_i.rogue_encampement = reader.ReadBit() === 1;
453
- waypoints.act_i.cold_plains = reader.ReadBit() === 1;
454
- waypoints.act_i.stony_field = reader.ReadBit() === 1;
455
- waypoints.act_i.dark_woods = reader.ReadBit() === 1;
456
- waypoints.act_i.black_marsh = reader.ReadBit() === 1;
457
- waypoints.act_i.outer_cloister = reader.ReadBit() === 1;
458
- waypoints.act_i.jail_lvl_1 = reader.ReadBit() === 1;
459
- waypoints.act_i.inner_cloister = reader.ReadBit() === 1;
460
- waypoints.act_i.catacombs_lvl_2 = reader.ReadBit() === 1;
461
- waypoints.act_ii = {};
462
- waypoints.act_ii.lut_gholein = reader.ReadBit() === 1;
463
- waypoints.act_ii.sewers_lvl_2 = reader.ReadBit() === 1;
464
- waypoints.act_ii.dry_hills = reader.ReadBit() === 1;
465
- waypoints.act_ii.halls_of_the_dead_lvl_2 = reader.ReadBit() === 1;
466
- waypoints.act_ii.far_oasis = reader.ReadBit() === 1;
467
- waypoints.act_ii.lost_city = reader.ReadBit() === 1;
468
- waypoints.act_ii.palace_cellar_lvl_1 = reader.ReadBit() === 1;
469
- waypoints.act_ii.arcane_sanctuary = reader.ReadBit() === 1;
470
- waypoints.act_ii.canyon_of_the_magi = reader.ReadBit() === 1;
471
- waypoints.act_iii = {};
472
- waypoints.act_iii.kurast_docks = reader.ReadBit() === 1;
473
- waypoints.act_iii.spider_forest = reader.ReadBit() === 1;
474
- waypoints.act_iii.great_marsh = reader.ReadBit() === 1;
475
- waypoints.act_iii.flayer_jungle = reader.ReadBit() === 1;
476
- waypoints.act_iii.lower_kurast = reader.ReadBit() === 1;
477
- waypoints.act_iii.kurast_bazaar = reader.ReadBit() === 1;
478
- waypoints.act_iii.upper_kurast = reader.ReadBit() === 1;
479
- waypoints.act_iii.travincal = reader.ReadBit() === 1;
480
- waypoints.act_iii.durance_of_hate_lvl_2 = reader.ReadBit() === 1;
481
- waypoints.act_iv = {};
482
- waypoints.act_iv.the_pandemonium_fortress = reader.ReadBit() === 1;
483
- waypoints.act_iv.city_of_the_damned = reader.ReadBit() === 1;
484
- waypoints.act_iv.river_of_flame = reader.ReadBit() === 1;
485
- waypoints.act_v = {};
486
- waypoints.act_v.harrogath = reader.ReadBit() === 1;
487
- waypoints.act_v.frigid_highlands = reader.ReadBit() === 1;
488
- waypoints.act_v.arreat_plateau = reader.ReadBit() === 1;
489
- waypoints.act_v.crystalline_passage = reader.ReadBit() === 1;
490
- waypoints.act_v.glacial_trail = reader.ReadBit() === 1;
491
- waypoints.act_v.halls_of_pain = reader.ReadBit() === 1;
492
- waypoints.act_v.frozen_tundra = reader.ReadBit() === 1;
493
- waypoints.act_v.the_ancients_way = reader.ReadBit() === 1;
494
- waypoints.act_v.worldstone_keep_lvl_2 = reader.ReadBit() === 1;
495
- reader.Align().SkipBytes(17);
496
- return waypoints;
497
- }
498
- function _writeWaypointData(waypoints) {
499
- const writer = new bitwriter_1.BitWriter(72);
500
- writer.length = 72 * 8;
501
- for (let i = 0; i < difficulties.length; i++) {
502
- const w = waypoints != null ? waypoints[difficulties[i]] : null;
503
- writer.WriteArray(_writeWaypoints(w));
504
- }
505
- return writer.ToArray();
506
- }
507
- function _writeWaypoints(waypoints) {
508
- const writer = new bitwriter_1.BitWriter(24);
509
- writer.length = 24 * 8;
510
- writer.WriteArray(new Uint8Array([0x02, 0x01]));
511
- if (waypoints) {
512
- if (waypoints.act_i) {
513
- writer.WriteBit(+waypoints.act_i.rogue_encampement);
514
- writer.WriteBit(+waypoints.act_i.cold_plains);
515
- writer.WriteBit(+waypoints.act_i.stony_field);
516
- writer.WriteBit(+waypoints.act_i.dark_woods);
517
- writer.WriteBit(+waypoints.act_i.black_marsh);
518
- writer.WriteBit(+waypoints.act_i.outer_cloister);
519
- writer.WriteBit(+waypoints.act_i.jail_lvl_1);
520
- writer.WriteBit(+waypoints.act_i.inner_cloister);
521
- writer.WriteBit(+waypoints.act_i.catacombs_lvl_2);
522
- }
523
- if (waypoints.act_ii) {
524
- writer.WriteBit(+waypoints.act_ii.lut_gholein);
525
- writer.WriteBit(+waypoints.act_ii.sewers_lvl_2);
526
- writer.WriteBit(+waypoints.act_ii.dry_hills);
527
- writer.WriteBit(+waypoints.act_ii.halls_of_the_dead_lvl_2);
528
- writer.WriteBit(+waypoints.act_ii.far_oasis);
529
- writer.WriteBit(+waypoints.act_ii.lost_city);
530
- writer.WriteBit(+waypoints.act_ii.palace_cellar_lvl_1);
531
- writer.WriteBit(+waypoints.act_ii.arcane_sanctuary);
532
- writer.WriteBit(+waypoints.act_ii.canyon_of_the_magi);
533
- }
534
- if (waypoints.act_iii) {
535
- writer.WriteBit(+waypoints.act_iii.kurast_docks);
536
- writer.WriteBit(+waypoints.act_iii.spider_forest);
537
- writer.WriteBit(+waypoints.act_iii.great_marsh);
538
- writer.WriteBit(+waypoints.act_iii.flayer_jungle);
539
- writer.WriteBit(+waypoints.act_iii.lower_kurast);
540
- writer.WriteBit(+waypoints.act_iii.kurast_bazaar);
541
- writer.WriteBit(+waypoints.act_iii.upper_kurast);
542
- writer.WriteBit(+waypoints.act_iii.travincal);
543
- writer.WriteBit(+waypoints.act_iii.durance_of_hate_lvl_2);
544
- }
545
- if (waypoints.act_iv) {
546
- writer.WriteBit(+waypoints.act_iv.the_pandemonium_fortress);
547
- writer.WriteBit(+waypoints.act_iv.city_of_the_damned);
548
- writer.WriteBit(+waypoints.act_iv.river_of_flame);
549
- }
550
- if (waypoints.act_v) {
551
- writer.WriteBit(+waypoints.act_v.harrogath);
552
- writer.WriteBit(+waypoints.act_v.frigid_highlands);
553
- writer.WriteBit(+waypoints.act_v.arreat_plateau);
554
- writer.WriteBit(+waypoints.act_v.crystalline_passage);
555
- writer.WriteBit(+waypoints.act_v.glacial_trail);
556
- writer.WriteBit(+waypoints.act_v.halls_of_pain);
557
- writer.WriteBit(+waypoints.act_v.frozen_tundra);
558
- writer.WriteBit(+waypoints.act_v.the_ancients_way);
559
- writer.WriteBit(+waypoints.act_v.worldstone_keep_lvl_2);
560
- }
561
- }
562
- else {
563
- //all wps
564
- //writer.WriteArray(new Uint8Array(5));
565
- writer.WriteArray(new Uint8Array([0xff, 0xff, 0xff, 0xff, 0x7f]));
566
- //_writeBits(writer, 0x3fffffffff, start, 0, 38);
567
- }
568
- writer.Align().WriteArray(new Uint8Array(17));
569
- return writer.ToArray();
570
- }
571
- function _readNPCData(bytes) {
572
- const npcs = { normal: {}, nm: {}, hell: {} };
573
- const reader = new bitreader_1.BitReader(bytes);
574
- for (let j = 0; j < 3; j++) {
575
- npcs[difficulties[j]] = {
576
- warriv_act_ii: { intro: false, congrats: false },
577
- charsi: { intro: false, congrats: false },
578
- warriv_act_i: { intro: false, congrats: false },
579
- kashya: { intro: false, congrats: false },
580
- akara: { intro: false, congrats: false },
581
- gheed: { intro: false, congrats: false },
582
- greiz: { intro: false, congrats: false },
583
- jerhyn: { intro: false, congrats: false },
584
- meshif_act_ii: { intro: false, congrats: false },
585
- geglash: { intro: false, congrats: false },
586
- lysnader: { intro: false, congrats: false },
587
- fara: { intro: false, congrats: false },
588
- drogan: { intro: false, congrats: false },
589
- alkor: { intro: false, congrats: false },
590
- hratli: { intro: false, congrats: false },
591
- ashera: { intro: false, congrats: false },
592
- cain_act_iii: { intro: false, congrats: false },
593
- elzix: { intro: false, congrats: false },
594
- malah: { intro: false, congrats: false },
595
- anya: { intro: false, congrats: false },
596
- natalya: { intro: false, congrats: false },
597
- meshif_act_iii: { intro: false, congrats: false },
598
- ormus: { intro: false, congrats: false },
599
- cain_act_v: { intro: false, congrats: false },
600
- qualkehk: { intro: false, congrats: false },
601
- nihlathak: { intro: false, congrats: false },
602
- };
603
- }
604
- //introductions
605
- for (let i = 0; i < 3; i++) {
606
- const j = i * 5;
607
- const npc = npcs[difficulties[i]];
608
- npc.warriv_act_ii.intro = reader.bits[0 + j * 8] === 1;
609
- npc.charsi.intro = reader.bits[2 + j * 8] === 1;
610
- npc.warriv_act_i.intro = reader.bits[3 + j * 8] === 1;
611
- npc.kashya.intro = reader.bits[4 + j * 8] === 1;
612
- npc.akara.intro = reader.bits[5 + j * 8] === 1;
613
- npc.gheed.intro = reader.bits[6 + j * 8] === 1;
614
- npc.greiz.intro = reader.bits[8 + j * 8] === 1;
615
- npc.jerhyn.intro = reader.bits[9 + j * 8] === 1;
616
- npc.meshif_act_ii.intro = reader.bits[10 + j * 8] === 1;
617
- npc.geglash.intro = reader.bits[11 + j * 8] === 1;
618
- npc.lysnader.intro = reader.bits[12 + j * 8] === 1;
619
- npc.fara.intro = reader.bits[13 + j * 8] === 1;
620
- npc.drogan.intro = reader.bits[14 + j * 8] === 1;
621
- npc.alkor.intro = reader.bits[16 + j * 8] === 1;
622
- npc.hratli.intro = reader.bits[17 + j * 8] === 1;
623
- npc.ashera.intro = reader.bits[18 + j * 8] === 1;
624
- npc.cain_act_iii.intro = reader.bits[21 + j * 8] === 1;
625
- npc.elzix.intro = reader.bits[23 + j * 8] === 1;
626
- npc.malah.intro = reader.bits[24 + j * 8] === 1;
627
- npc.anya.intro = reader.bits[25 + j * 8] === 1;
628
- npc.natalya.intro = reader.bits[27 + j * 8] === 1;
629
- npc.meshif_act_iii.intro = reader.bits[28 + j * 8] === 1;
630
- npc.ormus.intro = reader.bits[31 + j * 8] === 1;
631
- npc.cain_act_v.intro = reader.bits[37 + j * 8] === 1;
632
- npc.qualkehk.intro = reader.bits[38 + j * 8] === 1;
633
- npc.nihlathak.intro = reader.bits[39 + j * 8] === 1;
634
- }
635
- //congrats
636
- for (let i = 0; i < 3; i++) {
637
- const j = i * 5;
638
- const npc = npcs[difficulties[i]];
639
- npc.warriv_act_ii.congrats = reader.bits[192 + (0 + j * 8)] === 1;
640
- npc.charsi.congrats = reader.bits[192 + (2 + j * 8)] === 1;
641
- npc.warriv_act_i.congrats = reader.bits[192 + (3 + j * 8)] === 1;
642
- npc.kashya.congrats = reader.bits[192 + (4 + j * 8)] === 1;
643
- npc.akara.congrats = reader.bits[192 + (5 + j * 8)] === 1;
644
- npc.gheed.congrats = reader.bits[192 + (6 + j * 8)] === 1;
645
- npc.greiz.congrats = reader.bits[192 + (8 + j * 8)] === 1;
646
- npc.jerhyn.congrats = reader.bits[192 + (9 + j * 8)] === 1;
647
- npc.meshif_act_ii.congrats = reader.bits[192 + (10 + j * 8)] === 1;
648
- npc.geglash.congrats = reader.bits[192 + (11 + j * 8)] === 1;
649
- npc.lysnader.congrats = reader.bits[192 + (12 + j * 8)] === 1;
650
- npc.fara.congrats = reader.bits[192 + (13 + j * 8)] === 1;
651
- npc.drogan.congrats = reader.bits[192 + (14 + j * 8)] === 1;
652
- npc.alkor.congrats = reader.bits[192 + (16 + j * 8)] === 1;
653
- npc.hratli.congrats = reader.bits[192 + (17 + j * 8)] === 1;
654
- npc.ashera.congrats = reader.bits[192 + (18 + j * 8)] === 1;
655
- npc.cain_act_iii.congrats = reader.bits[192 + (21 + j * 8)] === 1;
656
- npc.elzix.congrats = reader.bits[192 + (23 + j * 8)] === 1;
657
- npc.malah.congrats = reader.bits[192 + (24 + j * 8)] === 1;
658
- npc.anya.congrats = reader.bits[192 + (25 + j * 8)] === 1;
659
- npc.natalya.congrats = reader.bits[192 + (27 + j * 8)] === 1;
660
- npc.meshif_act_iii.congrats = reader.bits[192 + (28 + j * 8)] === 1;
661
- npc.ormus.congrats = reader.bits[192 + (31 + j * 8)] === 1;
662
- npc.cain_act_v.congrats = reader.bits[192 + (37 + j * 8)] === 1;
663
- npc.qualkehk.congrats = reader.bits[192 + (38 + j * 8)] === 1;
664
- npc.nihlathak.congrats = reader.bits[192 + (39 + j * 8)] === 1;
665
- }
666
- return npcs;
667
- }
668
- function _writeNPCData(npcs) {
669
- const writer = new bitwriter_1.BitWriter(0x30);
670
- writer.length = 0x30 * 8;
671
- if (npcs) {
672
- for (let j = 0; j < 3; j++) {
673
- const npc = npcs[difficulties[j]];
674
- writer.SeekByte(j * 5);
675
- writer.WriteBit(+npc.warriv_act_ii.intro);
676
- writer.WriteBit(0);
677
- writer.WriteBit(+npc.charsi.intro);
678
- writer.WriteBit(+npc.warriv_act_i.intro);
679
- writer.WriteBit(+npc.kashya.intro);
680
- writer.WriteBit(+npc.akara.intro);
681
- writer.WriteBit(+npc.gheed.intro);
682
- writer.WriteBit(0);
683
- writer.WriteBit(+npc.greiz.intro);
684
- writer.WriteBit(+npc.jerhyn.intro);
685
- writer.WriteBit(+npc.meshif_act_ii.intro);
686
- writer.WriteBit(+npc.geglash.intro);
687
- writer.WriteBit(+npc.lysnader.intro);
688
- writer.WriteBit(+npc.fara.intro);
689
- writer.WriteBit(+npc.drogan.intro);
690
- writer.WriteBit(0);
691
- writer.WriteBit(+npc.alkor.intro);
692
- writer.WriteBit(+npc.hratli.intro);
693
- writer.WriteBit(+npc.ashera.intro);
694
- writer.WriteBits(new Uint8Array(2).fill(0), 2);
695
- writer.WriteBit(+npc.cain_act_iii.intro);
696
- writer.WriteBit(0);
697
- writer.WriteBit(+npc.elzix.intro);
698
- writer.WriteBit(+npc.malah.intro);
699
- writer.WriteBit(+npc.anya.intro);
700
- writer.WriteBit(0);
701
- writer.WriteBit(+npc.natalya.intro);
702
- writer.WriteBit(+npc.meshif_act_iii.intro);
703
- writer.WriteBits(new Uint8Array(2).fill(0), 2);
704
- writer.WriteBit(+npc.ormus.intro);
705
- writer.WriteBits(new Uint8Array(5).fill(0), 5);
706
- writer.WriteBit(+npc.cain_act_v.intro);
707
- writer.WriteBit(+npc.qualkehk.intro);
708
- writer.WriteBit(+npc.nihlathak.intro);
709
- }
710
- for (let j = 0; j < 3; j++) {
711
- writer.SeekByte(24 + j * 5);
712
- const npc = npcs[difficulties[j]];
713
- writer.WriteBit(+npc.warriv_act_ii.congrats);
714
- writer.WriteBit(0);
715
- writer.WriteBit(+npc.charsi.congrats);
716
- writer.WriteBit(+npc.warriv_act_i.congrats);
717
- writer.WriteBit(+npc.kashya.congrats);
718
- writer.WriteBit(+npc.akara.congrats);
719
- writer.WriteBit(+npc.gheed.congrats);
720
- writer.WriteBit(0);
721
- writer.WriteBit(+npc.greiz.congrats);
722
- writer.WriteBit(+npc.jerhyn.congrats);
723
- writer.WriteBit(+npc.meshif_act_ii.congrats);
724
- writer.WriteBit(+npc.geglash.congrats);
725
- writer.WriteBit(+npc.lysnader.congrats);
726
- writer.WriteBit(+npc.fara.congrats);
727
- writer.WriteBit(+npc.drogan.congrats);
728
- writer.WriteBit(0);
729
- writer.WriteBit(+npc.alkor.congrats);
730
- writer.WriteBit(+npc.hratli.congrats);
731
- writer.WriteBit(+npc.ashera.congrats);
732
- writer.WriteBits(new Uint8Array(2).fill(0), 2);
733
- writer.WriteBit(+npc.cain_act_iii.congrats);
734
- writer.WriteBit(0);
735
- writer.WriteBit(+npc.elzix.congrats);
736
- writer.WriteBit(+npc.malah.congrats);
737
- writer.WriteBit(+npc.anya.congrats);
738
- writer.WriteBit(0);
739
- writer.WriteBit(+npc.natalya.congrats);
740
- writer.WriteBit(+npc.meshif_act_iii.congrats);
741
- writer.WriteBits(new Uint8Array(2).fill(0), 2);
742
- writer.WriteBit(+npc.ormus.congrats);
743
- writer.WriteBits(new Uint8Array(5).fill(0), 5);
744
- writer.WriteBit(+npc.cain_act_v.congrats);
745
- writer.WriteBit(+npc.qualkehk.congrats);
746
- writer.WriteBit(+npc.nihlathak.congrats);
747
- }
748
- }
749
- return writer.ToArray();
750
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writeHeader = exports.readHeader = void 0;
4
+ const bitreader_1 = require("../../binary/bitreader");
5
+ const bitwriter_1 = require("../../binary/bitwriter");
6
+ const difficulties = ["normal", "nm", "hell"];
7
+ function readHeader(char, reader, constants) {
8
+ var _a, _b, _c, _d;
9
+ char.header.filesize = reader.ReadUInt32(); //0x0008
10
+ char.header.checksum = reader.ReadUInt32().toString(16).padStart(8, "0"); //0x000c
11
+ reader.SkipBytes(4); //0x0010
12
+ if (char.header.version > 0x61) {
13
+ if (char.header.version === 0x69) {
14
+ reader.SeekByte(299);
15
+ }
16
+ else {
17
+ reader.SeekByte(267);
18
+ }
19
+ }
20
+ char.header.name = reader.ReadString(16).replace(/\0/g, ""); //0x0014
21
+ if (char.header.version > 0x61) {
22
+ if (char.header.version === 0x69) {
23
+ reader.SeekByte(20);
24
+ }
25
+ else {
26
+ reader.SeekByte(36);
27
+ }
28
+ }
29
+ char.header.status = _readStatus(reader.ReadUInt8()); //0x0024
30
+ char.header.progression = reader.ReadUInt8(); //0x0025
31
+ char.header.active_arms = reader.ReadUInt16(); //0x0026 [unk = 0x0, 0x0]
32
+ char.header.class = constants.classes[reader.ReadUInt8()].n; //0x0028
33
+ reader.SkipBytes(2); //0x0029 [unk = 0x10, 0x1E]
34
+ char.header.level = reader.ReadUInt8(); //0x002b
35
+ char.header.created = reader.ReadUInt32(); //0x002c
36
+ char.header.last_played = reader.ReadUInt32(); //0x0030
37
+ reader.SkipBytes(4); //0x0034 [unk = 0xff, 0xff, 0xff, 0xff]
38
+ char.header.assigned_skills = _readAssignedSkills(reader.ReadArray(64), constants); //0x0038
39
+ char.header.left_skill = (_a = constants.skills[reader.ReadUInt32()]) === null || _a === void 0 ? void 0 : _a.s; //0x0078
40
+ char.header.right_skill = (_b = constants.skills[reader.ReadUInt32()]) === null || _b === void 0 ? void 0 : _b.s; //0x007c
41
+ char.header.left_swap_skill = (_c = constants.skills[reader.ReadUInt32()]) === null || _c === void 0 ? void 0 : _c.s; //0x0080
42
+ char.header.right_swap_skill = (_d = constants.skills[reader.ReadUInt32()]) === null || _d === void 0 ? void 0 : _d.s; //0x0084
43
+ char.header.menu_appearance = _readCharMenuAppearance(reader.ReadArray(32), constants); //0x0088 [char menu appearance]
44
+ char.header.difficulty = _readDifficulty(reader.ReadArray(3)); //0x00a8
45
+ char.header.map_id = reader.ReadUInt32(); //0x00ab
46
+ reader.SkipBytes(2); //0x00af [unk = 0x0, 0x0]
47
+ char.header.dead_merc = reader.ReadUInt16(); //0x00b1
48
+ char.header.merc_id = reader.ReadUInt32().toString(16); //0x00b3
49
+ char.header.merc_name_id = reader.ReadUInt16(); //0x00b7
50
+ char.header.merc_type = reader.ReadUInt16(); //0x00b9
51
+ char.header.merc_experience = reader.ReadUInt32(); //0x00bb 175
52
+ if (char.header.version === 0x69) {
53
+ reader.SkipBytes(228); //0x00bf [unk]
54
+ }
55
+ else {
56
+ reader.SkipBytes(144); //0x00bf [unk]
57
+ }
58
+ reader.SkipBytes(4); //0x014f [quests header identifier = 0x57, 0x6f, 0x6f, 0x21 "Woo!"]
59
+ reader.SkipBytes(4); //0x0153 [version = 0x6, 0x0, 0x0, 0x0]
60
+ reader.SkipBytes(2); //0x0153 [quests header length = 0x2a, 0x1]
61
+ char.header.quests_normal = _readQuests(reader.ReadArray(96)); //0x0159
62
+ char.header.quests_nm = _readQuests(reader.ReadArray(96)); //0x01b9
63
+ char.header.quests_hell = _readQuests(reader.ReadArray(96)); //0x0219
64
+ reader.SkipBytes(2); //0x0279 [waypoint header identifier = 0x57, 0x53 "WS"]
65
+ reader.SkipBytes(4); //0x027b [waypoint header version = 0x1, 0x0, 0x0, 0x0]
66
+ reader.SkipBytes(2); //0x027f [waypoint header length = 0x50, 0x0]
67
+ char.header.waypoints = _readWaypointData(reader.ReadArray(0x48)); //0x0281
68
+ reader.SkipBytes(2); //0x02c9 [npc header identifier = 0x01, 0x77 ".w"]
69
+ reader.SkipBytes(2); //0x02ca [npc header length = 0x34]
70
+ char.header.npcs = _readNPCData(reader.ReadArray(0x30)); //0x02cc
71
+ }
72
+ exports.readHeader = readHeader;
73
+ function writeHeader(char, writer, constants) {
74
+ writer
75
+ .WriteUInt32(0x0) //0x0008 (filesize. needs to be writen after all data)
76
+ .WriteUInt32(0x0); //0x000c (checksum. needs to be calculated after all data writer)
77
+ if (char.header.version > 0x61) {
78
+ if (char.header.version === 0x69) {
79
+ writer.WriteArray(new Uint8Array([0x00, 0x00, 0x00, 0x00]));
80
+ }
81
+ else {
82
+ writer.WriteArray(new Uint8Array(Array(20).fill(0))); // 0x0010
83
+ }
84
+ }
85
+ else {
86
+ writer
87
+ .WriteArray(new Uint8Array([0x00, 0x00, 0x00, 0x00])) //0x0010
88
+ .WriteString(char.header.name, 16); //0x0014
89
+ }
90
+ writer
91
+ .WriteArray(_writeStatus(char.header.status)) //0x0024
92
+ .WriteUInt8(char.header.progression) //0x0025
93
+ .WriteUInt16(char.header.active_arms) //0x0026
94
+ .WriteUInt8(_classId(char.header.class, constants)) //0x0028
95
+ .WriteArray(new Uint8Array([0x10, 0x1e])) //0x0029
96
+ .WriteUInt8(char.header.level) //0x002b
97
+ .WriteArray(new Uint8Array([0x00, 0x00, 0x00, 0x00])) //0x002c
98
+ .WriteUInt32(char.header.last_played) //0x0030
99
+ .WriteArray(new Uint8Array([0xff, 0xff, 0xff, 0xff])) //0x0034
100
+ .WriteArray(_writeAssignedSkills(char.header.assigned_skills, constants)) //0x0038
101
+ .WriteUInt32(_skillId(char.header.left_skill, constants)) //0x0078
102
+ .WriteUInt32(_skillId(char.header.right_skill, constants)) //0x007c
103
+ .WriteUInt32(_skillId(char.header.left_swap_skill, constants)) //0x0080
104
+ .WriteUInt32(_skillId(char.header.right_swap_skill, constants)) //0x0084
105
+ .WriteArray(_writeCharMenuAppearance(char.header.menu_appearance, constants)) //0x0088 [char menu appearance]
106
+ .WriteArray(_writeDifficulty(char.header.difficulty)) //0x00a8
107
+ .WriteUInt32(char.header.map_id) //0x00ab
108
+ .WriteArray(new Uint8Array([0x00, 0x00])) //0x00af [unk = 0x0, 0x0]
109
+ .WriteUInt16(char.header.dead_merc) //0x00b1
110
+ .WriteUInt32(parseInt(char.header.merc_id, 16)) //0x00b3
111
+ .WriteUInt16(char.header.merc_name_id) //0x00b7
112
+ .WriteUInt16(char.header.merc_type) //0x00b9
113
+ .WriteUInt32(char.header.merc_experience); //0x00bb
114
+ if (char.header.version > 0x61) {
115
+ if (char.header.version === 0x69) {
116
+ writer
117
+ .WriteArray(new Uint8Array(73)) //175
118
+ .WriteArray(new Uint8Array([0x03])) //248
119
+ .WriteArray(new Uint8Array(50)) //248
120
+ .WriteString(char.header.name, 16) //299
121
+ .WriteArray(new Uint8Array(88)); //0x011b [unk]
122
+ }
123
+ else {
124
+ writer
125
+ .WriteArray(new Uint8Array(76)) //0x00bf [unk]
126
+ .WriteString(char.header.name, 16) //0x010b
127
+ .WriteArray(new Uint8Array(52)); //0x011b [unk]
128
+ }
129
+ }
130
+ else {
131
+ writer
132
+ .WriteArray(new Uint8Array(140)) //0x00bf [unk]
133
+ .WriteUInt32(0x1); //0x014b [unk = 0x1, 0x0, 0x0, 0x0]
134
+ }
135
+ writer
136
+ .WriteString("Woo!", 4) //0x014f [quests = 0x57, 0x6f, 0x6f, 0x21 "Woo!"]
137
+ .WriteArray(new Uint8Array([0x06, 0x00, 0x00, 0x00, 0x2a, 0x01])) //0x0153 [unk = 0x6, 0x0, 0x0, 0x0, 0x2a, 0x1]
138
+ .WriteArray(_writeQuests(char.header.quests_normal)) //0x0159
139
+ .WriteArray(_writeQuests(char.header.quests_nm)) //0x01b9
140
+ .WriteArray(_writeQuests(char.header.quests_hell)) //0x0219
141
+ .WriteString("WS", 2) //0x0279 [waypoint data = 0x57, 0x53 "WS"]
142
+ .WriteArray(new Uint8Array([0x01, 0x00, 0x00, 0x00, 0x50, 0x00])) //0x027b [unk = 0x1, 0x0, 0x0, 0x0, 0x50, 0x0]
143
+ .WriteArray(_writeWaypointData(char.header.waypoints)) //0x0281
144
+ .WriteArray(new Uint8Array([0x01, 0x77])) //0x02c9 [npc header = 0x01, 0x77 ".w"]
145
+ .WriteUInt16(0x34) //0x02ca [npc struct length]
146
+ .WriteArray(_writeNPCData(char.header.npcs)); //0x02cc [npc introduction data... unk]
147
+ }
148
+ exports.writeHeader = writeHeader;
149
+ function _classId(name, constants) {
150
+ if (!name)
151
+ return -1;
152
+ return constants.classes.findIndex((c) => c && c.n == name);
153
+ }
154
+ function _skillId(name, constants) {
155
+ //default to "attack" if empty string or can't find spellname.
156
+ if (name === "")
157
+ return 0;
158
+ if (!name)
159
+ return -1;
160
+ const idx = constants.skills.findIndex((s) => s && s.s == name);
161
+ return idx >= 0 ? idx : 0;
162
+ }
163
+ function _readStatus(byte) {
164
+ const status = {};
165
+ status.hardcore = ((byte >>> 2) & 1) === 1;
166
+ status.died = ((byte >>> 3) & 1) === 1;
167
+ status.expansion = ((byte >>> 5) & 1) === 1;
168
+ status.ladder = ((byte >>> 6) & 1) === 1;
169
+ return status;
170
+ }
171
+ function _writeStatus(status) {
172
+ const arr = new Uint8Array(1);
173
+ arr[0] |= status.hardcore ? 1 << 2 : 0;
174
+ arr[0] |= status.died ? 1 << 3 : 0;
175
+ arr[0] |= status.expansion ? 1 << 5 : 0;
176
+ arr[0] |= status.ladder ? 1 << 6 : 0;
177
+ return arr;
178
+ }
179
+ function _readCharMenuAppearance(bytes, constants) {
180
+ const appearance = {};
181
+ const reader = new bitreader_1.BitReader(bytes);
182
+ const graphics = reader.ReadArray(16);
183
+ const tints = reader.ReadArray(16);
184
+ appearance.head = { graphic: graphics[0], tint: tints[0] };
185
+ appearance.torso = { graphic: graphics[1], tint: tints[1] };
186
+ appearance.legs = { graphic: graphics[2], tint: tints[2] };
187
+ appearance.right_arm = { graphic: graphics[3], tint: tints[3] };
188
+ appearance.left_arm = { graphic: graphics[4], tint: tints[4] };
189
+ appearance.right_hand = { graphic: graphics[5], tint: tints[5] };
190
+ appearance.left_hand = { graphic: graphics[6], tint: tints[6] };
191
+ appearance.shield = { graphic: graphics[7], tint: tints[7] };
192
+ appearance.special1 = { graphic: graphics[8], tint: tints[8] };
193
+ appearance.special2 = { graphic: graphics[9], tint: tints[9] };
194
+ appearance.special3 = { graphic: graphics[10], tint: tints[10] };
195
+ appearance.special4 = { graphic: graphics[11], tint: tints[11] };
196
+ appearance.special5 = { graphic: graphics[12], tint: tints[12] };
197
+ appearance.special6 = { graphic: graphics[13], tint: tints[13] };
198
+ appearance.special7 = { graphic: graphics[14], tint: tints[14] };
199
+ appearance.special8 = { graphic: graphics[15], tint: tints[15] };
200
+ return appearance;
201
+ }
202
+ function _writeCharMenuAppearance(appearance, constants) {
203
+ const writer = new bitwriter_1.BitWriter(32);
204
+ writer.length = 32 * 8;
205
+ const graphics = [];
206
+ graphics.push(appearance && appearance.head ? appearance.head.graphic : 0);
207
+ graphics.push(appearance && appearance.torso ? appearance.torso.graphic : 0);
208
+ graphics.push(appearance && appearance.legs ? appearance.legs.graphic : 0);
209
+ graphics.push(appearance && appearance.right_arm ? appearance.right_arm.graphic : 0);
210
+ graphics.push(appearance && appearance.left_arm ? appearance.left_arm.graphic : 0);
211
+ graphics.push(appearance && appearance.right_hand ? appearance.right_hand.graphic : 0);
212
+ graphics.push(appearance && appearance.left_hand ? appearance.left_hand.graphic : 0);
213
+ graphics.push(appearance && appearance.shield ? appearance.shield.graphic : 0);
214
+ graphics.push(appearance && appearance.special1 ? appearance.special1.graphic : 0);
215
+ graphics.push(appearance && appearance.special2 ? appearance.special2.graphic : 0);
216
+ graphics.push(appearance && appearance.special3 ? appearance.special3.graphic : 0);
217
+ graphics.push(appearance && appearance.special4 ? appearance.special4.graphic : 0);
218
+ graphics.push(appearance && appearance.special5 ? appearance.special5.graphic : 0);
219
+ graphics.push(appearance && appearance.special6 ? appearance.special6.graphic : 0);
220
+ graphics.push(appearance && appearance.special7 ? appearance.special7.graphic : 0);
221
+ graphics.push(appearance && appearance.special8 ? appearance.special8.graphic : 0);
222
+ for (const g of graphics) {
223
+ writer.WriteUInt8(g);
224
+ }
225
+ const tints = [];
226
+ tints.push(appearance && appearance.head ? appearance.head.tint : 0);
227
+ tints.push(appearance && appearance.torso ? appearance.torso.tint : 0);
228
+ tints.push(appearance && appearance.legs ? appearance.legs.tint : 0);
229
+ tints.push(appearance && appearance.right_arm ? appearance.right_arm.tint : 0);
230
+ tints.push(appearance && appearance.left_arm ? appearance.left_arm.tint : 0);
231
+ tints.push(appearance && appearance.right_hand ? appearance.right_hand.tint : 0);
232
+ tints.push(appearance && appearance.left_hand ? appearance.left_hand.tint : 0);
233
+ tints.push(appearance && appearance.shield ? appearance.shield.tint : 0);
234
+ tints.push(appearance && appearance.special1 ? appearance.special1.tint : 0);
235
+ tints.push(appearance && appearance.special2 ? appearance.special2.tint : 0);
236
+ tints.push(appearance && appearance.special3 ? appearance.special3.tint : 0);
237
+ tints.push(appearance && appearance.special4 ? appearance.special4.tint : 0);
238
+ tints.push(appearance && appearance.special5 ? appearance.special5.tint : 0);
239
+ tints.push(appearance && appearance.special6 ? appearance.special6.tint : 0);
240
+ tints.push(appearance && appearance.special7 ? appearance.special7.tint : 0);
241
+ tints.push(appearance && appearance.special8 ? appearance.special8.tint : 0);
242
+ for (const t of tints) {
243
+ writer.WriteUInt8(t);
244
+ }
245
+ return writer.ToArray();
246
+ }
247
+ function _readAssignedSkills(bytes, constants) {
248
+ const skills = [];
249
+ const reader = new bitreader_1.BitReader(bytes);
250
+ for (let i = 0; i < 16; i++) {
251
+ const skillId = reader.ReadUInt32();
252
+ const skill = constants.skills[skillId];
253
+ if (skill) {
254
+ skills.push(skill.s);
255
+ }
256
+ }
257
+ return skills;
258
+ }
259
+ function _writeAssignedSkills(skills, constants) {
260
+ const writer = new bitwriter_1.BitWriter(64);
261
+ writer.length = 64 * 8;
262
+ skills = skills || [];
263
+ for (let i = 0; i < 16; i++) {
264
+ const skillId = _skillId(skills[i], constants);
265
+ if (skillId > 0) {
266
+ writer.WriteUInt32(skillId);
267
+ }
268
+ else {
269
+ writer.WriteUInt32(0xffff);
270
+ }
271
+ }
272
+ return writer.ToArray();
273
+ }
274
+ function _readDifficulty(bytes) {
275
+ const difficulty = {};
276
+ difficulty.Normal = bytes[0];
277
+ difficulty.Nightmare = bytes[1];
278
+ difficulty.Hell = bytes[2];
279
+ return difficulty;
280
+ }
281
+ function _writeDifficulty(difficulty) {
282
+ const writer = new bitwriter_1.BitWriter(3);
283
+ writer.length = 3 * 8;
284
+ writer.WriteUInt8(difficulty.Normal);
285
+ writer.WriteUInt8(difficulty.Nightmare);
286
+ writer.WriteUInt8(difficulty.Hell);
287
+ return writer.ToArray();
288
+ }
289
+ function _readQuests(bytes) {
290
+ const quests = {};
291
+ const reader = new bitreader_1.BitReader(bytes);
292
+ quests.act_i = {};
293
+ quests.act_i.introduced = reader.ReadUInt16() === 0x1; //0x0000
294
+ quests.act_i.den_of_evil = _readQuest(reader.ReadArray(2)); //0x0002
295
+ quests.act_i.sisters_burial_grounds = _readQuest(reader.ReadArray(2));
296
+ quests.act_i.tools_of_the_trade = _readQuest(reader.ReadArray(2));
297
+ quests.act_i.the_search_for_cain = _readQuest(reader.ReadArray(2));
298
+ quests.act_i.the_forgotten_tower = _readQuest(reader.ReadArray(2));
299
+ quests.act_i.sisters_to_the_slaughter = _readQuest(reader.ReadArray(2));
300
+ quests.act_i.completed = reader.ReadUInt16() === 0x1;
301
+ quests.act_ii = {};
302
+ quests.act_ii.introduced = reader.ReadUInt16() === 0x1; //0x0010 [if jerhyn introduction = 0x01]
303
+ quests.act_ii.radaments_lair = _readQuest(reader.ReadArray(2)); //0x0012
304
+ quests.act_ii.the_horadric_staff = _readQuest(reader.ReadArray(2));
305
+ quests.act_ii.tainted_sun = _readQuest(reader.ReadArray(2));
306
+ quests.act_ii.arcane_sanctuary = _readQuest(reader.ReadArray(2));
307
+ quests.act_ii.the_summoner = _readQuest(reader.ReadArray(2));
308
+ quests.act_ii.the_seven_tombs = _readQuest(reader.ReadArray(2));
309
+ quests.act_ii.completed = reader.ReadUInt16() === 0x1; //0x001e
310
+ quests.act_iii = {};
311
+ quests.act_iii.introduced = reader.ReadUInt16() === 0x1; //0x0020 [if hratli introduction = 0x01]
312
+ quests.act_iii.lam_esens_tome = _readQuest(reader.ReadArray(2)); //0x0022
313
+ quests.act_iii.khalims_will = _readQuest(reader.ReadArray(2));
314
+ quests.act_iii.blade_of_the_old_religion = _readQuest(reader.ReadArray(2));
315
+ quests.act_iii.the_golden_bird = _readQuest(reader.ReadArray(2));
316
+ quests.act_iii.the_blackened_temple = _readQuest(reader.ReadArray(2));
317
+ quests.act_iii.the_guardian = _readQuest(reader.ReadArray(2));
318
+ quests.act_iii.completed = reader.ReadUInt16() === 0x1; //0x002e
319
+ quests.act_iv = {};
320
+ quests.act_iv.introduced = reader.ReadUInt16() === 0x1; //0x0030 [if activ introduction = 0x01]
321
+ quests.act_iv.the_fallen_angel = _readQuest(reader.ReadArray(2)); //0x0032
322
+ quests.act_iv.terrors_end = _readQuest(reader.ReadArray(2));
323
+ quests.act_iv.hellforge = _readQuest(reader.ReadArray(2));
324
+ quests.act_iv.completed = reader.ReadUInt16() === 0x1; //0x0038
325
+ reader.SkipBytes(10); //0x003a
326
+ quests.act_v = {};
327
+ quests.act_v.introduced = reader.ReadUInt16() === 0x1;
328
+ quests.act_v.siege_on_harrogath = _readQuest(reader.ReadArray(2)); //0x0046
329
+ quests.act_v.rescue_on_mount_arreat = _readQuest(reader.ReadArray(2));
330
+ quests.act_v.prison_of_ice = _readQuest(reader.ReadArray(2));
331
+ quests.act_v.betrayal_of_harrogath = _readQuest(reader.ReadArray(2));
332
+ quests.act_v.rite_of_passage = _readQuest(reader.ReadArray(2));
333
+ quests.act_v.eve_of_destruction = _readQuest(reader.ReadArray(2));
334
+ quests.act_v.completed = reader.ReadUInt16() === 0x1;
335
+ reader.SkipBytes(12);
336
+ return quests; //sizeof [0x0060]
337
+ }
338
+ function _writeQuests(quests) {
339
+ const writer = new bitwriter_1.BitWriter(96);
340
+ writer.length = 96 * 8;
341
+ const difficultyCompleted = +quests.act_v.completed || +quests.act_v.eve_of_destruction.is_completed;
342
+ return writer
343
+ .WriteUInt16(+quests.act_i.introduced)
344
+ .WriteArray(_writeQuest(quests.act_i.den_of_evil))
345
+ .WriteArray(_writeQuest(quests.act_i.sisters_burial_grounds))
346
+ .WriteArray(_writeQuest(quests.act_i.tools_of_the_trade))
347
+ .WriteArray(_writeQuest(quests.act_i.the_search_for_cain))
348
+ .WriteArray(_writeQuest(quests.act_i.the_forgotten_tower))
349
+ .WriteArray(_writeQuest(quests.act_i.sisters_to_the_slaughter))
350
+ .WriteUInt16(+quests.act_i.completed || +quests.act_i.sisters_to_the_slaughter.is_completed)
351
+ .WriteUInt16(+quests.act_ii.introduced || +quests.act_i.sisters_to_the_slaughter.is_completed)
352
+ .WriteArray(_writeQuest(quests.act_ii.radaments_lair))
353
+ .WriteArray(_writeQuest(quests.act_ii.the_horadric_staff))
354
+ .WriteArray(_writeQuest(quests.act_ii.tainted_sun))
355
+ .WriteArray(_writeQuest(quests.act_ii.arcane_sanctuary))
356
+ .WriteArray(_writeQuest(quests.act_ii.the_summoner))
357
+ .WriteArray(_writeQuest(quests.act_ii.the_seven_tombs))
358
+ .WriteUInt16(+quests.act_ii.completed || +quests.act_ii.the_seven_tombs.is_completed)
359
+ .WriteUInt16(+quests.act_iii.introduced || +quests.act_ii.the_seven_tombs.is_completed)
360
+ .WriteArray(_writeQuest(quests.act_iii.lam_esens_tome))
361
+ .WriteArray(_writeQuest(quests.act_iii.khalims_will))
362
+ .WriteArray(_writeQuest(quests.act_iii.blade_of_the_old_religion))
363
+ .WriteArray(_writeQuest(quests.act_iii.the_golden_bird))
364
+ .WriteArray(_writeQuest(quests.act_iii.the_blackened_temple))
365
+ .WriteArray(_writeQuest(quests.act_iii.the_guardian))
366
+ .WriteUInt16(+quests.act_iii.completed || +quests.act_iii.the_guardian.is_completed)
367
+ .WriteUInt16(+quests.act_iv.introduced || +quests.act_iii.the_guardian.is_completed)
368
+ .WriteArray(_writeQuest(quests.act_iv.the_fallen_angel))
369
+ .WriteArray(_writeQuest(quests.act_iv.terrors_end))
370
+ .WriteArray(_writeQuest(quests.act_iv.hellforge))
371
+ .WriteUInt16(+quests.act_iv.completed || +quests.act_iv.terrors_end.is_completed)
372
+ .WriteArray(new Uint8Array(6))
373
+ .WriteUInt16(+quests.act_v.introduced || +quests.act_iv.terrors_end.is_completed)
374
+ .WriteArray(new Uint8Array(4))
375
+ .WriteArray(_writeQuest(quests.act_v.siege_on_harrogath))
376
+ .WriteArray(_writeQuest(quests.act_v.rescue_on_mount_arreat))
377
+ .WriteArray(_writeQuest(quests.act_v.prison_of_ice))
378
+ .WriteArray(_writeQuest(quests.act_v.betrayal_of_harrogath))
379
+ .WriteArray(_writeQuest(quests.act_v.rite_of_passage))
380
+ .WriteArray(_writeQuest(quests.act_v.eve_of_destruction))
381
+ .WriteUInt8(difficultyCompleted)
382
+ .WriteUInt8(difficultyCompleted ? 0x80 : 0x0) //is this right?
383
+ .WriteArray(new Uint8Array(12))
384
+ .ToArray();
385
+ }
386
+ function _readQuest(bytes) {
387
+ const quest = {};
388
+ const reader = new bitreader_1.BitReader(bytes);
389
+ quest.is_completed = reader.ReadBit() === 1;
390
+ quest.is_requirement_completed = reader.ReadBit() === 1;
391
+ quest.is_received = reader.ReadBit() === 1;
392
+ if (reader.ReadBit() === 1)
393
+ quest.unk3 = true;
394
+ if (reader.ReadBit() === 1)
395
+ quest.unk4 = true;
396
+ if (reader.ReadBit() === 1)
397
+ quest.unk5 = true;
398
+ if (reader.ReadBit() === 1)
399
+ quest.unk6 = true;
400
+ if (reader.ReadBit() === 1)
401
+ quest.consumed_scroll = true;
402
+ if (reader.ReadBit() === 1)
403
+ quest.unk8 = true;
404
+ if (reader.ReadBit() === 1)
405
+ quest.unk9 = true;
406
+ if (reader.ReadBit() === 1)
407
+ quest.unk10 = true;
408
+ if (reader.ReadBit() === 1)
409
+ quest.unk11 = true;
410
+ quest.closed = reader.ReadBit() === 1;
411
+ quest.done_recently = reader.ReadBit() === 1;
412
+ if (reader.ReadBit() === 1)
413
+ quest.unk14 = true;
414
+ if (reader.ReadBit() === 1)
415
+ quest.unk15 = true;
416
+ return quest;
417
+ }
418
+ function _writeQuest(quest) {
419
+ const writer = new bitwriter_1.BitWriter(2);
420
+ writer.length = 2 * 8;
421
+ writer.WriteBit(+quest.is_completed);
422
+ writer.WriteBit(+quest.is_requirement_completed);
423
+ writer.WriteBit(+quest.is_received);
424
+ writer.WriteBit(+quest.unk3);
425
+ writer.WriteBit(+quest.unk4);
426
+ writer.WriteBit(+quest.unk5);
427
+ writer.WriteBit(+quest.unk6);
428
+ writer.WriteBit(+quest.consumed_scroll);
429
+ writer.WriteBit(+quest.unk8);
430
+ writer.WriteBit(+quest.unk9);
431
+ writer.WriteBit(+quest.unk10);
432
+ writer.WriteBit(+quest.unk11);
433
+ writer.WriteBit(+quest.closed);
434
+ writer.WriteBit(+quest.done_recently);
435
+ writer.WriteBit(+quest.unk14);
436
+ writer.WriteBit(+quest.unk15);
437
+ return writer.ToArray();
438
+ }
439
+ function _readWaypointData(bytes) {
440
+ const waypoints = {};
441
+ const reader = new bitreader_1.BitReader(bytes);
442
+ for (let i = 0; i < difficulties.length; i++) {
443
+ waypoints[difficulties[i]] = _readWaypoints(reader.ReadArray(24));
444
+ }
445
+ return waypoints;
446
+ }
447
+ function _readWaypoints(bytes) {
448
+ const waypoints = {};
449
+ const reader = new bitreader_1.BitReader(bytes);
450
+ reader.SkipBytes(2); //unk = 0x2, 0x
451
+ waypoints.act_i = {};
452
+ waypoints.act_i.rogue_encampement = reader.ReadBit() === 1;
453
+ waypoints.act_i.cold_plains = reader.ReadBit() === 1;
454
+ waypoints.act_i.stony_field = reader.ReadBit() === 1;
455
+ waypoints.act_i.dark_woods = reader.ReadBit() === 1;
456
+ waypoints.act_i.black_marsh = reader.ReadBit() === 1;
457
+ waypoints.act_i.outer_cloister = reader.ReadBit() === 1;
458
+ waypoints.act_i.jail_lvl_1 = reader.ReadBit() === 1;
459
+ waypoints.act_i.inner_cloister = reader.ReadBit() === 1;
460
+ waypoints.act_i.catacombs_lvl_2 = reader.ReadBit() === 1;
461
+ waypoints.act_ii = {};
462
+ waypoints.act_ii.lut_gholein = reader.ReadBit() === 1;
463
+ waypoints.act_ii.sewers_lvl_2 = reader.ReadBit() === 1;
464
+ waypoints.act_ii.dry_hills = reader.ReadBit() === 1;
465
+ waypoints.act_ii.halls_of_the_dead_lvl_2 = reader.ReadBit() === 1;
466
+ waypoints.act_ii.far_oasis = reader.ReadBit() === 1;
467
+ waypoints.act_ii.lost_city = reader.ReadBit() === 1;
468
+ waypoints.act_ii.palace_cellar_lvl_1 = reader.ReadBit() === 1;
469
+ waypoints.act_ii.arcane_sanctuary = reader.ReadBit() === 1;
470
+ waypoints.act_ii.canyon_of_the_magi = reader.ReadBit() === 1;
471
+ waypoints.act_iii = {};
472
+ waypoints.act_iii.kurast_docks = reader.ReadBit() === 1;
473
+ waypoints.act_iii.spider_forest = reader.ReadBit() === 1;
474
+ waypoints.act_iii.great_marsh = reader.ReadBit() === 1;
475
+ waypoints.act_iii.flayer_jungle = reader.ReadBit() === 1;
476
+ waypoints.act_iii.lower_kurast = reader.ReadBit() === 1;
477
+ waypoints.act_iii.kurast_bazaar = reader.ReadBit() === 1;
478
+ waypoints.act_iii.upper_kurast = reader.ReadBit() === 1;
479
+ waypoints.act_iii.travincal = reader.ReadBit() === 1;
480
+ waypoints.act_iii.durance_of_hate_lvl_2 = reader.ReadBit() === 1;
481
+ waypoints.act_iv = {};
482
+ waypoints.act_iv.the_pandemonium_fortress = reader.ReadBit() === 1;
483
+ waypoints.act_iv.city_of_the_damned = reader.ReadBit() === 1;
484
+ waypoints.act_iv.river_of_flame = reader.ReadBit() === 1;
485
+ waypoints.act_v = {};
486
+ waypoints.act_v.harrogath = reader.ReadBit() === 1;
487
+ waypoints.act_v.frigid_highlands = reader.ReadBit() === 1;
488
+ waypoints.act_v.arreat_plateau = reader.ReadBit() === 1;
489
+ waypoints.act_v.crystalline_passage = reader.ReadBit() === 1;
490
+ waypoints.act_v.glacial_trail = reader.ReadBit() === 1;
491
+ waypoints.act_v.halls_of_pain = reader.ReadBit() === 1;
492
+ waypoints.act_v.frozen_tundra = reader.ReadBit() === 1;
493
+ waypoints.act_v.the_ancients_way = reader.ReadBit() === 1;
494
+ waypoints.act_v.worldstone_keep_lvl_2 = reader.ReadBit() === 1;
495
+ reader.Align().SkipBytes(17);
496
+ return waypoints;
497
+ }
498
+ function _writeWaypointData(waypoints) {
499
+ const writer = new bitwriter_1.BitWriter(72);
500
+ writer.length = 72 * 8;
501
+ for (let i = 0; i < difficulties.length; i++) {
502
+ const w = waypoints != null ? waypoints[difficulties[i]] : null;
503
+ writer.WriteArray(_writeWaypoints(w));
504
+ }
505
+ return writer.ToArray();
506
+ }
507
+ function _writeWaypoints(waypoints) {
508
+ const writer = new bitwriter_1.BitWriter(24);
509
+ writer.length = 24 * 8;
510
+ writer.WriteArray(new Uint8Array([0x02, 0x01]));
511
+ if (waypoints) {
512
+ if (waypoints.act_i) {
513
+ writer.WriteBit(+waypoints.act_i.rogue_encampement);
514
+ writer.WriteBit(+waypoints.act_i.cold_plains);
515
+ writer.WriteBit(+waypoints.act_i.stony_field);
516
+ writer.WriteBit(+waypoints.act_i.dark_woods);
517
+ writer.WriteBit(+waypoints.act_i.black_marsh);
518
+ writer.WriteBit(+waypoints.act_i.outer_cloister);
519
+ writer.WriteBit(+waypoints.act_i.jail_lvl_1);
520
+ writer.WriteBit(+waypoints.act_i.inner_cloister);
521
+ writer.WriteBit(+waypoints.act_i.catacombs_lvl_2);
522
+ }
523
+ if (waypoints.act_ii) {
524
+ writer.WriteBit(+waypoints.act_ii.lut_gholein);
525
+ writer.WriteBit(+waypoints.act_ii.sewers_lvl_2);
526
+ writer.WriteBit(+waypoints.act_ii.dry_hills);
527
+ writer.WriteBit(+waypoints.act_ii.halls_of_the_dead_lvl_2);
528
+ writer.WriteBit(+waypoints.act_ii.far_oasis);
529
+ writer.WriteBit(+waypoints.act_ii.lost_city);
530
+ writer.WriteBit(+waypoints.act_ii.palace_cellar_lvl_1);
531
+ writer.WriteBit(+waypoints.act_ii.arcane_sanctuary);
532
+ writer.WriteBit(+waypoints.act_ii.canyon_of_the_magi);
533
+ }
534
+ if (waypoints.act_iii) {
535
+ writer.WriteBit(+waypoints.act_iii.kurast_docks);
536
+ writer.WriteBit(+waypoints.act_iii.spider_forest);
537
+ writer.WriteBit(+waypoints.act_iii.great_marsh);
538
+ writer.WriteBit(+waypoints.act_iii.flayer_jungle);
539
+ writer.WriteBit(+waypoints.act_iii.lower_kurast);
540
+ writer.WriteBit(+waypoints.act_iii.kurast_bazaar);
541
+ writer.WriteBit(+waypoints.act_iii.upper_kurast);
542
+ writer.WriteBit(+waypoints.act_iii.travincal);
543
+ writer.WriteBit(+waypoints.act_iii.durance_of_hate_lvl_2);
544
+ }
545
+ if (waypoints.act_iv) {
546
+ writer.WriteBit(+waypoints.act_iv.the_pandemonium_fortress);
547
+ writer.WriteBit(+waypoints.act_iv.city_of_the_damned);
548
+ writer.WriteBit(+waypoints.act_iv.river_of_flame);
549
+ }
550
+ if (waypoints.act_v) {
551
+ writer.WriteBit(+waypoints.act_v.harrogath);
552
+ writer.WriteBit(+waypoints.act_v.frigid_highlands);
553
+ writer.WriteBit(+waypoints.act_v.arreat_plateau);
554
+ writer.WriteBit(+waypoints.act_v.crystalline_passage);
555
+ writer.WriteBit(+waypoints.act_v.glacial_trail);
556
+ writer.WriteBit(+waypoints.act_v.halls_of_pain);
557
+ writer.WriteBit(+waypoints.act_v.frozen_tundra);
558
+ writer.WriteBit(+waypoints.act_v.the_ancients_way);
559
+ writer.WriteBit(+waypoints.act_v.worldstone_keep_lvl_2);
560
+ }
561
+ }
562
+ else {
563
+ //all wps
564
+ //writer.WriteArray(new Uint8Array(5));
565
+ writer.WriteArray(new Uint8Array([0xff, 0xff, 0xff, 0xff, 0x7f]));
566
+ //_writeBits(writer, 0x3fffffffff, start, 0, 38);
567
+ }
568
+ writer.Align().WriteArray(new Uint8Array(17));
569
+ return writer.ToArray();
570
+ }
571
+ function _readNPCData(bytes) {
572
+ const npcs = { normal: {}, nm: {}, hell: {} };
573
+ const reader = new bitreader_1.BitReader(bytes);
574
+ for (let j = 0; j < 3; j++) {
575
+ npcs[difficulties[j]] = {
576
+ warriv_act_ii: { intro: false, congrats: false },
577
+ charsi: { intro: false, congrats: false },
578
+ warriv_act_i: { intro: false, congrats: false },
579
+ kashya: { intro: false, congrats: false },
580
+ akara: { intro: false, congrats: false },
581
+ gheed: { intro: false, congrats: false },
582
+ greiz: { intro: false, congrats: false },
583
+ jerhyn: { intro: false, congrats: false },
584
+ meshif_act_ii: { intro: false, congrats: false },
585
+ geglash: { intro: false, congrats: false },
586
+ lysnader: { intro: false, congrats: false },
587
+ fara: { intro: false, congrats: false },
588
+ drogan: { intro: false, congrats: false },
589
+ alkor: { intro: false, congrats: false },
590
+ hratli: { intro: false, congrats: false },
591
+ ashera: { intro: false, congrats: false },
592
+ cain_act_iii: { intro: false, congrats: false },
593
+ elzix: { intro: false, congrats: false },
594
+ malah: { intro: false, congrats: false },
595
+ anya: { intro: false, congrats: false },
596
+ natalya: { intro: false, congrats: false },
597
+ meshif_act_iii: { intro: false, congrats: false },
598
+ ormus: { intro: false, congrats: false },
599
+ cain_act_v: { intro: false, congrats: false },
600
+ qualkehk: { intro: false, congrats: false },
601
+ nihlathak: { intro: false, congrats: false },
602
+ };
603
+ }
604
+ //introductions
605
+ for (let i = 0; i < 3; i++) {
606
+ const j = i * 5;
607
+ const npc = npcs[difficulties[i]];
608
+ npc.warriv_act_ii.intro = reader.bits[0 + j * 8] === 1;
609
+ npc.charsi.intro = reader.bits[2 + j * 8] === 1;
610
+ npc.warriv_act_i.intro = reader.bits[3 + j * 8] === 1;
611
+ npc.kashya.intro = reader.bits[4 + j * 8] === 1;
612
+ npc.akara.intro = reader.bits[5 + j * 8] === 1;
613
+ npc.gheed.intro = reader.bits[6 + j * 8] === 1;
614
+ npc.greiz.intro = reader.bits[8 + j * 8] === 1;
615
+ npc.jerhyn.intro = reader.bits[9 + j * 8] === 1;
616
+ npc.meshif_act_ii.intro = reader.bits[10 + j * 8] === 1;
617
+ npc.geglash.intro = reader.bits[11 + j * 8] === 1;
618
+ npc.lysnader.intro = reader.bits[12 + j * 8] === 1;
619
+ npc.fara.intro = reader.bits[13 + j * 8] === 1;
620
+ npc.drogan.intro = reader.bits[14 + j * 8] === 1;
621
+ npc.alkor.intro = reader.bits[16 + j * 8] === 1;
622
+ npc.hratli.intro = reader.bits[17 + j * 8] === 1;
623
+ npc.ashera.intro = reader.bits[18 + j * 8] === 1;
624
+ npc.cain_act_iii.intro = reader.bits[21 + j * 8] === 1;
625
+ npc.elzix.intro = reader.bits[23 + j * 8] === 1;
626
+ npc.malah.intro = reader.bits[24 + j * 8] === 1;
627
+ npc.anya.intro = reader.bits[25 + j * 8] === 1;
628
+ npc.natalya.intro = reader.bits[27 + j * 8] === 1;
629
+ npc.meshif_act_iii.intro = reader.bits[28 + j * 8] === 1;
630
+ npc.ormus.intro = reader.bits[31 + j * 8] === 1;
631
+ npc.cain_act_v.intro = reader.bits[37 + j * 8] === 1;
632
+ npc.qualkehk.intro = reader.bits[38 + j * 8] === 1;
633
+ npc.nihlathak.intro = reader.bits[39 + j * 8] === 1;
634
+ }
635
+ //congrats
636
+ for (let i = 0; i < 3; i++) {
637
+ const j = i * 5;
638
+ const npc = npcs[difficulties[i]];
639
+ npc.warriv_act_ii.congrats = reader.bits[192 + (0 + j * 8)] === 1;
640
+ npc.charsi.congrats = reader.bits[192 + (2 + j * 8)] === 1;
641
+ npc.warriv_act_i.congrats = reader.bits[192 + (3 + j * 8)] === 1;
642
+ npc.kashya.congrats = reader.bits[192 + (4 + j * 8)] === 1;
643
+ npc.akara.congrats = reader.bits[192 + (5 + j * 8)] === 1;
644
+ npc.gheed.congrats = reader.bits[192 + (6 + j * 8)] === 1;
645
+ npc.greiz.congrats = reader.bits[192 + (8 + j * 8)] === 1;
646
+ npc.jerhyn.congrats = reader.bits[192 + (9 + j * 8)] === 1;
647
+ npc.meshif_act_ii.congrats = reader.bits[192 + (10 + j * 8)] === 1;
648
+ npc.geglash.congrats = reader.bits[192 + (11 + j * 8)] === 1;
649
+ npc.lysnader.congrats = reader.bits[192 + (12 + j * 8)] === 1;
650
+ npc.fara.congrats = reader.bits[192 + (13 + j * 8)] === 1;
651
+ npc.drogan.congrats = reader.bits[192 + (14 + j * 8)] === 1;
652
+ npc.alkor.congrats = reader.bits[192 + (16 + j * 8)] === 1;
653
+ npc.hratli.congrats = reader.bits[192 + (17 + j * 8)] === 1;
654
+ npc.ashera.congrats = reader.bits[192 + (18 + j * 8)] === 1;
655
+ npc.cain_act_iii.congrats = reader.bits[192 + (21 + j * 8)] === 1;
656
+ npc.elzix.congrats = reader.bits[192 + (23 + j * 8)] === 1;
657
+ npc.malah.congrats = reader.bits[192 + (24 + j * 8)] === 1;
658
+ npc.anya.congrats = reader.bits[192 + (25 + j * 8)] === 1;
659
+ npc.natalya.congrats = reader.bits[192 + (27 + j * 8)] === 1;
660
+ npc.meshif_act_iii.congrats = reader.bits[192 + (28 + j * 8)] === 1;
661
+ npc.ormus.congrats = reader.bits[192 + (31 + j * 8)] === 1;
662
+ npc.cain_act_v.congrats = reader.bits[192 + (37 + j * 8)] === 1;
663
+ npc.qualkehk.congrats = reader.bits[192 + (38 + j * 8)] === 1;
664
+ npc.nihlathak.congrats = reader.bits[192 + (39 + j * 8)] === 1;
665
+ }
666
+ return npcs;
667
+ }
668
+ function _writeNPCData(npcs) {
669
+ const writer = new bitwriter_1.BitWriter(0x30);
670
+ writer.length = 0x30 * 8;
671
+ if (npcs) {
672
+ for (let j = 0; j < 3; j++) {
673
+ const npc = npcs[difficulties[j]];
674
+ writer.SeekByte(j * 5);
675
+ writer.WriteBit(+npc.warriv_act_ii.intro);
676
+ writer.WriteBit(0);
677
+ writer.WriteBit(+npc.charsi.intro);
678
+ writer.WriteBit(+npc.warriv_act_i.intro);
679
+ writer.WriteBit(+npc.kashya.intro);
680
+ writer.WriteBit(+npc.akara.intro);
681
+ writer.WriteBit(+npc.gheed.intro);
682
+ writer.WriteBit(0);
683
+ writer.WriteBit(+npc.greiz.intro);
684
+ writer.WriteBit(+npc.jerhyn.intro);
685
+ writer.WriteBit(+npc.meshif_act_ii.intro);
686
+ writer.WriteBit(+npc.geglash.intro);
687
+ writer.WriteBit(+npc.lysnader.intro);
688
+ writer.WriteBit(+npc.fara.intro);
689
+ writer.WriteBit(+npc.drogan.intro);
690
+ writer.WriteBit(0);
691
+ writer.WriteBit(+npc.alkor.intro);
692
+ writer.WriteBit(+npc.hratli.intro);
693
+ writer.WriteBit(+npc.ashera.intro);
694
+ writer.WriteBits(new Uint8Array(2).fill(0), 2);
695
+ writer.WriteBit(+npc.cain_act_iii.intro);
696
+ writer.WriteBit(0);
697
+ writer.WriteBit(+npc.elzix.intro);
698
+ writer.WriteBit(+npc.malah.intro);
699
+ writer.WriteBit(+npc.anya.intro);
700
+ writer.WriteBit(0);
701
+ writer.WriteBit(+npc.natalya.intro);
702
+ writer.WriteBit(+npc.meshif_act_iii.intro);
703
+ writer.WriteBits(new Uint8Array(2).fill(0), 2);
704
+ writer.WriteBit(+npc.ormus.intro);
705
+ writer.WriteBits(new Uint8Array(5).fill(0), 5);
706
+ writer.WriteBit(+npc.cain_act_v.intro);
707
+ writer.WriteBit(+npc.qualkehk.intro);
708
+ writer.WriteBit(+npc.nihlathak.intro);
709
+ }
710
+ for (let j = 0; j < 3; j++) {
711
+ writer.SeekByte(24 + j * 5);
712
+ const npc = npcs[difficulties[j]];
713
+ writer.WriteBit(+npc.warriv_act_ii.congrats);
714
+ writer.WriteBit(0);
715
+ writer.WriteBit(+npc.charsi.congrats);
716
+ writer.WriteBit(+npc.warriv_act_i.congrats);
717
+ writer.WriteBit(+npc.kashya.congrats);
718
+ writer.WriteBit(+npc.akara.congrats);
719
+ writer.WriteBit(+npc.gheed.congrats);
720
+ writer.WriteBit(0);
721
+ writer.WriteBit(+npc.greiz.congrats);
722
+ writer.WriteBit(+npc.jerhyn.congrats);
723
+ writer.WriteBit(+npc.meshif_act_ii.congrats);
724
+ writer.WriteBit(+npc.geglash.congrats);
725
+ writer.WriteBit(+npc.lysnader.congrats);
726
+ writer.WriteBit(+npc.fara.congrats);
727
+ writer.WriteBit(+npc.drogan.congrats);
728
+ writer.WriteBit(0);
729
+ writer.WriteBit(+npc.alkor.congrats);
730
+ writer.WriteBit(+npc.hratli.congrats);
731
+ writer.WriteBit(+npc.ashera.congrats);
732
+ writer.WriteBits(new Uint8Array(2).fill(0), 2);
733
+ writer.WriteBit(+npc.cain_act_iii.congrats);
734
+ writer.WriteBit(0);
735
+ writer.WriteBit(+npc.elzix.congrats);
736
+ writer.WriteBit(+npc.malah.congrats);
737
+ writer.WriteBit(+npc.anya.congrats);
738
+ writer.WriteBit(0);
739
+ writer.WriteBit(+npc.natalya.congrats);
740
+ writer.WriteBit(+npc.meshif_act_iii.congrats);
741
+ writer.WriteBits(new Uint8Array(2).fill(0), 2);
742
+ writer.WriteBit(+npc.ormus.congrats);
743
+ writer.WriteBits(new Uint8Array(5).fill(0), 5);
744
+ writer.WriteBit(+npc.cain_act_v.congrats);
745
+ writer.WriteBit(+npc.qualkehk.congrats);
746
+ writer.WriteBit(+npc.nihlathak.congrats);
747
+ }
748
+ }
749
+ return writer.ToArray();
750
+ }
751
751
  //# sourceMappingURL=default_header.js.map