@monokrome/bl4 0.5.5

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.
Files changed (5) hide show
  1. package/LICENSE +24 -0
  2. package/bl4.d.ts +178 -0
  3. package/bl4.js +645 -0
  4. package/bl4_bg.wasm +0 -0
  5. package/package.json +24 -0
package/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ BSD 2-Clause License
2
+
3
+ Copyright (c) 2025 bl4 Contributors
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
19
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/bl4.d.ts ADDED
@@ -0,0 +1,178 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export class ChangeSet {
5
+ free(): void;
6
+ [Symbol.dispose](): void;
7
+ /**
8
+ * Check if a path has a pending change
9
+ */
10
+ hasChange(path: string): boolean;
11
+ setEridium(amount: number): void;
12
+ setCharacterXp(xp: number): void;
13
+ setCharacterName(name: string): void;
14
+ setSpecializationXp(xp: number): void;
15
+ /**
16
+ * Add a change (value auto-parsed from string)
17
+ */
18
+ add(path: string, value: string): void;
19
+ /**
20
+ * Get number of changes
21
+ */
22
+ length(): number;
23
+ /**
24
+ * Create a new ChangeSet
25
+ */
26
+ constructor();
27
+ /**
28
+ * Apply changes to a SaveFile
29
+ */
30
+ apply(save: SaveFile): void;
31
+ /**
32
+ * Clear all changes
33
+ */
34
+ clear(): void;
35
+ /**
36
+ * Remove a change
37
+ */
38
+ remove(path: string): boolean;
39
+ /**
40
+ * Add raw YAML change
41
+ */
42
+ addRaw(path: string, yaml_str: string): void;
43
+ /**
44
+ * Check if empty
45
+ */
46
+ isEmpty(): boolean;
47
+ setCash(amount: number): void;
48
+ }
49
+
50
+ export class SaveFile {
51
+ free(): void;
52
+ [Symbol.dispose](): void;
53
+ getEridium(): number | undefined;
54
+ setEridium(amount: number): void;
55
+ getDifficulty(): string | undefined;
56
+ setCharacterXp(xp: number): void;
57
+ getCharacterName(): string | undefined;
58
+ setCharacterName(name: string): void;
59
+ getCharacterClass(): string | undefined;
60
+ getCharacterLevel(): Array<any> | undefined;
61
+ setSpecializationXp(xp: number): void;
62
+ getSpecializationLevel(): Array<any> | undefined;
63
+ /**
64
+ * Query a value at a YAML path
65
+ */
66
+ get(path: string): string;
67
+ /**
68
+ * Parse a save file from decrypted YAML data
69
+ */
70
+ constructor(yaml_data: Uint8Array);
71
+ /**
72
+ * Set a value at a YAML path (from string, auto-parsed)
73
+ */
74
+ set(path: string, value: string): void;
75
+ /**
76
+ * Set raw YAML value from string
77
+ */
78
+ setRaw(path: string, yaml_str: string): void;
79
+ /**
80
+ * Serialize back to YAML
81
+ */
82
+ toYaml(): Uint8Array;
83
+ getCash(): number | undefined;
84
+ setCash(amount: number): void;
85
+ }
86
+
87
+ /**
88
+ * Decrypt a Borderlands 4 save file
89
+ *
90
+ * # Arguments
91
+ * * `encrypted_data` - The encrypted .sav file as bytes
92
+ * * `steam_id` - Steam ID for decryption
93
+ *
94
+ * # Returns
95
+ * Decrypted YAML data as bytes
96
+ */
97
+ export function decryptSav(encrypted_data: Uint8Array, steam_id: string): Uint8Array;
98
+
99
+ /**
100
+ * Encrypt YAML data to a Borderlands 4 save file
101
+ *
102
+ * # Arguments
103
+ * * `yaml_data` - The YAML data as bytes
104
+ * * `steam_id` - Steam ID for encryption
105
+ *
106
+ * # Returns
107
+ * Encrypted .sav file data
108
+ */
109
+ export function encryptSav(yaml_data: Uint8Array, steam_id: string): Uint8Array;
110
+
111
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
112
+
113
+ export interface InitOutput {
114
+ readonly memory: WebAssembly.Memory;
115
+ readonly __wbg_changeset_free: (a: number, b: number) => void;
116
+ readonly __wbg_savefile_free: (a: number, b: number) => void;
117
+ readonly changeset_add: (a: number, b: number, c: number, d: number, e: number) => void;
118
+ readonly changeset_addRaw: (a: number, b: number, c: number, d: number, e: number) => [number, number];
119
+ readonly changeset_apply: (a: number, b: number) => [number, number];
120
+ readonly changeset_clear: (a: number) => void;
121
+ readonly changeset_hasChange: (a: number, b: number, c: number) => number;
122
+ readonly changeset_isEmpty: (a: number) => number;
123
+ readonly changeset_length: (a: number) => number;
124
+ readonly changeset_new: () => number;
125
+ readonly changeset_remove: (a: number, b: number, c: number) => number;
126
+ readonly changeset_setCash: (a: number, b: number) => void;
127
+ readonly changeset_setCharacterName: (a: number, b: number, c: number) => void;
128
+ readonly changeset_setCharacterXp: (a: number, b: number) => void;
129
+ readonly changeset_setEridium: (a: number, b: number) => void;
130
+ readonly changeset_setSpecializationXp: (a: number, b: number) => void;
131
+ readonly decryptSav: (a: number, b: number, c: number, d: number) => [number, number, number, number];
132
+ readonly encryptSav: (a: number, b: number, c: number, d: number) => [number, number, number, number];
133
+ readonly savefile_get: (a: number, b: number, c: number) => [number, number, number, number];
134
+ readonly savefile_getCash: (a: number) => [number, number];
135
+ readonly savefile_getCharacterClass: (a: number) => [number, number];
136
+ readonly savefile_getCharacterLevel: (a: number) => any;
137
+ readonly savefile_getCharacterName: (a: number) => [number, number];
138
+ readonly savefile_getDifficulty: (a: number) => [number, number];
139
+ readonly savefile_getEridium: (a: number) => [number, number];
140
+ readonly savefile_getSpecializationLevel: (a: number) => any;
141
+ readonly savefile_new: (a: number, b: number) => [number, number, number];
142
+ readonly savefile_set: (a: number, b: number, c: number, d: number, e: number) => [number, number];
143
+ readonly savefile_setCash: (a: number, b: number) => [number, number];
144
+ readonly savefile_setCharacterName: (a: number, b: number, c: number) => [number, number];
145
+ readonly savefile_setCharacterXp: (a: number, b: number) => [number, number];
146
+ readonly savefile_setEridium: (a: number, b: number) => [number, number];
147
+ readonly savefile_setRaw: (a: number, b: number, c: number, d: number, e: number) => [number, number];
148
+ readonly savefile_setSpecializationXp: (a: number, b: number) => [number, number];
149
+ readonly savefile_toYaml: (a: number) => [number, number, number, number];
150
+ readonly __wbindgen_externrefs: WebAssembly.Table;
151
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
152
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
153
+ readonly __externref_table_dealloc: (a: number) => void;
154
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
155
+ readonly __wbindgen_start: () => void;
156
+ }
157
+
158
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
159
+
160
+ /**
161
+ * Instantiates the given `module`, which can either be bytes or
162
+ * a precompiled `WebAssembly.Module`.
163
+ *
164
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
165
+ *
166
+ * @returns {InitOutput}
167
+ */
168
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
169
+
170
+ /**
171
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
172
+ * for everything else, calls `WebAssembly.instantiate` directly.
173
+ *
174
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
175
+ *
176
+ * @returns {Promise<InitOutput>}
177
+ */
178
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/bl4.js ADDED
@@ -0,0 +1,645 @@
1
+ let wasm;
2
+
3
+ function _assertClass(instance, klass) {
4
+ if (!(instance instanceof klass)) {
5
+ throw new Error(`expected instance of ${klass.name}`);
6
+ }
7
+ }
8
+
9
+ function getArrayU8FromWasm0(ptr, len) {
10
+ ptr = ptr >>> 0;
11
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
12
+ }
13
+
14
+ function getStringFromWasm0(ptr, len) {
15
+ ptr = ptr >>> 0;
16
+ return decodeText(ptr, len);
17
+ }
18
+
19
+ let cachedUint8ArrayMemory0 = null;
20
+ function getUint8ArrayMemory0() {
21
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
22
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
23
+ }
24
+ return cachedUint8ArrayMemory0;
25
+ }
26
+
27
+ function passArray8ToWasm0(arg, malloc) {
28
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
29
+ getUint8ArrayMemory0().set(arg, ptr / 1);
30
+ WASM_VECTOR_LEN = arg.length;
31
+ return ptr;
32
+ }
33
+
34
+ function passStringToWasm0(arg, malloc, realloc) {
35
+ if (realloc === undefined) {
36
+ const buf = cachedTextEncoder.encode(arg);
37
+ const ptr = malloc(buf.length, 1) >>> 0;
38
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
39
+ WASM_VECTOR_LEN = buf.length;
40
+ return ptr;
41
+ }
42
+
43
+ let len = arg.length;
44
+ let ptr = malloc(len, 1) >>> 0;
45
+
46
+ const mem = getUint8ArrayMemory0();
47
+
48
+ let offset = 0;
49
+
50
+ for (; offset < len; offset++) {
51
+ const code = arg.charCodeAt(offset);
52
+ if (code > 0x7F) break;
53
+ mem[ptr + offset] = code;
54
+ }
55
+ if (offset !== len) {
56
+ if (offset !== 0) {
57
+ arg = arg.slice(offset);
58
+ }
59
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
60
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
61
+ const ret = cachedTextEncoder.encodeInto(arg, view);
62
+
63
+ offset += ret.written;
64
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
65
+ }
66
+
67
+ WASM_VECTOR_LEN = offset;
68
+ return ptr;
69
+ }
70
+
71
+ function takeFromExternrefTable0(idx) {
72
+ const value = wasm.__wbindgen_externrefs.get(idx);
73
+ wasm.__externref_table_dealloc(idx);
74
+ return value;
75
+ }
76
+
77
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
78
+ cachedTextDecoder.decode();
79
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
80
+ let numBytesDecoded = 0;
81
+ function decodeText(ptr, len) {
82
+ numBytesDecoded += len;
83
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
84
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
85
+ cachedTextDecoder.decode();
86
+ numBytesDecoded = len;
87
+ }
88
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
89
+ }
90
+
91
+ const cachedTextEncoder = new TextEncoder();
92
+
93
+ if (!('encodeInto' in cachedTextEncoder)) {
94
+ cachedTextEncoder.encodeInto = function (arg, view) {
95
+ const buf = cachedTextEncoder.encode(arg);
96
+ view.set(buf);
97
+ return {
98
+ read: arg.length,
99
+ written: buf.length
100
+ };
101
+ }
102
+ }
103
+
104
+ let WASM_VECTOR_LEN = 0;
105
+
106
+ const ChangeSetFinalization = (typeof FinalizationRegistry === 'undefined')
107
+ ? { register: () => {}, unregister: () => {} }
108
+ : new FinalizationRegistry(ptr => wasm.__wbg_changeset_free(ptr >>> 0, 1));
109
+
110
+ const SaveFileFinalization = (typeof FinalizationRegistry === 'undefined')
111
+ ? { register: () => {}, unregister: () => {} }
112
+ : new FinalizationRegistry(ptr => wasm.__wbg_savefile_free(ptr >>> 0, 1));
113
+
114
+ /**
115
+ * JavaScript-friendly ChangeSet wrapper
116
+ */
117
+ export class ChangeSet {
118
+ __destroy_into_raw() {
119
+ const ptr = this.__wbg_ptr;
120
+ this.__wbg_ptr = 0;
121
+ ChangeSetFinalization.unregister(this);
122
+ return ptr;
123
+ }
124
+ free() {
125
+ const ptr = this.__destroy_into_raw();
126
+ wasm.__wbg_changeset_free(ptr, 0);
127
+ }
128
+ /**
129
+ * Check if a path has a pending change
130
+ * @param {string} path
131
+ * @returns {boolean}
132
+ */
133
+ hasChange(path) {
134
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
135
+ const len0 = WASM_VECTOR_LEN;
136
+ const ret = wasm.changeset_hasChange(this.__wbg_ptr, ptr0, len0);
137
+ return ret !== 0;
138
+ }
139
+ /**
140
+ * @param {number} amount
141
+ */
142
+ setEridium(amount) {
143
+ wasm.changeset_setEridium(this.__wbg_ptr, amount);
144
+ }
145
+ /**
146
+ * @param {number} xp
147
+ */
148
+ setCharacterXp(xp) {
149
+ wasm.changeset_setCharacterXp(this.__wbg_ptr, xp);
150
+ }
151
+ /**
152
+ * @param {string} name
153
+ */
154
+ setCharacterName(name) {
155
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
156
+ const len0 = WASM_VECTOR_LEN;
157
+ wasm.changeset_setCharacterName(this.__wbg_ptr, ptr0, len0);
158
+ }
159
+ /**
160
+ * @param {number} xp
161
+ */
162
+ setSpecializationXp(xp) {
163
+ wasm.changeset_setSpecializationXp(this.__wbg_ptr, xp);
164
+ }
165
+ /**
166
+ * Add a change (value auto-parsed from string)
167
+ * @param {string} path
168
+ * @param {string} value
169
+ */
170
+ add(path, value) {
171
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
172
+ const len0 = WASM_VECTOR_LEN;
173
+ const ptr1 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
174
+ const len1 = WASM_VECTOR_LEN;
175
+ wasm.changeset_add(this.__wbg_ptr, ptr0, len0, ptr1, len1);
176
+ }
177
+ /**
178
+ * Get number of changes
179
+ * @returns {number}
180
+ */
181
+ length() {
182
+ const ret = wasm.changeset_length(this.__wbg_ptr);
183
+ return ret >>> 0;
184
+ }
185
+ /**
186
+ * Create a new ChangeSet
187
+ */
188
+ constructor() {
189
+ const ret = wasm.changeset_new();
190
+ this.__wbg_ptr = ret >>> 0;
191
+ ChangeSetFinalization.register(this, this.__wbg_ptr, this);
192
+ return this;
193
+ }
194
+ /**
195
+ * Apply changes to a SaveFile
196
+ * @param {SaveFile} save
197
+ */
198
+ apply(save) {
199
+ _assertClass(save, SaveFile);
200
+ const ret = wasm.changeset_apply(this.__wbg_ptr, save.__wbg_ptr);
201
+ if (ret[1]) {
202
+ throw takeFromExternrefTable0(ret[0]);
203
+ }
204
+ }
205
+ /**
206
+ * Clear all changes
207
+ */
208
+ clear() {
209
+ wasm.changeset_clear(this.__wbg_ptr);
210
+ }
211
+ /**
212
+ * Remove a change
213
+ * @param {string} path
214
+ * @returns {boolean}
215
+ */
216
+ remove(path) {
217
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
218
+ const len0 = WASM_VECTOR_LEN;
219
+ const ret = wasm.changeset_remove(this.__wbg_ptr, ptr0, len0);
220
+ return ret !== 0;
221
+ }
222
+ /**
223
+ * Add raw YAML change
224
+ * @param {string} path
225
+ * @param {string} yaml_str
226
+ */
227
+ addRaw(path, yaml_str) {
228
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
229
+ const len0 = WASM_VECTOR_LEN;
230
+ const ptr1 = passStringToWasm0(yaml_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
231
+ const len1 = WASM_VECTOR_LEN;
232
+ const ret = wasm.changeset_addRaw(this.__wbg_ptr, ptr0, len0, ptr1, len1);
233
+ if (ret[1]) {
234
+ throw takeFromExternrefTable0(ret[0]);
235
+ }
236
+ }
237
+ /**
238
+ * Check if empty
239
+ * @returns {boolean}
240
+ */
241
+ isEmpty() {
242
+ const ret = wasm.changeset_isEmpty(this.__wbg_ptr);
243
+ return ret !== 0;
244
+ }
245
+ /**
246
+ * @param {number} amount
247
+ */
248
+ setCash(amount) {
249
+ wasm.changeset_setCash(this.__wbg_ptr, amount);
250
+ }
251
+ }
252
+ if (Symbol.dispose) ChangeSet.prototype[Symbol.dispose] = ChangeSet.prototype.free;
253
+
254
+ /**
255
+ * JavaScript-friendly SaveFile wrapper
256
+ */
257
+ export class SaveFile {
258
+ __destroy_into_raw() {
259
+ const ptr = this.__wbg_ptr;
260
+ this.__wbg_ptr = 0;
261
+ SaveFileFinalization.unregister(this);
262
+ return ptr;
263
+ }
264
+ free() {
265
+ const ptr = this.__destroy_into_raw();
266
+ wasm.__wbg_savefile_free(ptr, 0);
267
+ }
268
+ /**
269
+ * @returns {number | undefined}
270
+ */
271
+ getEridium() {
272
+ const ret = wasm.savefile_getEridium(this.__wbg_ptr);
273
+ return ret[0] === 0 ? undefined : ret[1];
274
+ }
275
+ /**
276
+ * @param {number} amount
277
+ */
278
+ setEridium(amount) {
279
+ const ret = wasm.savefile_setEridium(this.__wbg_ptr, amount);
280
+ if (ret[1]) {
281
+ throw takeFromExternrefTable0(ret[0]);
282
+ }
283
+ }
284
+ /**
285
+ * @returns {string | undefined}
286
+ */
287
+ getDifficulty() {
288
+ const ret = wasm.savefile_getDifficulty(this.__wbg_ptr);
289
+ let v1;
290
+ if (ret[0] !== 0) {
291
+ v1 = getStringFromWasm0(ret[0], ret[1]).slice();
292
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
293
+ }
294
+ return v1;
295
+ }
296
+ /**
297
+ * @param {number} xp
298
+ */
299
+ setCharacterXp(xp) {
300
+ const ret = wasm.savefile_setCharacterXp(this.__wbg_ptr, xp);
301
+ if (ret[1]) {
302
+ throw takeFromExternrefTable0(ret[0]);
303
+ }
304
+ }
305
+ /**
306
+ * @returns {string | undefined}
307
+ */
308
+ getCharacterName() {
309
+ const ret = wasm.savefile_getCharacterName(this.__wbg_ptr);
310
+ let v1;
311
+ if (ret[0] !== 0) {
312
+ v1 = getStringFromWasm0(ret[0], ret[1]).slice();
313
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
314
+ }
315
+ return v1;
316
+ }
317
+ /**
318
+ * @param {string} name
319
+ */
320
+ setCharacterName(name) {
321
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
322
+ const len0 = WASM_VECTOR_LEN;
323
+ const ret = wasm.savefile_setCharacterName(this.__wbg_ptr, ptr0, len0);
324
+ if (ret[1]) {
325
+ throw takeFromExternrefTable0(ret[0]);
326
+ }
327
+ }
328
+ /**
329
+ * @returns {string | undefined}
330
+ */
331
+ getCharacterClass() {
332
+ const ret = wasm.savefile_getCharacterClass(this.__wbg_ptr);
333
+ let v1;
334
+ if (ret[0] !== 0) {
335
+ v1 = getStringFromWasm0(ret[0], ret[1]).slice();
336
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
337
+ }
338
+ return v1;
339
+ }
340
+ /**
341
+ * @returns {Array<any> | undefined}
342
+ */
343
+ getCharacterLevel() {
344
+ const ret = wasm.savefile_getCharacterLevel(this.__wbg_ptr);
345
+ return ret;
346
+ }
347
+ /**
348
+ * @param {number} xp
349
+ */
350
+ setSpecializationXp(xp) {
351
+ const ret = wasm.savefile_setSpecializationXp(this.__wbg_ptr, xp);
352
+ if (ret[1]) {
353
+ throw takeFromExternrefTable0(ret[0]);
354
+ }
355
+ }
356
+ /**
357
+ * @returns {Array<any> | undefined}
358
+ */
359
+ getSpecializationLevel() {
360
+ const ret = wasm.savefile_getSpecializationLevel(this.__wbg_ptr);
361
+ return ret;
362
+ }
363
+ /**
364
+ * Query a value at a YAML path
365
+ * @param {string} path
366
+ * @returns {string}
367
+ */
368
+ get(path) {
369
+ let deferred3_0;
370
+ let deferred3_1;
371
+ try {
372
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
373
+ const len0 = WASM_VECTOR_LEN;
374
+ const ret = wasm.savefile_get(this.__wbg_ptr, ptr0, len0);
375
+ var ptr2 = ret[0];
376
+ var len2 = ret[1];
377
+ if (ret[3]) {
378
+ ptr2 = 0; len2 = 0;
379
+ throw takeFromExternrefTable0(ret[2]);
380
+ }
381
+ deferred3_0 = ptr2;
382
+ deferred3_1 = len2;
383
+ return getStringFromWasm0(ptr2, len2);
384
+ } finally {
385
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
386
+ }
387
+ }
388
+ /**
389
+ * Parse a save file from decrypted YAML data
390
+ * @param {Uint8Array} yaml_data
391
+ */
392
+ constructor(yaml_data) {
393
+ const ptr0 = passArray8ToWasm0(yaml_data, wasm.__wbindgen_malloc);
394
+ const len0 = WASM_VECTOR_LEN;
395
+ const ret = wasm.savefile_new(ptr0, len0);
396
+ if (ret[2]) {
397
+ throw takeFromExternrefTable0(ret[1]);
398
+ }
399
+ this.__wbg_ptr = ret[0] >>> 0;
400
+ SaveFileFinalization.register(this, this.__wbg_ptr, this);
401
+ return this;
402
+ }
403
+ /**
404
+ * Set a value at a YAML path (from string, auto-parsed)
405
+ * @param {string} path
406
+ * @param {string} value
407
+ */
408
+ set(path, value) {
409
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
410
+ const len0 = WASM_VECTOR_LEN;
411
+ const ptr1 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
412
+ const len1 = WASM_VECTOR_LEN;
413
+ const ret = wasm.savefile_set(this.__wbg_ptr, ptr0, len0, ptr1, len1);
414
+ if (ret[1]) {
415
+ throw takeFromExternrefTable0(ret[0]);
416
+ }
417
+ }
418
+ /**
419
+ * Set raw YAML value from string
420
+ * @param {string} path
421
+ * @param {string} yaml_str
422
+ */
423
+ setRaw(path, yaml_str) {
424
+ const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
425
+ const len0 = WASM_VECTOR_LEN;
426
+ const ptr1 = passStringToWasm0(yaml_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
427
+ const len1 = WASM_VECTOR_LEN;
428
+ const ret = wasm.savefile_setRaw(this.__wbg_ptr, ptr0, len0, ptr1, len1);
429
+ if (ret[1]) {
430
+ throw takeFromExternrefTable0(ret[0]);
431
+ }
432
+ }
433
+ /**
434
+ * Serialize back to YAML
435
+ * @returns {Uint8Array}
436
+ */
437
+ toYaml() {
438
+ const ret = wasm.savefile_toYaml(this.__wbg_ptr);
439
+ if (ret[3]) {
440
+ throw takeFromExternrefTable0(ret[2]);
441
+ }
442
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
443
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
444
+ return v1;
445
+ }
446
+ /**
447
+ * @returns {number | undefined}
448
+ */
449
+ getCash() {
450
+ const ret = wasm.savefile_getCash(this.__wbg_ptr);
451
+ return ret[0] === 0 ? undefined : ret[1];
452
+ }
453
+ /**
454
+ * @param {number} amount
455
+ */
456
+ setCash(amount) {
457
+ const ret = wasm.savefile_setCash(this.__wbg_ptr, amount);
458
+ if (ret[1]) {
459
+ throw takeFromExternrefTable0(ret[0]);
460
+ }
461
+ }
462
+ }
463
+ if (Symbol.dispose) SaveFile.prototype[Symbol.dispose] = SaveFile.prototype.free;
464
+
465
+ /**
466
+ * Decrypt a Borderlands 4 save file
467
+ *
468
+ * # Arguments
469
+ * * `encrypted_data` - The encrypted .sav file as bytes
470
+ * * `steam_id` - Steam ID for decryption
471
+ *
472
+ * # Returns
473
+ * Decrypted YAML data as bytes
474
+ * @param {Uint8Array} encrypted_data
475
+ * @param {string} steam_id
476
+ * @returns {Uint8Array}
477
+ */
478
+ export function decryptSav(encrypted_data, steam_id) {
479
+ const ptr0 = passArray8ToWasm0(encrypted_data, wasm.__wbindgen_malloc);
480
+ const len0 = WASM_VECTOR_LEN;
481
+ const ptr1 = passStringToWasm0(steam_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
482
+ const len1 = WASM_VECTOR_LEN;
483
+ const ret = wasm.decryptSav(ptr0, len0, ptr1, len1);
484
+ if (ret[3]) {
485
+ throw takeFromExternrefTable0(ret[2]);
486
+ }
487
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
488
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
489
+ return v3;
490
+ }
491
+
492
+ /**
493
+ * Encrypt YAML data to a Borderlands 4 save file
494
+ *
495
+ * # Arguments
496
+ * * `yaml_data` - The YAML data as bytes
497
+ * * `steam_id` - Steam ID for encryption
498
+ *
499
+ * # Returns
500
+ * Encrypted .sav file data
501
+ * @param {Uint8Array} yaml_data
502
+ * @param {string} steam_id
503
+ * @returns {Uint8Array}
504
+ */
505
+ export function encryptSav(yaml_data, steam_id) {
506
+ const ptr0 = passArray8ToWasm0(yaml_data, wasm.__wbindgen_malloc);
507
+ const len0 = WASM_VECTOR_LEN;
508
+ const ptr1 = passStringToWasm0(steam_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
509
+ const len1 = WASM_VECTOR_LEN;
510
+ const ret = wasm.encryptSav(ptr0, len0, ptr1, len1);
511
+ if (ret[3]) {
512
+ throw takeFromExternrefTable0(ret[2]);
513
+ }
514
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
515
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
516
+ return v3;
517
+ }
518
+
519
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
520
+
521
+ async function __wbg_load(module, imports) {
522
+ if (typeof Response === 'function' && module instanceof Response) {
523
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
524
+ try {
525
+ return await WebAssembly.instantiateStreaming(module, imports);
526
+ } catch (e) {
527
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
528
+
529
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
530
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
531
+
532
+ } else {
533
+ throw e;
534
+ }
535
+ }
536
+ }
537
+
538
+ const bytes = await module.arrayBuffer();
539
+ return await WebAssembly.instantiate(bytes, imports);
540
+ } else {
541
+ const instance = await WebAssembly.instantiate(module, imports);
542
+
543
+ if (instance instanceof WebAssembly.Instance) {
544
+ return { instance, module };
545
+ } else {
546
+ return instance;
547
+ }
548
+ }
549
+ }
550
+
551
+ function __wbg_get_imports() {
552
+ const imports = {};
553
+ imports.wbg = {};
554
+ imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
555
+ throw new Error(getStringFromWasm0(arg0, arg1));
556
+ };
557
+ imports.wbg.__wbg_new_25f239778d6112b9 = function() {
558
+ const ret = new Array();
559
+ return ret;
560
+ };
561
+ imports.wbg.__wbg_push_7d9be8f38fc13975 = function(arg0, arg1) {
562
+ const ret = arg0.push(arg1);
563
+ return ret;
564
+ };
565
+ imports.wbg.__wbindgen_cast_2241b6af4c4b2941 = function(arg0, arg1) {
566
+ // Cast intrinsic for `Ref(String) -> Externref`.
567
+ const ret = getStringFromWasm0(arg0, arg1);
568
+ return ret;
569
+ };
570
+ imports.wbg.__wbindgen_cast_d6cd19b81560fd6e = function(arg0) {
571
+ // Cast intrinsic for `F64 -> Externref`.
572
+ const ret = arg0;
573
+ return ret;
574
+ };
575
+ imports.wbg.__wbindgen_init_externref_table = function() {
576
+ const table = wasm.__wbindgen_externrefs;
577
+ const offset = table.grow(4);
578
+ table.set(0, undefined);
579
+ table.set(offset + 0, undefined);
580
+ table.set(offset + 1, null);
581
+ table.set(offset + 2, true);
582
+ table.set(offset + 3, false);
583
+ };
584
+
585
+ return imports;
586
+ }
587
+
588
+ function __wbg_finalize_init(instance, module) {
589
+ wasm = instance.exports;
590
+ __wbg_init.__wbindgen_wasm_module = module;
591
+ cachedUint8ArrayMemory0 = null;
592
+
593
+
594
+ wasm.__wbindgen_start();
595
+ return wasm;
596
+ }
597
+
598
+ function initSync(module) {
599
+ if (wasm !== undefined) return wasm;
600
+
601
+
602
+ if (typeof module !== 'undefined') {
603
+ if (Object.getPrototypeOf(module) === Object.prototype) {
604
+ ({module} = module)
605
+ } else {
606
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
607
+ }
608
+ }
609
+
610
+ const imports = __wbg_get_imports();
611
+ if (!(module instanceof WebAssembly.Module)) {
612
+ module = new WebAssembly.Module(module);
613
+ }
614
+ const instance = new WebAssembly.Instance(module, imports);
615
+ return __wbg_finalize_init(instance, module);
616
+ }
617
+
618
+ async function __wbg_init(module_or_path) {
619
+ if (wasm !== undefined) return wasm;
620
+
621
+
622
+ if (typeof module_or_path !== 'undefined') {
623
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
624
+ ({module_or_path} = module_or_path)
625
+ } else {
626
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
627
+ }
628
+ }
629
+
630
+ if (typeof module_or_path === 'undefined') {
631
+ module_or_path = new URL('bl4_bg.wasm', import.meta.url);
632
+ }
633
+ const imports = __wbg_get_imports();
634
+
635
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
636
+ module_or_path = fetch(module_or_path);
637
+ }
638
+
639
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
640
+
641
+ return __wbg_finalize_init(instance, module);
642
+ }
643
+
644
+ export { initSync };
645
+ export default __wbg_init;
package/bl4_bg.wasm ADDED
Binary file
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@monokrome/bl4",
3
+ "type": "module",
4
+ "collaborators": [
5
+ "bl4 Contributors"
6
+ ],
7
+ "description": "Borderlands 4 save editor library - encryption, decryption, and parsing",
8
+ "version": "0.5.5",
9
+ "license": "BSD-2-Clause",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/monokrome/bl4"
13
+ },
14
+ "files": [
15
+ "bl4_bg.wasm",
16
+ "bl4.js",
17
+ "bl4.d.ts"
18
+ ],
19
+ "main": "bl4.js",
20
+ "types": "bl4.d.ts",
21
+ "sideEffects": [
22
+ "./snippets/*"
23
+ ]
24
+ }