forked from aperpen/clash-royale-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
replay.js
75 lines (70 loc) · 2.25 KB
/
replay.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
const fs = require('fs')
const prettyjson = require('prettyjson')
const consoleUtil = require('./utils/console')
const config = require('./config')
const packets = require('./logic/packets')
const plugins = require('./logic/plugins')
const savedSessions = fs.readdirSync(config.savePath).sort()
if (savedSessions.length > 0) {
consoleUtil
.prompt([
{
type: 'list',
name: 'session',
message: 'Select saved session',
choices: savedSessions,
pageSize: 10
},
{
type: 'list',
name: 'message',
message: 'Select packet ID to replay',
pageSize: 15,
choices: answers => {
let messages = []
let files = fs.readdirSync(config.savePath + '/' + answers.session)
for (let file of files) {
let code = file.split(/-|\./).shift()
if (messages.indexOf(code) === -1) messages.push(code)
}
return messages
.filter(message => packets[message] !== undefined)
.map(message => {
return {
name: packets[message].name,
value: message
}
})
}
}
])
.then(answers => {
consoleUtil.setState(consoleUtil.states.REPLAYING)
if (typeof packets[answers.message].decode == 'function') {
let path = config.savePath + '/' + answers.session
let files = fs.readdirSync(path)
.filter(file => {
let code = file.split(/-|\./).shift()
return code === answers.message
})
.sort()
.reverse()
for (let file of files) {
console.log('[*] Replaying', file)
let data = packets[answers.message].decode(Buffer.from(fs.readFileSync(path + '/' + file, { encoding: 'hex' }), 'hex'))
if(!packets[answers.message].hidden) {
console.log(prettyjson.render(data))
}
if (typeof plugins[answers.message].handle == 'function') {
plugins[answers.message].handle(this, data)
}
}
} else {
console.log('[!] Selected packet has not decode function')
process.exit(0)
}
})
} else {
console.log('[!] No saved sessions found')
process.exit(0)
}