-
Notifications
You must be signed in to change notification settings - Fork 0
/
decodeSave.ts
54 lines (44 loc) · 1.27 KB
/
decodeSave.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { decode } from "@/serialization";
import * as readLine from 'readline/promises';
const readline = readLine.createInterface({
input: process.stdin,
output: process.stdout
});
async function main() {
const lines: string[] = [];
console.log('Paste save data (enter empty line to continue):');
await new Promise<void>(resolve => {
const onLine = (line: string) => {
const trimmed = line.trim().replace(/\s/g, '');
if (trimmed.length > 0) {
lines.push(trimmed);
} else {
readline.off('line', onLine);
resolve();
}
}
readline.on('line', onLine);
});
const saveData = lines.join('');
if (!saveData) {
console.error('Exiting: no save data provided');
process.exit();
}
const fileName = await readline.question(
'Enter output file name\n(will be saved to ./output/, leave empty to use date): '
);
const defaultFileName = new Date().toISOString().replace(/[-:]/g, '').replace(/\..+/, '');
let filePath = `.\\output\\${fileName || defaultFileName}`;
if (!filePath.endsWith('.bin')) {
filePath += '.bin';
}
console.log('Decoding...');
await decode(saveData, filePath);
console.log(`Saved to ${filePath}`);
}
async function loop() {
while (true) {
await main();
}
}
loop();