aoe2rec-js 0.1.0
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.
- package/README.md +31 -0
- package/aoe2rec_js.d.ts +4 -0
- package/aoe2rec_js.js +5 -0
- package/aoe2rec_js_bg.js +280 -0
- package/aoe2rec_js_bg.wasm +0 -0
- package/package.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Age of Empires 2 Record parser
|
|
2
|
+
|
|
3
|
+
This is a WASM library to parse Age of Empires 2 DE save games
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
To use the library, pass a ArrayBuffer to the `parse_rec` function. Example:
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
```html
|
|
10
|
+
<input type="file" id="fileElem">
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { parse_rec } from "aoe2rec-js";
|
|
15
|
+
|
|
16
|
+
const fileElem = document.getElementById("fileElem");
|
|
17
|
+
fileElem.addEventListener("change", event => {
|
|
18
|
+
const files = (event.target as HTMLInputElement).files
|
|
19
|
+
if (!files) {
|
|
20
|
+
replayFile.value = null
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
const file = files[0]
|
|
24
|
+
const reader = new FileReader();
|
|
25
|
+
reader.onload = (event) => {
|
|
26
|
+
const rec = instance.parse_rec(event.target.result);
|
|
27
|
+
};
|
|
28
|
+
reader.readAsArrayBuffer(file);
|
|
29
|
+
|
|
30
|
+
}, false);
|
|
31
|
+
```
|
package/aoe2rec_js.d.ts
ADDED
package/aoe2rec_js.js
ADDED
package/aoe2rec_js_bg.js
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
let wasm;
|
|
2
|
+
export function __wbg_set_wasm(val) {
|
|
3
|
+
wasm = val;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
|
|
8
|
+
|
|
9
|
+
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
10
|
+
|
|
11
|
+
cachedTextDecoder.decode();
|
|
12
|
+
|
|
13
|
+
let cachedUint8ArrayMemory0 = null;
|
|
14
|
+
|
|
15
|
+
function getUint8ArrayMemory0() {
|
|
16
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
17
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
18
|
+
}
|
|
19
|
+
return cachedUint8ArrayMemory0;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function getStringFromWasm0(ptr, len) {
|
|
23
|
+
ptr = ptr >>> 0;
|
|
24
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let WASM_VECTOR_LEN = 0;
|
|
28
|
+
|
|
29
|
+
const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
|
|
30
|
+
|
|
31
|
+
let cachedTextEncoder = new lTextEncoder('utf-8');
|
|
32
|
+
|
|
33
|
+
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
34
|
+
? function (arg, view) {
|
|
35
|
+
return cachedTextEncoder.encodeInto(arg, view);
|
|
36
|
+
}
|
|
37
|
+
: function (arg, view) {
|
|
38
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
39
|
+
view.set(buf);
|
|
40
|
+
return {
|
|
41
|
+
read: arg.length,
|
|
42
|
+
written: buf.length
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
47
|
+
|
|
48
|
+
if (realloc === undefined) {
|
|
49
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
50
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
51
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
52
|
+
WASM_VECTOR_LEN = buf.length;
|
|
53
|
+
return ptr;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let len = arg.length;
|
|
57
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
58
|
+
|
|
59
|
+
const mem = getUint8ArrayMemory0();
|
|
60
|
+
|
|
61
|
+
let offset = 0;
|
|
62
|
+
|
|
63
|
+
for (; offset < len; offset++) {
|
|
64
|
+
const code = arg.charCodeAt(offset);
|
|
65
|
+
if (code > 0x7F) break;
|
|
66
|
+
mem[ptr + offset] = code;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (offset !== len) {
|
|
70
|
+
if (offset !== 0) {
|
|
71
|
+
arg = arg.slice(offset);
|
|
72
|
+
}
|
|
73
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
74
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
75
|
+
const ret = encodeString(arg, view);
|
|
76
|
+
|
|
77
|
+
offset += ret.written;
|
|
78
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
WASM_VECTOR_LEN = offset;
|
|
82
|
+
return ptr;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let cachedDataViewMemory0 = null;
|
|
86
|
+
|
|
87
|
+
function getDataViewMemory0() {
|
|
88
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
89
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
90
|
+
}
|
|
91
|
+
return cachedDataViewMemory0;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function debugString(val) {
|
|
95
|
+
// primitive types
|
|
96
|
+
const type = typeof val;
|
|
97
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
98
|
+
return `${val}`;
|
|
99
|
+
}
|
|
100
|
+
if (type == 'string') {
|
|
101
|
+
return `"${val}"`;
|
|
102
|
+
}
|
|
103
|
+
if (type == 'symbol') {
|
|
104
|
+
const description = val.description;
|
|
105
|
+
if (description == null) {
|
|
106
|
+
return 'Symbol';
|
|
107
|
+
} else {
|
|
108
|
+
return `Symbol(${description})`;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (type == 'function') {
|
|
112
|
+
const name = val.name;
|
|
113
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
114
|
+
return `Function(${name})`;
|
|
115
|
+
} else {
|
|
116
|
+
return 'Function';
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// objects
|
|
120
|
+
if (Array.isArray(val)) {
|
|
121
|
+
const length = val.length;
|
|
122
|
+
let debug = '[';
|
|
123
|
+
if (length > 0) {
|
|
124
|
+
debug += debugString(val[0]);
|
|
125
|
+
}
|
|
126
|
+
for(let i = 1; i < length; i++) {
|
|
127
|
+
debug += ', ' + debugString(val[i]);
|
|
128
|
+
}
|
|
129
|
+
debug += ']';
|
|
130
|
+
return debug;
|
|
131
|
+
}
|
|
132
|
+
// Test for built-in
|
|
133
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
134
|
+
let className;
|
|
135
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
136
|
+
className = builtInMatches[1];
|
|
137
|
+
} else {
|
|
138
|
+
// Failed to match the standard '[object ClassName]'
|
|
139
|
+
return toString.call(val);
|
|
140
|
+
}
|
|
141
|
+
if (className == 'Object') {
|
|
142
|
+
// we're a user defined class or Object
|
|
143
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
144
|
+
// easier than looping through ownProperties of `val`.
|
|
145
|
+
try {
|
|
146
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
147
|
+
} catch (_) {
|
|
148
|
+
return 'Object';
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// errors
|
|
152
|
+
if (val instanceof Error) {
|
|
153
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
154
|
+
}
|
|
155
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
156
|
+
return className;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function greet() {
|
|
160
|
+
wasm.greet();
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* @param {ArrayBuffer} buffer
|
|
165
|
+
* @returns {any}
|
|
166
|
+
*/
|
|
167
|
+
export function parse_rec(buffer) {
|
|
168
|
+
const ret = wasm.parse_rec(buffer);
|
|
169
|
+
return ret;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function __wbg_alert_4407f2dea11ed32a(arg0, arg1) {
|
|
173
|
+
alert(getStringFromWasm0(arg0, arg1));
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
export function __wbg_buffer_61b7ce01341d7f88(arg0) {
|
|
177
|
+
const ret = arg0.buffer;
|
|
178
|
+
return ret;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export function __wbg_error_7534b8e9a36f1ab4(arg0, arg1) {
|
|
182
|
+
let deferred0_0;
|
|
183
|
+
let deferred0_1;
|
|
184
|
+
try {
|
|
185
|
+
deferred0_0 = arg0;
|
|
186
|
+
deferred0_1 = arg1;
|
|
187
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
188
|
+
} finally {
|
|
189
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export function __wbg_length_65d1cd11729ced11(arg0) {
|
|
194
|
+
const ret = arg0.length;
|
|
195
|
+
return ret;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export function __wbg_new_254fa9eac11932ae() {
|
|
199
|
+
const ret = new Array();
|
|
200
|
+
return ret;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
export function __wbg_new_3ff5b33b1ce712df(arg0) {
|
|
204
|
+
const ret = new Uint8Array(arg0);
|
|
205
|
+
return ret;
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
export function __wbg_new_688846f374351c92() {
|
|
209
|
+
const ret = new Object();
|
|
210
|
+
return ret;
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
export function __wbg_new_8a6f238a6ece86ea() {
|
|
214
|
+
const ret = new Error();
|
|
215
|
+
return ret;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export function __wbg_set_1d80752d0d5f0b21(arg0, arg1, arg2) {
|
|
219
|
+
arg0[arg1 >>> 0] = arg2;
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export function __wbg_set_23d69db4e5c66a6e(arg0, arg1, arg2) {
|
|
223
|
+
arg0.set(arg1, arg2 >>> 0);
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
export function __wbg_set_3f1d0b984ed272ed(arg0, arg1, arg2) {
|
|
227
|
+
arg0[arg1] = arg2;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
export function __wbg_stack_0ed75d68575b0f3c(arg0, arg1) {
|
|
231
|
+
const ret = arg1.stack;
|
|
232
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
233
|
+
const len1 = WASM_VECTOR_LEN;
|
|
234
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
235
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
export function __wbindgen_as_number(arg0) {
|
|
239
|
+
const ret = +arg0;
|
|
240
|
+
return ret;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
export function __wbindgen_debug_string(arg0, arg1) {
|
|
244
|
+
const ret = debugString(arg1);
|
|
245
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
246
|
+
const len1 = WASM_VECTOR_LEN;
|
|
247
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
248
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
export function __wbindgen_init_externref_table() {
|
|
252
|
+
const table = wasm.__wbindgen_export_3;
|
|
253
|
+
const offset = table.grow(4);
|
|
254
|
+
table.set(0, undefined);
|
|
255
|
+
table.set(offset + 0, undefined);
|
|
256
|
+
table.set(offset + 1, null);
|
|
257
|
+
table.set(offset + 2, true);
|
|
258
|
+
table.set(offset + 3, false);
|
|
259
|
+
;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
export function __wbindgen_memory() {
|
|
263
|
+
const ret = wasm.memory;
|
|
264
|
+
return ret;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
export function __wbindgen_number_new(arg0) {
|
|
268
|
+
const ret = arg0;
|
|
269
|
+
return ret;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
export function __wbindgen_string_new(arg0, arg1) {
|
|
273
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
274
|
+
return ret;
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
export function __wbindgen_throw(arg0, arg1) {
|
|
278
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
279
|
+
};
|
|
280
|
+
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "aoe2rec-js",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"collaborators": [
|
|
5
|
+
"Stéphane Bisinger <stephane@sbisinger.ch>"
|
|
6
|
+
],
|
|
7
|
+
"version": "0.1.0",
|
|
8
|
+
"files": [
|
|
9
|
+
"aoe2rec_js_bg.wasm",
|
|
10
|
+
"aoe2rec_js.js",
|
|
11
|
+
"aoe2rec_js_bg.js",
|
|
12
|
+
"aoe2rec_js.d.ts"
|
|
13
|
+
],
|
|
14
|
+
"main": "aoe2rec_js.js",
|
|
15
|
+
"types": "aoe2rec_js.d.ts",
|
|
16
|
+
"sideEffects": [
|
|
17
|
+
"./aoe2rec_js.js",
|
|
18
|
+
"./snippets/*"
|
|
19
|
+
]
|
|
20
|
+
}
|