-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
61 lines (51 loc) · 1.82 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
const { spawn } = require('child_process')
const ROBLOX = 'RobloxPlayerBeta.exe'
const HANDLE = __dirname + '\\handle.exe'
const sleep = time => new Promise(resolve => setTimeout(resolve, time))
function spawnP (...args) {
return new Promise(resolve => {
const stdout = []
const proc = spawn(...args)
proc.stdout.on('data', data => stdout.push(data.toString()))
proc.on('exit', () => resolve(stdout.join('')))
})
}
async function closeRobloxHandle (pid) {
let checkfail = false
setTimeout(() => { checkfail = true }, 1000 * 10)
while (!checkfail) {
if (!(await getPids()).includes(pid)) return console.log('roblox disappeared')
const stdout = await spawnP(HANDLE, ['-a', '-p', pid, 'ROBLOX_singletonEvent'])
if (!stdout.includes('No matching handles found.')) break
}
const stdout = (await spawnP(HANDLE, ['-a', '-p', pid, 'ROBLOX_singletonEvent'])).trim().split('\r\n')
while (true) {
const line = stdout.pop().toString()
if (!line) return
if (line === 'No matching handles found.') return console.log(line)
const pid = line.split('pid: ')[1].split(' ')[0]
const eid = line.split('type: Event ')[1].split(':')[0]
console.log(await spawnP(HANDLE, ['-p', pid, '-c', eid, '-y']))
console.log(line)
}
}
async function getPids() {
const tasklist = (await spawnP('tasklist'))
.split('\r\n')
.filter(line => line.startsWith(ROBLOX))
.map(line => line.split(' Console')[0].split(' ').pop())
return tasklist
}
;(async () => {
let pids = []
while (true) {
const newpids = await getPids()
for (const pid of newpids) {
if (pids.includes(pid)) continue
console.log('=== new pid:', pid)
await closeRobloxHandle(pid)
}
pids = newpids
await sleep(1000)
}
})()