fix arRPC

This commit is contained in:
smartfrigde 2024-01-28 15:10:45 +01:00
parent 037a26ef34
commit 613ea3f7b4
5 changed files with 110 additions and 91 deletions

View file

@ -1,16 +1,18 @@
const {readlink, readdir} = require("fs/promises"); const {readFile, readdir} = require("fs/promises");
const getProcesses = async () => { const getProcesses = async () =>
const pids = (await readdir("/proc")).filter((f) => !isNaN(+f)); (
return (
await Promise.all( await Promise.all(
pids.map((pid) => (
readlink(`/proc/${pid}/exe`).then( await readdir("/proc")
(path) => [+pid, path], ).map(
() => {} (pid) =>
+pid > 0 &&
readFile(`/proc/${pid}/cmdline`, "utf8").then(
(path) => [+pid, path.replaceAll("0", "")],
() => 0
) )
) )
) )
).filter((x) => x); ).filter((x) => x);
};
module.exports = {getProcesses}; module.exports = {getProcesses};

View file

@ -23,6 +23,8 @@ class RPCServer extends EventEmitter {
this.ipc = await new IPCServer(handlers); this.ipc = await new IPCServer(handlers);
this.ws = await new WSServer(handlers); this.ws = await new WSServer(handlers);
if (!process.argv.includes("--no-process-scanning") && !process.env.ARRPC_NO_PROCESS_SCANNING)
this.process = await new ProcessServer(handlers); this.process = await new ProcessServer(handlers);
return this; return this;
@ -33,6 +35,7 @@ class RPCServer extends EventEmitter {
socket.send({ socket.send({
cmd: "DISPATCH", cmd: "DISPATCH",
evt: "READY", evt: "READY",
nonce: 0,
data: { data: {
v: 1, v: 1,
@ -137,15 +140,23 @@ class RPCServer extends EventEmitter {
case "GUILD_TEMPLATE_BROWSER": case "GUILD_TEMPLATE_BROWSER":
case "INVITE_BROWSER": case "INVITE_BROWSER":
const {code} = args; const {code} = args;
const isInvite = cmd === "INVITE_BROWSER";
const callback = (isValid = true) => {
socket.send({ socket.send({
cmd, cmd,
data: { data: isValid
code ? {code}
: {
code: isInvite ? 4011 : 4017,
message: `Invalid ${isInvite ? "invite" : "guild template"} id: ${code}`
}, },
evt: isValid ? null : "ERROR",
nonce nonce
}); });
};
this.emit(cmd === "INVITE_BROWSER" ? "invite" : "guild-template", code); this.emit(isInvite ? "invite" : "guild-template", code, callback);
break; break;
case "DEEP_LINK": case "DEEP_LINK":

View file

@ -1,21 +1,16 @@
{ (() => {
const cb = () => {
let Dispatcher, let Dispatcher,
lookupAsset, lookupAsset,
lookupApp, lookupApp,
apps = {}; apps = {};
ArmCordRPC.listen(async (msg) => { ArmCordRPC.listen(async (msg) => {
console.warn(msg);
if (!Dispatcher) { if (!Dispatcher) {
let wpRequire; let wpRequire;
window.webpackChunkdiscord_app.push([[Symbol()], {}, (x) => (wpRequire = x)]); window.webpackChunkdiscord_app.push([[Symbol()], {}, (x) => (wpRequire = x)]);
window.webpackChunkdiscord_app.pop(); window.webpackChunkdiscord_app.pop();
const modules = wpRequire.c; const modules = wpRequire.c;
lookupAsset = Object.values(modules).find((m) => m.exports?.fetchAssetIds).exports.fetchAssetIds;
lookupApp = Object.values(modules).find((m) => m.exports?.fetchApplicationsRPC).exports
.fetchApplicationsRPC;
for (const id in modules) { for (const id in modules) {
const mod = modules[id].exports; const mod = modules[id].exports;
@ -33,6 +28,43 @@
if (Dispatcher) break; if (Dispatcher) break;
} }
const factories = wpRequire.m;
for (const id in factories) {
if (factories[id].toString().includes("getAssetImage: size must === [number, number] for Twitch")) {
const mod = wpRequire(id);
// fetchAssetIds
const _lookupAsset = Object.values(mod).find(
(e) => typeof e === "function" && e.toString().includes("APPLICATION_ASSETS_FETCH_SUCCESS")
);
if (_lookupAsset)
lookupAsset = async (appId, name) => (await _lookupAsset(appId, [name, undefined]))[0];
}
if (lookupAsset) break;
}
for (const id in factories) {
if (factories[id].toString().includes("APPLICATION_RPC(")) {
const mod = wpRequire(id);
// fetchApplicationsRPC
const _lookupApp = Object.values(mod).find((e) => {
if (typeof e !== "function") return;
const str = e.toString();
return str.includes(",coverImage:") && str.includes("INVALID_ORIGIN");
});
if (_lookupApp)
lookupApp = async (appId) => {
let socket = {};
await _lookupApp(socket, appId);
return socket.application;
};
}
if (lookupApp) break;
}
} }
if (msg.activity?.assets?.large_image) if (msg.activity?.assets?.large_image)
@ -53,10 +85,7 @@
const app = apps[appId]; const app = apps[appId];
if (!msg.activity.name) msg.activity.name = app.name; if (!msg.activity.name) msg.activity.name = app.name;
} }
Dispatcher.dispatch({type: "LOCAL_ACTIVITY_UPDATE", ...msg}); // set RPC status Dispatcher.dispatch({type: "LOCAL_ACTIVITY_UPDATE", ...msg}); // set RPC status
}); });
}; })();
cb();
setInterval(cb, 30 * 1000);
}

View file

@ -1,22 +0,0 @@
// What does this do?
// In case of faulty update of ArmCord we can quickly push an update to the user and possibly try to fix it
// This is completely optional and is disabled by default in settings
import {ipcRenderer} from "electron";
import {injectJS} from "../utils";
const patchEndpoint = "https://patch.armcord.app";
const version = ipcRenderer.sendSync("get-app-version", "app-version");
if (ipcRenderer.sendSync("shouldPatch")) {
document.addEventListener("DOMContentLoaded", function () {
fetch(`${patchEndpoint}/${version}/info.json`, {cache: "no-store"}) //lmao
.then((res) => res.json())
.then((res) => {
if (res.patch == true) {
console.log("Found a patch. Injecting...");
injectJS(`${patchEndpoint}/${version}/patch.js`);
} else {
console.log("No patches have been found.");
}
});
});
}

View file

@ -1,5 +1,4 @@
import "./bridge"; import "./bridge";
import "./patch";
import "./optimizer"; import "./optimizer";
import "./settings"; import "./settings";
import {ipcRenderer} from "electron"; import {ipcRenderer} from "electron";