forked from TeraProxy/Cosplayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
406 lines (366 loc) · 11.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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
// Contains code from elin-magic by Pinkie Pie https://github.com/pinkipi
// Contains code from from elin-magic's extension cosplay-ex by Bernkastel https://github.com/Bernkastel-0
// Version 1.3.0
const Command = require('command'),
Scanner = require('./scanner'),
CONTRACT_DRESSING_ROOM = 76
module.exports = function Cosplayer(dispatch) {
Scanner(dispatch)
let db = Scanner.db,
cid = null,
player,
external = null,
userDefaultAppearance,
inDressup = false,
inDye = false,
lastTooltip = 0,
lastTooltipTime = 0,
reapplyTimeout = null,
marrow = false
// ################## //
// ### Save Stuff ### //
// ################## //
const path = require('path')
fs = require('fs')
let presets = {},
nametags = {},
presetTimeout = null,
nametagTimeout = null,
presetLock = false,
nametagLock = false
try { presets = require('./presets.json') }
catch(e) { presets = {} }
try { nametags = require('./nametags.json') }
catch(e) { nametags = {} }
function presetUpdate() {
clearTimeout(presetTimeout)
presetTimeout = setTimeout(presetSave, 1000)
}
function nametagUpdate() {
clearTimeout(nametagTimeout)
nametagTimeout = setTimeout(nametagSave, 1000)
}
function presetSave() {
if(presetLock) {
presetUpdate()
return
}
presetLock = true
fs.writeFile(path.join(__dirname, 'presets.json'), JSON.stringify(presets, null, 4), err => {
presetLock = false
})
}
function nametagSave() {
if(nametagLock) {
nametagUpdate()
return
}
nametagLock = true
fs.writeFile(path.join(__dirname, 'nametags.json'), JSON.stringify(nametags, null, 4), err => {
nametagLock = false
})
}
// ############# //
// ### Magic ### //
// ############# //
dispatch.hook('S_LOGIN', 1, event => {
({cid} = event)
player = event.name
inDressup = false
inDye = false
if(presets[player] && presets[player].id != 0) {
external = presets[player]
external.id = cid
}
})
dispatch.hook('S_GET_USER_LIST', 2, event => {
for (let index in event.characters) {
if(presets[event.characters[index].name] && presets[event.characters[index].name].id != 0) {
event.characters[index].face = presets[event.characters[index].name].face
event.characters[index].hairAdornment = presets[event.characters[index].name].hairAdornment
event.characters[index].mask = presets[event.characters[index].name].mask
event.characters[index].back = presets[event.characters[index].name].back
event.characters[index].weaponSkin = presets[event.characters[index].name].weaponSkin
event.characters[index].weaponEnchant = presets[event.characters[index].name].weaponEnchant
event.characters[index].costume = presets[event.characters[index].name].costume
event.characters[index].unk35 = presets[event.characters[index].name].costumeDye
}
}
return true
})
dispatch.hook('S_USER_EXTERNAL_CHANGE', 1, event => {
if(event.id.equals(cid)) {
userDefaultAppearance = Object.assign({}, event)
if(presets[player] && (presets[player].id != 0)) {
dispatch.toClient('S_USER_EXTERNAL_CHANGE', 1, external)
if(nametags[player] && (nametags[player].length != 0)) updateNametag(nametags[player])
presets[player] = external
presetUpdate()
if(external.enable == 0) {
dispatch.toClient('S_ABNORMALITY_BEGIN', 2, {
target: cid,
source: cid,
id: 7777008,
duration: 864000000,
unk: 0,
stacks: 1,
unk2: 0,
})
}
return false
}
else {
external = Object.assign({}, event)
presets[player] = Object.assign({}, external)
presets[player].id = 0
presetUpdate()
}
}
})
dispatch.hook('S_ABNORMALITY_BEGIN', 2, (event) => {
if(presets[player] && (presets[player].id != 0) && (external.enable == 1) && (event.id == 7777008)) {
setTimeout(function() {
dispatch.toClient('S_ABNORMALITY_END', 1, {
target: cid,
id: 7777008,
})
}, 1000)
}
if(event.target == cid && event.id == 10155130) { // Ragnarok
dispatch.toClient('S_USER_EXTERNAL_CHANGE', 1, external);
if(nametags[player] && (nametags[player].length != 0)) updateNametag(nametags[player])
}
})
dispatch.hook('S_ABNORMALITY_END', 1, (event) =>{
if(event.target == cid) {
if(event.id == 10155130) { // Ragnarok
dispatch.toClient('S_USER_EXTERNAL_CHANGE', 1, external);
if(nametags[player] && (nametags[player].length != 0)) updateNametag(nametags[player])
}
}
})
dispatch.hook('C_ITEM_COLORING_SET_COLOR', 1, (event) => {
let color = Number('0x'+event.alpha.toString(16)+event.red.toString(16)+event.green.toString(16)+event.blue.toString(16))
external.costumeDye = color
presets[player] = external
presetUpdate()
inDye = true
})
dispatch.hook('S_REQUEST_CONTRACT', 1, event => {
if(event.type == CONTRACT_DRESSING_ROOM) {
inDressup = true
let items = []
for(let slot in db)
for(let item of db[slot])
items.push({
unk: 0,
item
})
dispatch.toClient('S_REQUEST_INGAMESTORE_PRODUCT_DETAIL', 1, {items})
}
})
dispatch.hook('C_CANCEL_CONTRACT', 1, event => {
if(inDye) {
inDye = false
dispatch.toClient('S_USER_EXTERNAL_CHANGE', 1, external)
if(nametags[player] && (nametags[player].length != 0)) updateNametag(nametags[player])
presets[player] = external
presetUpdate()
}
})
dispatch.hook('S_CANCEL_CONTRACT', 1, event => {
if(inDressup) {
inDressup = false
process.nextTick(() => { dispatch.toClient('S_USER_EXTERNAL_CHANGE', 1, external) })
if(nametags[player] && (nametags[player].length != 0)) updateNametag(nametags[player])
presets[player] = external
presetUpdate()
}
})
dispatch.hook('C_REQUEST_NONDB_ITEM_INFO', 1, event => {
if(inDressup) {
let time = Date.now()
// The only way to tell an item was clicked in the Dressing Room is to watch for this packet twice in a row.
// Unequipping is impossible to detect, unfortunately.
if(lastTooltip == (lastTooltip = event.item) && time - lastTooltipTime < 10) equipped(event.item)
lastTooltipTime = time
dispatch.toClient('S_REPLY_NONDB_ITEM_INFO', 1, {
item: event.item,
unk: 0
})
return false
}
})
dispatch.hook('S_UNICAST_TRANSFORM_DATA', 'raw', (code, data) => {
marrow = true
reapplyTimeout = setTimeout(reapplyPreset, 19000)
})
dispatch.hook('S_CREATURE_LIFE', 1, event => {
if(marrow && event.target.equals(cid) && event.alive == false) {
reapplyTimeout = setTimeout(reapplyPreset, 1000)
}
})
// ######################## //
// ### Helper Functions ### //
// ######################## //
function equipped(item) {
external.id = cid
presets[player] = external
presetUpdate()
for(let slot in db) {
if(db[slot].includes(item)) {
external[slot] = item
break
}
}
}
function colorThatShit() {
dispatch.toClient('S_REQUEST_CONTRACT', 1, {
senderId: cid,
recipientId: 0,
type: 42,
id: 999999,
unk3: 0,
time: 0,
senderName: player,
recipientName: '',
data: ''
})
dispatch.toClient('S_ITEM_COLORING_BAG', 1, {
unk: 40,
unk1: 593153247,
unk2: 0,
item: external.costume,
unk3: 0,
dye: 169087,
unk4: 0,
unk5: 0
})
}
function changePantsu() {
if(external.enable == 1) {
dispatch.toClient('S_ABNORMALITY_BEGIN', 2, {
target: cid,
source: cid,
id: 7777008, // self-confidence abnormality
duration: 864000000, // 10 days
unk: 0,
stacks: 1,
unk2: 0
})
external.enable = 0
presets[player] = external
presetUpdate()
}
else if(external.enable == 0) {
dispatch.toClient('S_ABNORMALITY_END', 1, {
target: cid,
id: 7777008 // self-confidence abnormality
})
external.enable = 1
presets[player] = external
presetUpdate()
}
}
function reapplyPreset() {
clearTimeout(reapplyTimeout)
if(presets[player] && presets[player].id != 0) {
external = presets[player]
external.id = cid
dispatch.toClient('S_USER_EXTERNAL_CHANGE', 1, external)
if(nametags[player] && (nametags[player].length != 0)) updateNametag(nametags[player])
marrow = false
}
}
function updateNametag(nametag) {
dispatch.toClient('S_ITEM_CUSTOM_STRING', 1, {owner: cid, items: [{item: external.costume, text: nametag}]})
if(nametag == player) nametags[player] = ""
else nametags[player] = nametag
nametagUpdate()
}
// ################# //
// ### Chat Hook ### //
// ################# //
const command = Command(dispatch)
command.add('cosplay', (param, value) => {
if (param == 'dye') {
colorThatShit()
presets[player] = external
presetUpdate()
}
else if (param == 'dyergb' && value != null) {
external.costumeDye = parseInt(value, 16)
dispatch.toClient('S_USER_EXTERNAL_CHANGE', 1, external)
presets[player] = external
presetUpdate()
}
else if (param == 'weapon' && value != null) {
external.weaponSkin = Number(value)
dispatch.toClient('S_USER_EXTERNAL_CHANGE', 1, external)
presets[player] = external
presetUpdate()
}
else if (param == 'costume' && value != null) {
external.costume = Number(value)
dispatch.toClient('S_USER_EXTERNAL_CHANGE', 1, external)
presets[player] = external
presetUpdate()
}
else if (param == 'back' && value != null) {
external.back = Number(value)
dispatch.toClient('S_USER_EXTERNAL_CHANGE', 1, external)
presets[player] = external
presetUpdate()
}
else if (param == 'mask' && value != null) {
external.mask = Number(value)
dispatch.toClient('S_USER_EXTERNAL_CHANGE', 1, external)
presets[player] = external
presetUpdate()
}
else if (param == 'hair' && value != null) {
external.hairAdornment = Number(value)
dispatch.toClient('S_USER_EXTERNAL_CHANGE', 1, external)
presets[player] = external
presetUpdate()
}
else if (param == 'innerwear' && value != null) {
external.innerwear = Number(value)
dispatch.toClient('S_USER_EXTERNAL_CHANGE', 1, external)
presets[player] = external
presetUpdate()
}
else if (param == 'pantsu') {
changePantsu()
}
else if (param == 'enchant' && value != null) {
external.weaponEnchant = Number(value)
dispatch.toClient('S_USER_EXTERNAL_CHANGE', 1, external)
presets[player] = external
presetUpdate()
}
else if (param == 'tag' && value != null) {
updateNametag(value)
}
else if (param == 'undress') {
dispatch.toClient('S_USER_EXTERNAL_CHANGE', 1, userDefaultAppearance)
external = Object.assign({}, userDefaultAppearance)
presets[player].id = 0
presetUpdate()
}
else command.message('Commands:<br>'
+ ' "cosplay dye" (change dye with the ingame slider tool),<br>'
+ ' "cosplay dyergb \'[0-255 0-255 0-255]\'" (change dye to rgb value, e.g. "cosplay dyergb \'214 153 204\'"),<br>'
+ ' "cosplay weapon [id]" (change your weapon skin to id, e.g. "cosplay weapon 99272"),<br>'
+ ' "cosplay costume [id]" (change your costume skin to id, e.g. "cosplay costume 180722"),<br>'
+ ' "cosplay back [id]" (change your back skin to id, e.g. "cosplay back 180081"),<br>'
+ ' "cosplay mask [id]" (change your mask skin to id, e.g. "cosplay mask 181563"),<br>'
+ ' "cosplay hair [id]" (change your hair adornment to id, e.g. "cosplay hair 252972"),<br>'
+ ' "cosplay innerwear [id]" (change your innerwear skin to id, e.g. "cosplay innerwear 97936"),<br>'
+ ' "cosplay pantsu" (switch between innerwear and costume),<br>'
+ ' "cosplay enchant [0-15]" (change weapon enchant glow, e.g. "cosplay enchant 13"),<br>'
+ ' "cosplay tag [name]" (change name tag on costume, e.g. "cosplay tag \'I love Spacecats\'"),<br>'
+ ' "cosplay undress" (goes back to your actual look)'
)
})
}