This repository has been archived by the owner on Apr 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
index.js
382 lines (331 loc) · 15.5 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/*
// FpsUtils revision1.3 - Saegusa
// New iterations through player objects,
// Should be around 3x faster in process speed.
// Also added a bunch more commands and functions
// Read README.md for more info about how to use.
// Thanks: Bernkastel - PinkiePie for ideas.
*/
var config = require('./config.json');
const format = require('./format.js');
const fs = require('fs');
module.exports = function FpsUtils(dispatch) {
let DEBUG = config.debug || false;
let player,
cid,
model,
clss;
let state = 0,
lastState = 0,
hiddenPlayers = {},
hiddenIndividual = {};
let flags = {
hide: {
tanks: false,
healers: false,
dps: false
},
fireworks: false
};
const classes = config.classes;
function getClass(m) {
return (m % 100);
}
function handleCommands(event) {
let command = format.stripTags(event.message).split(' ');
if(command[0] !== '!fps')
return;
lastState = state;
if(command.length > 1) {
let arg = command[1];
switch(arg.toString()) {
// Set state to 0: Disabled.
case "0":
state = 0;
config.state = 0;
log('fps-utils optimization disabled by client.');
systemMsg('optimization disabled by user. [0]');
if(lastState > 2) {
// Display all hidden players.
for(let pl in hiddenPlayers) {
if(!hiddenIndividual[hiddenPlayers[pl].cid]) {
dispatch.toClient('S_SPAWN_USER', 3, hiddenPlayers[pl]);
}
}
}
break;
// Set state to 1: Only hide projectiles.
case "1":
state = 1;
config.state = 1;
log('fps-utils optimization set to stage 1, disabling skill particles.');
systemMsg('optimization set to remove skill particles. [1]');
if(lastState > 2) {
// Display all hidden players. EXCEPT HIDDEN INDIVIDUALS
for(let pl in hiddenPlayers) {
if(!hiddenIndividual[hiddenPlayers[pl].cid]) {
dispatch.toClient('S_SPAWN_USER', 3, hiddenPlayers[pl]);
}
}
}
break;
// Set state to 2: Hide all skill animations.
case "2":
state = 2;
config.state = 2;
log('fps-utils optimization set to stage 2, disabling skill animations.');
systemMsg('optimization set to remove skill animations. [2]');
// Spawn all players with disabled animations.
if(lastState > 2) {
for(let pl in hiddenPlayers) {
if(!hiddenIndividual[hiddenPlayers[pl].cid]) {
dispatch.toClient('S_SPAWN_USER', 3, hiddenPlayers[pl]);
}
}
}
break;
// Set state to 3: Hide all other players.
case "3":
state = 3;
config.state = 3;
log('fps-utils optimization set to stage 3, disabling other player models.');
systemMsg('optimization set to remove other player models [3]');
if(lastState < 3) {
// Hide all players on screen and disable spawn.
for(let pl in hiddenPlayers) {
if(!hiddenIndividual[hiddenPlayers[pl].cid]) {
dispatch.toClient('S_DESPAWN_USER', 2, {
target: hiddenPlayers[pl].cid,
type: 1
});
}
}
}
break;
// Save configuration to file.
case "save":
saveConfig();
break;
// Disable fireworks.
case "fireworks":
flags.fireworks = !flags.fireworks;
log('fps-utils toggled fireworks: ' + flags.fireworks);
systemMsg(`toggled fireworks: ${flags.fireworks}`);
break;
// Toggle individual classes on and off
case "hide":
if(command.length < 3) {
log('fps-utils missing arguments for command "hide"');
systemMsg(`missing arguments for command "hide" [dps, healers, tanks] or [username]`);
break;
} else {
let arg2 = command[2];
if(state < 3)
switch(arg2.toString()) {
// Hide all dps classes
case "dps":
log('fps-utils hiding dps classes');
systemMsg(`hiding dps classes.`);
flags.hide.dps = true;
for (let pl in hiddenPlayers) {
if((!hiddenPlayers[pl].block || !hiddenIndividual[hiddenPlayers[pl].cid]) && classes.dps.indexOf(getClass(hiddenPlayers[pl].model)) > -1) {
dispatch.toClient('S_DESPAWN_USER', 2, {
target: hiddenPlayers[pl].cid,
type: 1
});
}
}
break;
// Hide all healer classes
case "healers":
flags.hide.healers = true;
for (let pl in hiddenPlayers) {
if((!hiddenPlayers[pl].block || !hiddenIndividual[hiddenPlayers[pl].cid]) && classes.healers.indexOf(getClass(hiddenPlayers[pl].model)) > -1) {
dispatch.toClient('S_DESPAWN_USER', 2, {
target: hiddenPlayers[pl].cid,
type: 1
});
}
}
break;
// Hide all tank classes
case "tanks":
flags.hide.tanks = true;
for (let pl in hiddenPlayers) {
if(!hiddenIndividual[hiddenPlayers[pl].cid] && classes.tanks.indexOf(getClass(hiddenPlayers[pl].model)) > -1) {
dispatch.toClient('S_DESPAWN_USER', 2, {
target: hiddenPlayers[pl].cid,
type: 1
});
}
}
break;
// Argument is an individual name or not recognized.
default:
for(let pl in hiddenPlayers) {
if(hiddenPlayers[pl].name.toString().toLowerCase() === arg2.toString().toLowerCase()) {
systemMsg(`player ${hiddenPlayers[pl].name} is added to the hiding list.`)
hiddenIndividual[hiddenPlayers[pl].cid] = hiddenPlayers[pl];
config.hiddenPeople.push(hiddenPlayers[pl].name.toString());
dispatch.toClient('S_DESPAWN_USER', 2, {
target: hiddenPlayers[pl].cid,
type: 1
});
break;
} else {
continue;
}
}
break;
}
}
break;
// Try to respawn all hidden players included in show command.
case "show":
if(command.length < 3) {
log('fps-utils missing arguments for command "show"');
systemMsg(`missing arguments for command "show" [dps, healers, tanks] or [username]`);
break;
} else {
let arg2 = command[2];
if(state < 3) {
switch(arg2.toString()) {
case "dps":
case "healers":
case "tanks":
if(flags.hide[arg2.toString()]) {
flags.hide[arg2.toString()] = false;
log('fps-utils showing: ' + arg2);
systemMsg(`showing ${arg2}`);
for(let pl in hiddenPlayers) {
if(classes[arg2.toString()].indexOf(getClass(hiddenPlayers[pl].model)) > -1) {
if(!hiddenIndividual[hiddenPlayers[pl].cid])
dispatch.toClient('S_SPAWN_USER', 3, hiddenPlayers[pl]);
}
}
}
break;
default:
// Individuals or unkown handler.
for(let pl in hiddenIndividual) {
if(arg2.toString().toLowerCase() === hiddenIndividual[pl].name.toString().toLowerCase()) {
systemMsg(`showing player ${hiddenIndividual[pl].name}.`);
config.hiddenPeople.splice(config.hiddenPeople.indexOf(hiddenPlayers[pl].name), 1);
dispatch.toClient('S_SPAWN_USER', 3, hiddenIndividual[pl]);
delete hiddenIndividual[pl];
}
}
break;
}
}
}
break;
// List the players in individuals list.
case "list":
let hiddenArray = [];
for(let pl in hiddenIndividual) {
hiddenArray.push(hiddenIndividual[pl].name);
}
systemMsg(`Manually hidden players: ${hiddenArray}`);
break;
// Command not recognized
default:
systemMsg('Command not recognized. use [!fps help] for a list of available commands');
break;
}
return false;
} else {
return false;
}
}
function log(msg) {
if(DEBUG) console.log('[fps-utils] ' + msg);
}
function systemMsg(msg) {
dispatch.toClient('S_CHAT', 1, {
channel: 24,
authorID: 0,
unk1: 0,
gm: 0,
unk2: 0,
authorName: '',
message: ' (fps-utils) ' + msg
});
}
function saveConfig() {
fs.writeFile('./config.json', config, 'utf8', (err) => { if(!err) log("config file overwritten successfully"); });
}
dispatch.hook('S_LOGIN', 2, (event) => {
({cid, model} = event);
player = event.name;
clss = getClass(event.model);
state = config.state || 0;
});
dispatch.hook('S_LOAD_TOPO', 1, (event) => {
// Refresh the hide list upon teleport or zone change.
hiddenPlayers = {};
});
dispatch.hook('S_SPAWN_USER', 3, (event) => {
// Add players in proximity of user to possible hide list.
hiddenPlayers[event.cid] = event;
// Check the state or if the individual is hidden.
if(state === 3 || hiddenIndividual[event.cid]) {
return false;
}
// Hide dps enabled, remove dps characters;
if(flags.hide.dps && classes.dps.indexOf(getClass(event.model)) > -1) {
return false;
}
// Hide tanks enabled, remove tank characters;
if(flags.hide.tanks && classes.tanks.indexOf(getClass(event.model)) > -1) {
return false;
}
// Why would you want this on, seriously...
if(flags.hide.healers && classes.healers.indexOf(getClass(event.model)) > -1) {
return false;
}
});
dispatch.hook('S_DESPAWN_USER', 2, (event) => {
delete hiddenPlayers[event.target];
if(state === 3 || hiddenIndividual[event.target]) {
return false;
}
});
dispatch.hook('S_SPAWN_NPC', 3, (event) => {
if(!flags.fireworks) {
if(event.huntingZoneId === 1023 && (event.templateId === 60016000 || event.templateId === 80037000))
return false;
}
});
dispatch.hook('S_USER_LOCATION', 1, (event) => {
// Update locations of every player in case we need to spawn them.
hiddenPlayers[event.target].x = event.x2;
hiddenPlayers[event.target].y = event.y2;
hiddenPlayers[event.target].z = event.z2;
hiddenPlayers[event.target].w = event.w;
if(state > 2 || hiddenIndividual[event.target]) {
return false;
}
});
dispatch.hook('S_ACTION_STAGE', 1, (event) => {
// If state is higher than state1 remove all skill animations.
if(state > 1 && (hiddenPlayers[event.source] || hiddenIndividual[event.source]))
return false;
});
dispatch.hook('S_ACTION_END', 1, (event) => {
// If we're removing skill animations we should ignore the end packet too.
if(state > 1 && (hiddenPlayers[event.source] || hiddenIndividual[event.source]))
return false;
});
dispatch.hook('S_START_USER_PROJECTILE', 1, (event) => {
// State 1 and higher ignores particles and projectiles so we're ignoring this.
if(state > 0 && (hiddenPlayers[event.source] || hiddenIndividual[event.source]))
return false;
});
dispatch.hook('S_SPAWN_PROJECTILE', 1, (event) => {
// Ignore the projectile spawn if enabled in state.
if(state > 0 && (hiddenPlayers[event.source] || hiddenIndividual[event.source]))
return false;
});
dispatch.hook('C_CHAT', 1, handleCommands);
}