Skip to content

Commit 6ce377d

Browse files
author
Danny Schumacher
committed
Initial Commit
0 parents  commit 6ce377d

34 files changed

+17959
-0
lines changed

.github/workflows/release.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Build, Test, Release
2+
3+
on:
4+
push:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
os: [windows-latest]
14+
node-version: [10.x]
15+
steps:
16+
- name: checkout
17+
uses: actions/checkout@v1
18+
- name: setup nodejs
19+
uses: actions/setup-node@v1
20+
with:
21+
node-version: ${{ matrix.node-version }}
22+
- name: install, build, test
23+
run: |
24+
npm install
25+
npm run build --if-present
26+
npm run web
27+
npm run test
28+
- name: publish github release
29+
uses: softprops/action-gh-release@v1
30+
with:
31+
files: dist/**
32+
env:
33+
GITHUB_TOKEN: ${{ github.token }}

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist
2+
lib
3+
node_modules
4+
.npmrc

.vscode/launch.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"type": "node",
6+
"request": "launch",
7+
"name": "Mocha Tests",
8+
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
9+
"args": [
10+
"-r",
11+
"ts-node/register",
12+
"--timeout",
13+
"999999",
14+
"--colors",
15+
"${workspaceFolder}/tests/**/*.spec.ts"
16+
],
17+
"internalConsoleOptions": "openOnSessionStart"
18+
}
19+
]
20+
}

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
### d2s
2+
3+
![](https://github.com/dschu012/d2s/workflows/.github/workflows/release.yml/badge.svg)
4+
5+
The goal of this project is to create an es6 compliant reader/writer of Diablo II save files. Additionally, the library should be able to consume files generated by nokka's Go implementation [d2s](https://github.com/nokka/d2s), therefore the output of reading a save will closely mirror the Go's output.
6+
7+
##### Examples
8+
* https://dschu012.github.io/d2s/ [[Source](docs/index.html)]
9+
10+
Using [d2s-ui](https://github.com/dschu012/d2s-ui) for a frontend:
11+
* https://diablo.dannyschumacher.com/#/
12+
* https://resurgence.dannyschumacher.com/#/
13+
14+
##### API/General Usage
15+
16+
```typescript
17+
/**
18+
* @see constants.bundle.min.js for an already parsed version of 1.13c data
19+
* @param buffers: object of ALL txt files. example: {
20+
* "ItemStatCost.txt": "Stat\tIDt\Send...",
21+
* "string.txt": "WarrivAct1IntroGossip1\t45}Greetings,...",
22+
* ...
23+
* }
24+
* @return constants: constant data required for parsing built from the txt files.
25+
**/
26+
function readConstantData(buffers: any): types.IConstantData
27+
28+
/**
29+
* @param buffer: Uint8Array representation of the file
30+
* @param constants: constant data used for reading the files. @see readConstantData or constants.bundle.min.js
31+
* @param userConfig: optional configuration. used for if there is a dll edit to allow larger stash sizes. example: {
32+
* extendedStash: true
33+
* }
34+
* @return d2s: the parsed save information
35+
**/
36+
function read(buffer: Uint8Array, constants: types.IConstantData, userConfig?: types.IConfig): Promise<types.ID2S>;
37+
38+
/**
39+
* @param d2s: the parsed save information
40+
* @param constants: constant data used for reading the files. @see readConstantData or constants.bundle.min.js
41+
* @param userConfig: optional configuration. used for if there is a dll edit to allow larger stash sizes. example: {
42+
* extendedStash: true
43+
* }
44+
* @return buffer: Uint8Array representation of the file
45+
**/
46+
function write(data: types.ID2S, constants: types.IConstantData, userConfig?: types.IConfig): Promise<Uint8Array>;
47+
```
48+
49+
##### Useful Links:
50+
* https://github.com/nokka/d2s
51+
* https://github.com/krisives/d2s-format
52+
* http://paul.siramy.free.fr/d2ref/eng/
53+
* http://user.xmission.com/~trevin/DiabloIIv1.09_File_Format.shtml
54+
* https://github.com/nickshanks/Alkor
55+
* https://github.com/HarpyWar/d2s-character-editor

docs/index.html

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
5+
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
6+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/6.3.0/jsoneditor.min.css"
7+
integrity="sha256-YSy983pvDw/pNyv/+uiHXKNh1LlveOgHY6XAXFclM/Y=" crossorigin="anonymous" />
8+
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
9+
rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
10+
<style>
11+
#d2sJson .jsoneditor {
12+
border: 0;
13+
}
14+
</style>
15+
<title>d2s - Example</title>
16+
</head>
17+
<body>
18+
<nav class="navbar navbar-expand-lg navbar-light bg-light">
19+
<div class="octicon octicon-clippy navbar-brand">
20+
<i class="fa fa-fw fa-github"></i>
21+
<a href="https://github.com/dschu012">dschu012</a> / <a class="font-weight-bold" href="https://github.com/dschu012/d2s">d2s</a>
22+
</div>
23+
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
24+
<span class="navbar-toggler-icon"></span>
25+
</button>
26+
<div class="collapse navbar-collapse" id="navbarSupportedContent">
27+
<ul class="navbar-nav">
28+
<li class="nav-item active">
29+
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
30+
</li>
31+
</ul>
32+
</div>
33+
</nav>
34+
<div class="container-fluid">
35+
<div class="row">
36+
<div class="col-2 d-none d-md-block"></div>
37+
<div class="col-8 mt-2">
38+
<div class="card bg-light">
39+
<div class="card-body">
40+
<form id="d2sForm">
41+
<fieldset>
42+
<div class="form-group">
43+
<div class="input-group">
44+
<div class="custom-file">
45+
<input type="file" name="d2sFile" id="d2sFile">
46+
<label class="custom-file-label" for="d2sFile">*.d2s</label>
47+
</div>
48+
<div class="input-group-append">
49+
<span>&nbsp;</span>
50+
</div>
51+
</div>
52+
</div>
53+
<div class="form-group mt-2">
54+
<div id="d2sJson"></div>
55+
</div>
56+
</fieldset>
57+
<div id="errors">
58+
</div>
59+
<button type="submit" class="btn btn-primary">Save</button>
60+
</form>
61+
</div>
62+
</div>
63+
</div>
64+
</div>
65+
</div>
66+
67+
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
68+
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
69+
crossorigin="anonymous"></script>
70+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/6.3.0/jsoneditor.min.js"
71+
integrity="sha256-o2/L37SBn4ufKxtZAItcvBdidVsP170IKNcqfVd3ZF4="
72+
crossorigin="anonymous"></script>
73+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
74+
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
75+
crossorigin="anonymous"></script>
76+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
77+
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
78+
crossorigin="anonymous"></script>
79+
<script src="../dist/constants.bundle.js"></script>
80+
<script src="../dist/d2s.bundle.js"></script>
81+
<script>
82+
//if we arent local, use github latest
83+
if (window.d2s === undefined) {
84+
let s = document.createElement('script');
85+
s.src = "https://github.com/dschu012/d2s/releases/latest/download/constants.bundle.min.js";
86+
document.querySelector('body').appendChild(s);
87+
s = document.createElement('script');
88+
s.src = "https://github.com/dschu012/d2s/releases/latest/download/d2s.bundle.min.js";
89+
document.querySelector('body').appendChild(s);
90+
}
91+
let editor = new JSONEditor(document.querySelector('#d2sJson'), {
92+
mode: 'form',
93+
mainMenuBar: false,
94+
navigationBar: false
95+
})
96+
let errors = document.querySelector("#errors");
97+
98+
//read from input type=file
99+
let input = document.querySelector('#d2sFile');
100+
input.onchange = function (e) {
101+
let reader = new FileReader();
102+
reader.onload = function (re) {
103+
try {
104+
d2s.read(re.target.result, constants.constants).then((response) => {
105+
editor.set(response);
106+
//textarea.style.display = "block";
107+
//textarea.value = JSON.stringify(response, null, 2);
108+
});
109+
} catch (e) {
110+
errors.innerHTML = `<div class="alert alert-warning alert-dismissible fade show" role="alert">
111+
<strong>Error: </strong>${e.message}
112+
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
113+
</div>`
114+
}
115+
}
116+
reader.readAsArrayBuffer(this.files[0]);
117+
this.value = null;
118+
}
119+
120+
//write from json data
121+
let form = document.querySelector("#d2sForm");
122+
let link = document.createElement('a');
123+
link.style.display = 'none';
124+
document.body.appendChild(link);
125+
form.onsubmit = function (e) {
126+
e.preventDefault();
127+
e.stopPropagation();
128+
let j = editor.get();
129+
try {
130+
d2s.write(j, constants.constants).then((response) => {
131+
let blob = new Blob([response], { type: "octet/stream" });
132+
link.href = window.URL.createObjectURL(blob);
133+
link.download = j.header.name + '.d2s';
134+
link.click();
135+
});
136+
} catch (e) {
137+
errors.innerHTML = `<div class="alert alert-warning alert-dismissible fade show" role="alert">
138+
<strong>Error: </strong>${e.message}
139+
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
140+
</div>`
141+
}
142+
}
143+
</script>
144+
</body>
145+
</html>

examples/complex.d2s

3.64 KB
Binary file not shown.

0 commit comments

Comments
 (0)