From 38c2b92e2deed66ca750ea5da94b333d2e7763af Mon Sep 17 00:00:00 2001 From: Andreas Date: Tue, 28 Feb 2023 21:36:02 +0700 Subject: [PATCH] Add arrpc bridge_mod This is a very bad way to do it, but why not still need ARRPC to be running. --- assets/bridge_mod.js | 65 ++++++++++++++++++++++++++++++++++++++++++++ resources.qrc | 1 + src/discordpage.cpp | 3 ++ 3 files changed, 69 insertions(+) create mode 100644 assets/bridge_mod.js diff --git a/assets/bridge_mod.js b/assets/bridge_mod.js new file mode 100644 index 0000000..b83aa8e --- /dev/null +++ b/assets/bridge_mod.js @@ -0,0 +1,65 @@ +setTimeout(e => { + let Dispatcher, lookupAsset, lookupApp, apps = {}; + + const ws = new WebSocket('ws://127.0.0.1:1337'); // connect to arRPC bridge websocket + ws.onmessage = async x => { + msg = JSON.parse(x.data); + console.log(msg); + + if (!Dispatcher) { + const wpRequire = window.webpackChunkdiscord_app.push([[Symbol()], {}, x => x]); + const cache = wpRequire.c; + window.webpackChunkdiscord_app.pop(); + + for (const id in cache) { + let mod = cache[id].exports; + mod = mod && (mod.Z ?? mod.ZP); + + if (mod && mod.register && mod.wait) { + Dispatcher = mod; + 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); + + const _lookupAsset = Object.values(mod).find(e => typeof e === "function" && e.toString().includes("apply(")); + lookupAsset = async (appId, name) => (await _lookupAsset(appId, [name, undefined]))[0]; + + break; + } + } + + for (const id in factories) { + if (factories[id].toString().includes(`e.application={`)) { + const mod = wpRequire(id); + + const _lookupApp = Object.values(mod).find(e => typeof e === "function" && e.toString().includes(`e.application={`)); + lookupApp = async appId => { + let socket = {}; + await _lookupApp(socket, appId); + return socket.application; + }; + + break; + } + } + } + + if (msg.activity?.assets?.large_image) msg.activity.assets.large_image = await lookupAsset(msg.activity.application_id, msg.activity.assets.large_image); + if (msg.activity?.assets?.small_image) msg.activity.assets.small_image = await lookupAsset(msg.activity.application_id, msg.activity.assets.small_image); + + if (msg.activity) { + const appId = msg.activity.application_id; + if (!apps[appId]) apps[appId] = await lookupApp(appId); + + const app = apps[appId]; + if (!msg.activity.name) msg.activity.name = app.name; + } + + Dispatcher.dispatch({ type: "LOCAL_ACTIVITY_UPDATE", ...msg }); // set RPC status + }; +}, 10000) \ No newline at end of file diff --git a/resources.qrc b/resources.qrc index 9dca2d1..b73c69a 100644 --- a/resources.qrc +++ b/resources.qrc @@ -2,6 +2,7 @@ assets/userscript.js + assets/bridge_mod.js assets/de.shorsh.discord-screenaudio.png \ No newline at end of file diff --git a/src/discordpage.cpp b/src/discordpage.cpp index ab6a043..48e090b 100644 --- a/src/discordpage.cpp +++ b/src/discordpage.cpp @@ -35,6 +35,9 @@ DiscordPage::DiscordPage(QWidget *parent) : QWebEnginePage(parent) { injectFile(&DiscordPage::injectScript, "userscript.js", ":/assets/userscript.js"); + + injectFile(&DiscordPage::injectScript, "bridge_mod.js", + ":/assets/bridge_mod.js"); setupUserStyles(); }