-
Notifications
You must be signed in to change notification settings - Fork 5
/
utils.js
77 lines (63 loc) · 1.85 KB
/
utils.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
"use strict";
const fs = require("fs");
const journalPath = require("path").join(__dirname, "journal.json");
let saveTimer, customLocations;
function save() {
try { fs.writeFileSync(journalPath, JSON.stringify(customLocations)); }
catch(e) { console.error("failed to write custom location", e); }
}
function queueSave() {
clearTimeout(saveTimer);
saveTimer = setTimeout(save, 1e4);
}
try { customLocations = require(journalPath); }
catch(_) {
customLocations = [];
save();
}
const initCtx = mod => {
const _ = {};
_.cmd = mod.command;
_.send = mod.send.bind(mod);
_.enabled = true;
_.currentContract =
_.newCustom =
_.serverLocations =
_.customLocations =
_.gameId =
_.tpTo = void (_.slotAtlas = -1);
return _;
};
const makeHook = (_, ctx) => {
const hook = _.hook;
return function() { hook.apply(_, arguments).__self = ctx; };
};
const locationSort = (a, b) => a.name.localeCompare(b.name);
const newLocation = (loc, ctx) => ({
zone: loc.zone,
x: loc.x,
y: loc.y,
z: loc.z,
name: ctx.newCustom
});
const makeCustom = loc => ({
unk: 0,
zone: loc.zone,
x: loc.x,
y: loc.y,
z: loc.z,
name: ~loc.name.indexOf("\t") ? loc.name : loc.name + "\t"
});
const getCustomLocations = () => customLocations.map(makeCustom);
const atlasIds = new Set([5250, 60486, 60487, 60488, 60489, 60490, 81186, 100701, 100705, 100719, 100721, 139112, 139162, 139187, 139696, 139737, 149035, 149296, 149307, 149336, 149489, 166598, 166599, 166600, 166601, 166602, 166603, 166687, 166688, 166689, 166690, 166691, 166692, 170002, 177339, 181116, 186786, 200528, 201024, 210536, 212782, 213302, 213396, 216000, 220219, 220358, 221635, 222674, 854563, 854564, 854565, 854566, 854567, 854568]);
module.exports = {
initCtx,
makeHook,
atlasIds,
queueSave,
newLocation,
journalPath,
locationSort,
customLocations,
getCustomLocations
};