Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix conflicts naming for export stash #49

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
1 change: 0 additions & 1 deletion src/d2/attributes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as types from "./types";
import { BitReader } from "../binary/bitreader";
import { BitWriter } from "../binary/bitwriter";
import { read } from "./stash";

//todo use constants.magical_properties and csvBits
export async function readAttributes(char: types.ID2S, reader: BitReader, constants: types.IConstantData) {
Expand Down
4 changes: 2 additions & 2 deletions src/d2/stash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const defaultConfig = {
extendedStash: false,
} as types.IConfig;

export async function read(
export async function readStash(
buffer: Uint8Array,
constants: types.IConstantData,
version: number,
Expand Down Expand Up @@ -114,7 +114,7 @@ async function readStashPart(stash: types.IStash, reader: BitReader, version: nu
stash.pages.push(page);
}

export async function write(
export async function writeStash(
data: types.IStash,
constants: types.IConstantData,
version: number,
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ export { readSkills, writeSkills } from "./d2/skills";
export { enhanceAttributes, enhanceItems, enhancePlayerAttributes } from "./d2/attribute_enhancer";
export * from "./data/parser";
export * as types from "./d2/types";

export * from "./d2/stash";
24 changes: 12 additions & 12 deletions tests/d2/stash.spec.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { expect, should } from "chai";
import { read, write } from "../../src/d2/stash";
import { readStash, writeStash } from "../../src/d2/stash";
import { constants } from "../../src/data/versions/96_constant_data";
import * as path from "path";
import * as fs from "fs";

describe("stash", () => {
it("should read D2R shared stash file", async () => {
const buffer = fs.readFileSync(path.join(__dirname, `../../examples/stash/SharedStashSoftCoreV2.d2i`));
const jsonData = await read(buffer, constants, 0x62);
const jsonData = await readStash(buffer, constants, 0x62);
expect(jsonData.pageCount, "pageCount").to.eq(3);
expect(jsonData.sharedGold, "sharedGold").to.eq(2500000);
expect(jsonData.version, "version").to.eq("98");
});

it("should write D2R shared stash file", async () => {
const buffer = fs.readFileSync(path.join(__dirname, `../../examples/stash/SharedStashSoftCoreV2.d2i`));
const jsonData = await read(buffer, constants, 0x62);
const jsonData = await readStash(buffer, constants, 0x62);

const savedBytes = await write(jsonData, constants, 0x62);
const savedBytes = await writeStash(jsonData, constants, 0x62);

expect(buffer.compare(savedBytes)).to.eq(0);
});

it("should read plugy shared stash file", async () => {
const buffer = fs.readFileSync(path.join(__dirname, `../../examples/stash/_LOD_SharedStashSave.sss`));
const jsonData = await read(buffer, constants, 0x60);
const jsonData = await readStash(buffer, constants, 0x60);

expect(jsonData.pageCount, "pageCount").to.eq(145);
expect(jsonData.sharedGold, "sharedGold").to.eq(5912844);
Expand All @@ -33,27 +33,27 @@ describe("stash", () => {

it("should provide read and write consistency for plugy shared stash file", async () => {
const buffer = fs.readFileSync(path.join(__dirname, `../../examples/stash/_LOD_SharedStashSave.sss`));
const jsonData = await read(buffer, constants, 0x60);
const newBuffer = await write(jsonData, constants, 0x60);
const newJson = await read(newBuffer, constants, 0x60);
const jsonData = await readStash(buffer, constants, 0x60);
const newBuffer = await writeStash(jsonData, constants, 0x60);
const newJson = await readStash(newBuffer, constants, 0x60);

expect(buffer.length, "file size").to.eq(newBuffer.length);
expect(newJson, "json").to.deep.eq(jsonData);
});

it("should read plugy private stash file", async () => {
const buffer = fs.readFileSync(path.join(__dirname, `../../examples/stash/PrivateStash.d2x`));
const jsonData = await read(buffer, constants, 0x60);
const jsonData = await readStash(buffer, constants, 0x60);
expect(jsonData.pageCount, "pageCount").to.eq(56);
expect(jsonData.sharedGold, "sharedGold").to.eq(0);
expect(jsonData.version, "version").to.eq("01");
});

it("should provide read and write consistency for plugy private stash file", async () => {
const buffer = fs.readFileSync(path.join(__dirname, `../../examples/stash/PrivateStash.d2x`));
const jsonData = await read(buffer, constants, 0x60);
const newBuffer = await write(jsonData, constants, 0x60);
const newJson = await read(newBuffer, constants, 0x60);
const jsonData = await readStash(buffer, constants, 0x60);
const newBuffer = await writeStash(jsonData, constants, 0x60);
const newJson = await readStash(newBuffer, constants, 0x60);

expect(buffer.length, "file size").to.eq(newBuffer.length);
expect(newJson, "json").to.deep.eq(jsonData);
Expand Down