Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/d2/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ export async function readItem(
item.current_durability = reader.ReadUInt16(constants.magical_properties[72].sB) - constants.magical_properties[72].sA;
}
}
if (version === 105) {
reader.SkipBits(1);
}

if (constants.stackables[item.type]) {
item.quantity = reader.ReadUInt16(9);
Expand Down Expand Up @@ -323,6 +326,9 @@ export async function readItem(
}
}
}
if (version === 105 && reader.ReadBit()) {
reader.SkipBits(8);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Diablo II save files at version 105, item quantity is being silently discarded (SkipBits(8)) instead of parsed. This causes quantity data to be lost when reading stackable items (materials, gems, runes, etc.) from v105 saves. The following change fixes this issue and correctly parses quantities in the new stash tabs in Diablo 2: Reign of the Warlock

Suggested change
reader.SkipBits(8);
item.quantity = reader.ReadUInt8(8)

}
reader.Align();

if (item.nr_of_items_in_sockets > 0 && item.simple_item === 0) {
Expand All @@ -331,7 +337,7 @@ export async function readItem(
item.socketed_items.push(await readItem(reader, version, constants, config, item));
}
}
//console.log(JSON.stringify(item));

return item;
}

Expand Down Expand Up @@ -549,9 +555,9 @@ function _readSimpleBits(item: types.IItem, reader: BitReader, version: number,
item.type = item.type.trim().replace(/\0/g, "");
let details = _GetItemTXT(item, constants);
item.categories = details?.c;
if (item?.categories.includes("Any Armor")) {
if (item?.categories?.includes("Any Armor")) {
item.type_id = ItemType.Armor;
} else if (item?.categories.includes("Weapon")) {
} else if (item?.categories?.includes("Weapon")) {
item.type_id = ItemType.Weapon;
details = constants.weapon_items[item.type];
} else {
Expand Down
15 changes: 14 additions & 1 deletion src/d2/versions/default_header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ export function readHeader(char: types.ID2S, reader: BitReader, constants: types
if (char.header.version > 0x61) {
reader.SeekByte(267);
}
if (char.header.version > 0x63) {
reader.SeekByte(299);
}
char.header.name = reader.ReadString(16).replace(/\0/g, ""); //0x0014
if (char.header.version > 0x61) {
reader.SeekByte(36);
}
if (char.header.version > 0x63) {
reader.SeekByte(20);
}

char.header.status = _readStatus(reader.ReadUInt8()); //0x0024
char.header.progression = reader.ReadUInt8(); //0x0025
char.header.active_arms = reader.ReadUInt16(); //0x0026 [unk = 0x0, 0x0]
Expand All @@ -38,13 +45,19 @@ export function readHeader(char: types.ID2S, reader: BitReader, constants: types
char.header.merc_name_id = reader.ReadUInt16(); //0x00b7
char.header.merc_type = reader.ReadUInt16(); //0x00b9
char.header.merc_experience = reader.ReadUInt32(); //0x00bb
reader.SkipBytes(144); //0x00bf [unk]
if (char.header.version == 0x69) {
reader.SkipBytes(228);
} else if (char.header.version > 0x61) {
reader.SkipBytes(144);
}

reader.SkipBytes(4); //0x014f [quests header identifier = 0x57, 0x6f, 0x6f, 0x21 "Woo!"]
reader.SkipBytes(4); //0x0153 [version = 0x6, 0x0, 0x0, 0x0]
reader.SkipBytes(2); //0x0153 [quests header length = 0x2a, 0x1]
char.header.quests_normal = _readQuests(reader.ReadArray(96)); //0x0159
char.header.quests_nm = _readQuests(reader.ReadArray(96)); //0x01b9
char.header.quests_hell = _readQuests(reader.ReadArray(96)); //0x0219

reader.SkipBytes(2); //0x0279 [waypoint header identifier = 0x57, 0x53 "WS"]
reader.SkipBytes(4); //0x027b [waypoint header version = 0x1, 0x0, 0x0, 0x0]
reader.SkipBytes(2); //0x027f [waypoint header length = 0x50, 0x0]
Expand Down
Loading