mirror of
				https://github.com/smartfrigde/armcord.git
				synced 2024-08-14 23:56:58 +00:00 
			
		
		
		
	fix arRPC
This commit is contained in:
		
							parent
							
								
									037a26ef34
								
							
						
					
					
						commit
						613ea3f7b4
					
				
					 5 changed files with 110 additions and 91 deletions
				
			
		|  | @ -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}; | ||||||
|  |  | ||||||
|  | @ -23,7 +23,9 @@ 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); | ||||||
|             this.process = await new ProcessServer(handlers); | 
 | ||||||
|  |             if (!process.argv.includes("--no-process-scanning") && !process.env.ARRPC_NO_PROCESS_SCANNING) | ||||||
|  |                 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; | ||||||
|                 socket.send({ |  | ||||||
|                     cmd, |  | ||||||
|                     data: { |  | ||||||
|                         code |  | ||||||
|                     }, |  | ||||||
|                     nonce |  | ||||||
|                 }); |  | ||||||
| 
 | 
 | ||||||
|                 this.emit(cmd === "INVITE_BROWSER" ? "invite" : "guild-template", code); |                 const isInvite = cmd === "INVITE_BROWSER"; | ||||||
|  |                 const callback = (isValid = true) => { | ||||||
|  |                     socket.send({ | ||||||
|  |                         cmd, | ||||||
|  |                         data: isValid | ||||||
|  |                             ? {code} | ||||||
|  |                             : { | ||||||
|  |                                   code: isInvite ? 4011 : 4017, | ||||||
|  |                                   message: `Invalid ${isInvite ? "invite" : "guild template"} id: ${code}` | ||||||
|  |                               }, | ||||||
|  |                         evt: isValid ? null : "ERROR", | ||||||
|  |                         nonce | ||||||
|  |                     }); | ||||||
|  |                 }; | ||||||
|  | 
 | ||||||
|  |                 this.emit(isInvite ? "invite" : "guild-template", code, callback); | ||||||
|                 break; |                 break; | ||||||
| 
 | 
 | ||||||
|             case "DEEP_LINK": |             case "DEEP_LINK": | ||||||
|  |  | ||||||
|  | @ -1,62 +1,91 @@ | ||||||
| { | (() => { | ||||||
|     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; | ||||||
|                     if (!mod?.__esModule) continue; |                 if (!mod?.__esModule) continue; | ||||||
| 
 | 
 | ||||||
|                     for (const prop in mod) { |                 for (const prop in mod) { | ||||||
|                         if (!mod.hasOwnProperty(prop)) continue; |                     if (!mod.hasOwnProperty(prop)) continue; | ||||||
| 
 | 
 | ||||||
|                         const candidate = mod[prop]; |                     const candidate = mod[prop]; | ||||||
|                         if (candidate && candidate.register && candidate.wait) { |                     if (candidate && candidate.register && candidate.wait) { | ||||||
|                             Dispatcher = candidate; |                         Dispatcher = candidate; | ||||||
|                             break; |                         break; | ||||||
|                         } |  | ||||||
|                     } |                     } | ||||||
| 
 |  | ||||||
|                     if (Dispatcher) break; |  | ||||||
|                 } |                 } | ||||||
|  | 
 | ||||||
|  |                 if (Dispatcher) break; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             if (msg.activity?.assets?.large_image) |             const factories = wpRequire.m; | ||||||
|                 msg.activity.assets.large_image = await lookupAsset( |             for (const id in factories) { | ||||||
|                     msg.activity.application_id, |                 if (factories[id].toString().includes("getAssetImage: size must === [number, number] for Twitch")) { | ||||||
|                     msg.activity.assets.large_image |                     const mod = wpRequire(id); | ||||||
|                 ); |  | ||||||
|             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) { |                     // fetchAssetIds
 | ||||||
|                 const appId = msg.activity.application_id; |                     const _lookupAsset = Object.values(mod).find( | ||||||
|                 if (!apps[appId]) apps[appId] = await lookupApp(appId); |                         (e) => typeof e === "function" && e.toString().includes("APPLICATION_ASSETS_FETCH_SUCCESS") | ||||||
|  |                     ); | ||||||
|  |                     if (_lookupAsset) | ||||||
|  |                         lookupAsset = async (appId, name) => (await _lookupAsset(appId, [name, undefined]))[0]; | ||||||
|  |                 } | ||||||
| 
 | 
 | ||||||
|                 const app = apps[appId]; |                 if (lookupAsset) break; | ||||||
|                 if (!msg.activity.name) msg.activity.name = app.name; |  | ||||||
|             } |             } | ||||||
|             Dispatcher.dispatch({type: "LOCAL_ACTIVITY_UPDATE", ...msg}); // set RPC status
 |  | ||||||
|         }); |  | ||||||
|     }; |  | ||||||
| 
 | 
 | ||||||
|     cb(); |             for (const id in factories) { | ||||||
|     setInterval(cb, 30 * 1000); |                 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) | ||||||
|  |             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
 | ||||||
|  |     }); | ||||||
|  | })(); | ||||||
|  |  | ||||||
|  | @ -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."); |  | ||||||
|                 } |  | ||||||
|             }); |  | ||||||
|     }); |  | ||||||
| } |  | ||||||
|  | @ -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"; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue