Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 deletions src/process/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ export default class ProcessServer {

// log(`got processed in ${(performance.now() - startTime).toFixed(2)}ms`);

for (const [ pid, _path ] of processes) {
for (const [ pid, _path, args ] of processes) {
const path = _path.toLowerCase().replaceAll('\\', '/');
const toCompare = [ path.split('/').pop(), path.split('/').slice(-2).join('/') ];
const toCompare = [];
const splitPath = path.split('/');
for (let i = 1; i < splitPath.length; i++) {
toCompare.push(splitPath.slice(-i).join('/'));
}

for (const p of toCompare.slice()) { // add more possible tweaked paths for less false negatives
toCompare.push(p.replace('64', '')); // remove 64bit identifiers-ish
Expand All @@ -40,31 +44,37 @@ export default class ProcessServer {
}

for (const { executables, id, name } of DetectableDB) {
if (executables?.some(x => !x.isLauncher && toCompare.some(y => x.name === y))) {
if (executables?.some(x => {
if (x.is_launcher) return false;
if (x.name[0] === '>' ? x.name.substring(1) !== toCompare[0] : !toCompare.some(y => x.name === y)) return false;
if (x.arguments) return args.join(" ").indexOf(x.arguments) > -1;
return true;
})) {
names[id] = name;
pids[id] = pid;

ids.push(id);
if (!timestamps[id]) {
log('detected game!', name);
timestamps[id] = Date.now();

this.handlers.message({
socketId: id
}, {
cmd: 'SET_ACTIVITY',
args: {
activity: {
application_id: id,
name,
timestamps: {
start: timestamps[id]
}
},
pid
}
});
}

// Resending this on evry scan is intentional, so that in the case that arRPC scans processes before Discord, existing activities will be sent
this.handlers.message({
socketId: id
}, {
cmd: 'SET_ACTIVITY',
args: {
activity: {
application_id: id,
name,
timestamps: {
start: timestamps[id]
}
},
pid
}
});
}
}
}
Expand All @@ -73,7 +83,7 @@ export default class ProcessServer {
if (!ids.includes(id)) {
log('lost game!', names[id]);
delete timestamps[id];

this.handlers.message({
socketId: id
}, {
Expand Down
2 changes: 1 addition & 1 deletion src/process/native/linux.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { readdir, readFile } from "fs/promises";
export const getProcesses = async () => (await Promise.all(
(await readdir("/proc")).map(pid =>
(+pid > 0) && readFile(`/proc/${pid}/cmdline`, 'utf8')
.then(path => [+pid, path.replaceAll('0', '')], () => 0)
.then(path => [+pid, path.split("\0")[0], path.split("\0").slice(1)], () => 0)
)
)).filter(x => x);