Skip to content

Commit d28374e

Browse files
committed
fixing 2.5 patch again, there was some incorrect logic from patch 2.4 fixes
1 parent 728e086 commit d28374e

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed
2.7 KB
Binary file not shown.

src/d2/items.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ export async function readItem(
250250
if (item.personalized) {
251251
const arr = new Uint8Array(16);
252252
for (let i = 0; i < arr.length; i++) {
253-
if (version == 0x62) {
253+
if (version > 0x61) {
254254
arr[i] = reader.ReadUInt8(8);
255255
} else {
256256
arr[i] = reader.ReadUInt8(7);
@@ -415,13 +415,13 @@ export async function writeItem(
415415
if (item.personalized) {
416416
const name = item.personalized_name.substring(0, 16);
417417
for (let i = 0; i < name.length; i++) {
418-
if (version == 0x62) {
418+
if (version > 0x61) {
419419
writer.WriteUInt8(name.charCodeAt(i), 8);
420420
} else {
421421
writer.WriteUInt8(name.charCodeAt(i) & 0x7f, 7);
422422
}
423423
}
424-
writer.WriteUInt8(0x00, version == 0x62 ? 8 : 7);
424+
writer.WriteUInt8(0x00, version > 0x61 ? 8 : 7);
425425
}
426426

427427
if (item.type === "tbk") {

src/d2/stash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export async function write(
122122
): Promise<Uint8Array> {
123123
const config = Object.assign(defaultConfig, userConfig);
124124
const writer = new BitWriter();
125-
if (version == 0x62) {
125+
if (version > 0x61) {
126126
for (const page of data.pages) {
127127
writer.WriteArray(await writeStashSection(data, page, constants, config));
128128
}

src/d2/versions/default_header.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ export function readHeader(char: types.ID2S, reader: BitReader, constants: types
88
char.header.filesize = reader.ReadUInt32(); //0x0008
99
char.header.checksum = reader.ReadUInt32().toString(16).padStart(8, "0"); //0x000c
1010
reader.SkipBytes(4); //0x0010
11-
if (char.header.version == 0x62) {
11+
if (char.header.version > 0x61) {
1212
reader.SeekByte(267);
1313
}
1414
char.header.name = reader.ReadString(16).replace(/\0/g, ""); //0x0014
15-
if (char.header.version == 0x62) {
15+
if (char.header.version > 0x61) {
1616
reader.SeekByte(36);
1717
}
1818
char.header.status = _readStatus(reader.ReadUInt8()); //0x0024
@@ -59,7 +59,7 @@ export function writeHeader(char: types.ID2S, writer: BitWriter, constants: type
5959
.WriteUInt32(0x0) //0x0008 (filesize. needs to be writen after all data)
6060
.WriteUInt32(0x0); //0x000c (checksum. needs to be calculated after all data writer)
6161

62-
if (char.header.version == 0x62) {
62+
if (char.header.version > 0x61) {
6363
writer.WriteArray(new Uint8Array(Array(20).fill(0))); // 0x0010
6464
} else {
6565
writer
@@ -92,7 +92,7 @@ export function writeHeader(char: types.ID2S, writer: BitWriter, constants: type
9292
.WriteUInt16(char.header.merc_type) //0x00b9
9393
.WriteUInt32(char.header.merc_experience); //0x00bb
9494

95-
if (char.header.version == 0x62) {
95+
if (char.header.version > 0x61) {
9696
writer
9797
.WriteArray(new Uint8Array(76)) //0x00bf [unk]
9898
.WriteString(char.header.name, 16) //0x010b

tests/d2/stash.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ describe("stash", () => {
2222
expect(buffer.compare(savedBytes)).to.eq(0);
2323
});
2424

25+
it("should read D2R shared stash file, with version autodetection", async () => {
26+
const buffer = fs.readFileSync(path.join(__dirname, `../../examples/stash/SharedStashSoftCoreV2_0x63.d2i`));
27+
const jsonData = await read(buffer, constants, null);
28+
const savedBytes = await write(jsonData, constants, 0x62);
29+
const savedJsonData = await read(savedBytes, constants, null);
30+
jsonData.version = '';
31+
savedJsonData.version = '';
32+
expect(jsonData).to.deep.eq(savedJsonData);
33+
});
34+
2535
it("should read plugy shared stash file", async () => {
2636
const buffer = fs.readFileSync(path.join(__dirname, `../../examples/stash/_LOD_SharedStashSave.sss`));
2737
const jsonData = await read(buffer, constants, 0x60);

0 commit comments

Comments
 (0)