This repository has been archived by the owner on Aug 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
107 lines (84 loc) · 2.97 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
const UI = require("../ui");
const bodyParser = require("../ui/node_modules/body-parser");
const globalShortcut = global.TeraProxy.GUIMode ? require("electron").globalShortcut : null;
module.exports = function Atlas(mod) {
const ui = UI(mod);
const citiesConfig = require("./cities");
const citiesNames = new Map();
let player = null;
mod.game.initialize("inventory");
mod.game.on("enter_character_lobby", async () => applyCitiesNames());
mod.command.add("atlas", {
"hotkey": arg => {
if (!arg) {
mod.command.message(`Current hotkey: ${mod.settings.hotkey}`);
} else {
if (arg.toLowerCase() !== mod.settings.hotkey.toLowerCase()) {
const hotkey = arg.toLowerCase().split("+").map(w => w[0].toUpperCase() + w.substr(1)).join("+");
try {
globalShortcut.register(hotkey, () => ui.open());
globalShortcut.unregister(mod.settings.hotkey);
mod.settings.hotkey = hotkey;
} catch (e) {
return mod.command.message(`Invalid hotkey: ${hotkey}`);
}
}
mod.command.message(`New hotkey: ${mod.settings.hotkey}`);
}
},
"$none": () => ui.open()
});
mod.hook("S_SPAWN_ME", 3, event => { player = event; });
mod.hook("C_PLAYER_LOCATION", 5, event => { player = event; });
ui.use((request, response, next) => {
response.header("Access-Control-Allow-Origin", "*");
response.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
ui.use(bodyParser.json({ "limit": "50mb" }));
ui.use(bodyParser.urlencoded({ "extended": true }));
ui.use(UI.static(`${__dirname}/ui`));
ui.post("/getTitle", (request, response) => {
applyCitiesNames();
response.json({ "title": `${citiesNames.get(1) || "World"} [${mod.settings.hotkey.replaceAll("+", " + ")}]` });
});
ui.post("/getCities", (request, response) => {
const cities = [];
citiesConfig.forEach(city => {
const entry = { "name": "", "available": 0, ...city };
const items = mod.game.inventory.findAll(city.itemId);
if (items.length !== 0) {
entry.available = items[0].amount;
}
if (citiesNames.has(city.id)) {
entry.name = citiesNames.get(city.id);
cities.push(entry);
}
});
response.json({ cities });
});
ui.post("/useItem", (request, response) => {
if (!player || !request.body || !request.body.itemId) return;
mod.send("C_USE_ITEM", 3, {
"gameId": mod.game.me.gameId,
"id": request.body.itemId,
"amount": 1,
"loc": player.loc,
"w": player.w,
"unk4": true
});
response.json({});
});
async function applyCitiesNames() {
if (citiesNames.size !== 0) return;
const citiesIds = [];
citiesConfig.forEach(city => citiesIds.push(city.id));
(await mod.queryData("/StrSheet_Region/String@id=?", [[1, ...citiesIds]], true))
.forEach(res => citiesNames.set(res.attributes.id, res.attributes.string));
}
globalShortcut.register(mod.settings.hotkey, () => ui.open());
this.destructor = () => {
globalShortcut.unregister(mod.settings.hotkey);
mod.command.remove("atlas");
};
};