-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
115 lines (97 loc) · 3.47 KB
/
index.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const fs = require('fs');
const path = require('path');
const os = require('os');
const readdir = fs.readdir;
const stat = fs.stat;
const readFile = fs.readFile;
const writeFileSync = fs.writeFileSync;
const join = path.join;
const homedir = os.homedir;
const userDirectory = homedir();
const bonelabSavesDir = join(userDirectory, 'AppData', 'LocalLow', 'Stress Level Zero', 'BONELAB', 'Saves');
const rgb = (r, g, b, msg) => `\x1b[38;2;${r};${g};${b}m${msg}\x1b[0m`;
const log = (...args) => console.log(`[${rgb(88, 101, 242, 'INFO')}]`, ...args);
log('Starting...')
function scanDirectory(dirPath) {
return new Promise((resolve, reject) => {
readdir(dirPath, (err, files) => {
if (err) {
reject(`Unable to get Saves Directory: ${err}`);
} else {
resolve(files);
}
});
});
}
function fetchFileStats(filePath) {
return new Promise((resolve, reject) => {
stat(filePath, (err, stats) => {
if (err) {
reject(`Unable to get stats of file: ${err}`);
} else {
resolve(stats);
}
});
});
}
function readFileContent(filePath) {
return new Promise((resolve, reject) => {
readFile(filePath, 'utf8', (err, data) => {
if (err) {
reject(`Unable to open file: ${err}`);
} else {
resolve(data);
}
});
});
}
scanDirectory(bonelabSavesDir)
.then(async files => {
let latestFile = null;
let latestTime = 0;
for (const file of files) {
if (!file.startsWith('save_')) continue;
const filePath = join(bonelabSavesDir, file);
const stats = await fetchFileStats(filePath);
if (stats.mtimeMs > latestTime) {
latestTime = stats.mtimeMs;
latestFile = filePath;
}
}
if (latestFile) {
log(`Latest Save is "${latestFile}"`);
let content;
try {
content = JSON.parse(await readFileContent(latestFile));
} catch (error) {
console.error(`Unable to parse Save file: ${error}`);
content = null;
}
return { latestFile, content }
} else {
throw new Error('No files found in the directory.');
}
})
.then(async (file) => {
log('Attempting to Recover...');
let saveData = file.content;
saveData.player_settings.favorite_avatars = [
"fa534c5a83ee4ec6bd641fec424c4142.Avatar.Strong",
"fa534c5a83ee4ec6bd641fec424c4142.Avatar.Fast",
"fa534c5a83ee4ec6bd641fec424c4142.Avatar.Heavy",
"fa534c5a83ee4ec6bd641fec424c4142.Avatar.CharFurv4GB",
"SLZ.BONELAB.Content.Avatar.Anime",
"fa534c5a83ee4ec6bd641fec424c4142.Avatar.CharTallv4"
]
try {
writeFileSync(file.latestFile, JSON.stringify(saveData, null, 4))
log('Successfully Patched Save!');
} catch (error) {
console.error(`Unable to write to save: ${error}`);
}
console.log('If any Errors occurred, please open an issue on the GitHub Repository (https://github.com/Grafaffel/bonelab-bodymall-fix)');
console.log('Press any key to exit...');
process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.on('data', process.exit.bind(process, 0));
})