forked from QuentinGruber/h1z1-string-finder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathh1z1-string-finder.js
41 lines (37 loc) · 1.18 KB
/
h1z1-string-finder.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
const locale = require("soe-locale");
const fs = require("fs");
const Jenkins = require("hash-jenkins");
const { program } = require("commander");
const strings = locale.parseFromBuffer(
fs.readFileSync("Locale/en_us_data.dat"),
fs.readFileSync("Locale/en_us_data.dir")
);
function lookupString(stringId) {
var hash = Jenkins.lookup2("Global.Text." + stringId);
if (hash in strings) {
return strings[hash].string;
} else {
return "[STRING #" + stringId + "NOT FOUND]";
}
}
program.option("-a, --all", "log all strings");
program.option("-j, --json", "log all strings in a .json file");
program.parse(process.argv);
if (program.json) {
const stringList = [];
Object.keys(strings).forEach((string, stringid) => {
stringList.push({ id: stringid, text: lookupString(stringid) });
});
fs.writeFileSync("strings.json", JSON.stringify(stringList));
} else {
if (program.all) {
Object.keys(strings).forEach((string, stringid) => {
console.log(`String ID #${stringid}: ${lookupString(stringid)}`);
});
} else {
const { args } = program.parse(process.argv);
args.forEach((arg) => {
console.log(`String ID #${arg}: ${lookupString(arg)}`);
});
}
}