2022-11-11 11:37:37 +00:00
|
|
|
/*
|
|
|
|
* Vencord, a modification for Discord's desktop app
|
|
|
|
* Copyright (c) 2022 Vendicated and contributors
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// eslint-disable-next-line spaced-comment
|
|
|
|
/// <reference types="../src/globals" />
|
|
|
|
// eslint-disable-next-line spaced-comment
|
|
|
|
/// <reference types="../src/modules" />
|
|
|
|
|
|
|
|
import { readFileSync } from "fs";
|
2022-11-11 12:06:04 +00:00
|
|
|
import pup, { JSHandle } from "puppeteer-core";
|
|
|
|
|
|
|
|
for (const variable of ["DISCORD_TOKEN", "CHROMIUM_BIN"]) {
|
|
|
|
if (!process.env[variable]) {
|
|
|
|
console.error(`Missing environment variable ${variable}`);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
}
|
2022-11-11 11:37:37 +00:00
|
|
|
|
2022-12-20 01:59:16 +00:00
|
|
|
const CANARY = process.env.USE_CANARY === "true";
|
|
|
|
|
2022-11-11 11:37:37 +00:00
|
|
|
const browser = await pup.launch({
|
2023-11-25 00:32:21 +00:00
|
|
|
headless: "new",
|
2022-11-11 12:06:04 +00:00
|
|
|
executablePath: process.env.CHROMIUM_BIN
|
2022-11-11 11:37:37 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const page = await browser.newPage();
|
2022-12-20 01:59:16 +00:00
|
|
|
await page.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36");
|
2022-11-11 11:37:37 +00:00
|
|
|
|
2024-05-23 06:36:53 +00:00
|
|
|
async function maybeGetError(handle: JSHandle) {
|
2022-11-11 11:37:37 +00:00
|
|
|
return (handle as JSHandle<Error>)?.getProperty("message")
|
|
|
|
.then(m => m.jsonValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
const report = {
|
|
|
|
badPatches: [] as {
|
|
|
|
plugin: string;
|
|
|
|
type: string;
|
|
|
|
id: string;
|
|
|
|
match: string;
|
|
|
|
error?: string;
|
|
|
|
}[],
|
|
|
|
badStarts: [] as {
|
|
|
|
plugin: string;
|
|
|
|
error: string;
|
|
|
|
}[],
|
2023-11-25 00:32:21 +00:00
|
|
|
otherErrors: [] as string[],
|
|
|
|
badWebpackFinds: [] as string[]
|
2022-11-11 11:37:37 +00:00
|
|
|
};
|
|
|
|
|
2023-10-21 15:51:07 +00:00
|
|
|
const IGNORED_DISCORD_ERRORS = [
|
|
|
|
"KeybindStore: Looking for callback action",
|
|
|
|
"Unable to process domain list delta: Client revision number is null",
|
|
|
|
"Downloading the full bad domains file",
|
2023-11-25 00:32:21 +00:00
|
|
|
/\[GatewaySocket\].{0,110}Cannot access '/,
|
2024-03-27 13:39:58 +00:00
|
|
|
"search for 'name' in undefined",
|
|
|
|
"Attempting to set fast connect zstd when unsupported"
|
2023-10-21 15:51:07 +00:00
|
|
|
] as Array<string | RegExp>;
|
|
|
|
|
2022-11-11 11:37:37 +00:00
|
|
|
function toCodeBlock(s: string) {
|
|
|
|
s = s.replace(/```/g, "`\u200B`\u200B`");
|
|
|
|
return "```" + s + " ```";
|
|
|
|
}
|
|
|
|
|
2022-11-11 12:27:44 +00:00
|
|
|
async function printReport() {
|
2023-11-25 00:32:21 +00:00
|
|
|
console.log();
|
|
|
|
|
2022-12-20 01:59:16 +00:00
|
|
|
console.log("# Vencord Report" + (CANARY ? " (Canary)" : ""));
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2022-11-11 11:37:37 +00:00
|
|
|
console.log();
|
|
|
|
|
|
|
|
console.log("## Bad Patches");
|
|
|
|
report.badPatches.forEach(p => {
|
|
|
|
console.log(`- ${p.plugin} (${p.type})`);
|
|
|
|
console.log(` - ID: \`${p.id}\``);
|
|
|
|
console.log(` - Match: ${toCodeBlock(p.match)}`);
|
|
|
|
if (p.error) console.log(` - Error: ${toCodeBlock(p.error)}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log();
|
|
|
|
|
2023-11-25 00:32:21 +00:00
|
|
|
console.log("## Bad Webpack Finds");
|
|
|
|
report.badWebpackFinds.forEach(p => console.log("- " + p));
|
|
|
|
|
|
|
|
console.log();
|
|
|
|
|
2022-11-11 11:37:37 +00:00
|
|
|
console.log("## Bad Starts");
|
|
|
|
report.badStarts.forEach(p => {
|
|
|
|
console.log(`- ${p.plugin}`);
|
|
|
|
console.log(` - Error: ${toCodeBlock(p.error)}`);
|
|
|
|
});
|
2022-11-11 12:06:04 +00:00
|
|
|
|
2023-11-25 00:32:21 +00:00
|
|
|
console.log();
|
|
|
|
|
2023-11-30 05:38:12 +00:00
|
|
|
const ignoredErrors = [] as string[];
|
|
|
|
report.otherErrors = report.otherErrors.filter(e => {
|
|
|
|
if (IGNORED_DISCORD_ERRORS.some(regex => e.match(regex))) {
|
|
|
|
ignoredErrors.push(e);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2023-10-21 15:51:07 +00:00
|
|
|
|
2022-11-11 12:06:04 +00:00
|
|
|
console.log("## Discord Errors");
|
|
|
|
report.otherErrors.forEach(e => {
|
|
|
|
console.log(`- ${toCodeBlock(e)}`);
|
|
|
|
});
|
2022-11-11 12:27:44 +00:00
|
|
|
|
2023-11-25 00:32:21 +00:00
|
|
|
console.log();
|
|
|
|
|
2023-11-30 05:38:12 +00:00
|
|
|
console.log("## Ignored Discord Errors");
|
|
|
|
ignoredErrors.forEach(e => {
|
|
|
|
console.log(`- ${toCodeBlock(e)}`);
|
|
|
|
});
|
|
|
|
|
|
|
|
console.log();
|
|
|
|
|
2022-11-11 12:27:44 +00:00
|
|
|
if (process.env.DISCORD_WEBHOOK) {
|
|
|
|
await fetch(process.env.DISCORD_WEBHOOK, {
|
|
|
|
method: "POST",
|
|
|
|
headers: {
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
},
|
|
|
|
body: JSON.stringify({
|
|
|
|
description: "Here's the latest Vencord Report!",
|
2022-12-20 01:59:16 +00:00
|
|
|
username: "Vencord Reporter" + (CANARY ? " (Canary)" : ""),
|
2023-12-14 00:46:51 +00:00
|
|
|
avatar_url: "https://cdn.discordapp.com/avatars/1017176847865352332/c312b6b44179ae6817de7e4b09e9c6af.webp?size=512",
|
2022-11-11 12:27:44 +00:00
|
|
|
embeds: [
|
|
|
|
{
|
|
|
|
title: "Bad Patches",
|
|
|
|
description: report.badPatches.map(p => {
|
|
|
|
const lines = [
|
|
|
|
`**__${p.plugin} (${p.type}):__**`,
|
|
|
|
`ID: \`${p.id}\``,
|
|
|
|
`Match: ${toCodeBlock(p.match)}`
|
|
|
|
];
|
|
|
|
if (p.error) lines.push(`Error: ${toCodeBlock(p.error)}`);
|
|
|
|
return lines.join("\n");
|
|
|
|
}).join("\n\n") || "None",
|
|
|
|
color: report.badPatches.length ? 0xff0000 : 0x00ff00
|
|
|
|
},
|
2023-11-25 00:32:21 +00:00
|
|
|
{
|
|
|
|
title: "Bad Webpack Finds",
|
|
|
|
description: report.badWebpackFinds.map(toCodeBlock).join("\n") || "None",
|
|
|
|
color: report.badWebpackFinds.length ? 0xff0000 : 0x00ff00
|
|
|
|
},
|
2022-11-11 12:27:44 +00:00
|
|
|
{
|
|
|
|
title: "Bad Starts",
|
|
|
|
description: report.badStarts.map(p => {
|
|
|
|
const lines = [
|
|
|
|
`**__${p.plugin}:__**`,
|
|
|
|
toCodeBlock(p.error)
|
|
|
|
];
|
|
|
|
return lines.join("\n");
|
|
|
|
}
|
|
|
|
).join("\n\n") || "None",
|
|
|
|
color: report.badStarts.length ? 0xff0000 : 0x00ff00
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Discord Errors",
|
2023-04-30 13:34:38 +00:00
|
|
|
description: report.otherErrors.length ? toCodeBlock(report.otherErrors.join("\n")) : "None",
|
2022-11-11 12:27:44 +00:00
|
|
|
color: report.otherErrors.length ? 0xff0000 : 0x00ff00
|
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
}).then(res => {
|
|
|
|
if (!res.ok) console.error(`Webhook failed with status ${res.status}`);
|
|
|
|
else console.error("Posted to Discord Webhook successfully");
|
|
|
|
});
|
|
|
|
}
|
2022-11-11 11:37:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
page.on("console", async e => {
|
|
|
|
const level = e.type();
|
2023-11-25 00:32:21 +00:00
|
|
|
const rawArgs = e.args();
|
2022-11-11 11:37:37 +00:00
|
|
|
|
2023-11-25 00:32:21 +00:00
|
|
|
const firstArg = await rawArgs[0]?.jsonValue();
|
|
|
|
if (firstArg === "[PUPPETEER_TEST_DONE_SIGNAL]") {
|
2022-11-11 11:37:37 +00:00
|
|
|
await browser.close();
|
2022-11-11 12:27:44 +00:00
|
|
|
await printReport();
|
2022-11-11 11:37:37 +00:00
|
|
|
process.exit();
|
|
|
|
}
|
|
|
|
|
2023-11-25 00:32:21 +00:00
|
|
|
const isVencord = firstArg === "[Vencord]";
|
|
|
|
const isDebug = firstArg === "[PUP_DEBUG]";
|
|
|
|
const isWebpackFindFail = firstArg === "[PUP_WEBPACK_FIND_FAIL]";
|
2022-11-11 12:06:04 +00:00
|
|
|
|
2023-11-25 00:32:21 +00:00
|
|
|
if (isWebpackFindFail) {
|
2022-11-11 11:37:37 +00:00
|
|
|
process.exitCode = 1;
|
2023-11-25 00:32:21 +00:00
|
|
|
report.badWebpackFinds.push(await rawArgs[1].jsonValue() as string);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isVencord) {
|
|
|
|
const args = await Promise.all(e.args().map(a => a.jsonValue()));
|
2022-11-11 11:37:37 +00:00
|
|
|
|
2023-11-25 00:32:21 +00:00
|
|
|
const [, tag, message] = args as Array<string>;
|
|
|
|
const cause = await maybeGetError(e.args()[3]);
|
2022-11-11 11:37:37 +00:00
|
|
|
|
|
|
|
switch (tag) {
|
|
|
|
case "WebpackInterceptor:":
|
2023-12-14 00:41:09 +00:00
|
|
|
const patchFailMatch = message.match(/Patch by (.+?) (had no effect|errored|found no module) \(Module id is (.+?)\): (.+)/)!;
|
|
|
|
if (!patchFailMatch) break;
|
|
|
|
|
2023-11-25 00:32:21 +00:00
|
|
|
process.exitCode = 1;
|
|
|
|
|
2023-12-14 00:41:09 +00:00
|
|
|
const [, plugin, type, id, regex] = patchFailMatch;
|
2022-11-11 11:37:37 +00:00
|
|
|
report.badPatches.push({
|
|
|
|
plugin,
|
|
|
|
type,
|
|
|
|
id,
|
2023-09-06 02:14:27 +00:00
|
|
|
match: regex.replace(/\[A-Za-z_\$\]\[\\w\$\]\*/g, "\\i"),
|
2022-11-11 11:37:37 +00:00
|
|
|
error: cause
|
|
|
|
});
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2022-11-11 11:37:37 +00:00
|
|
|
break;
|
|
|
|
case "PluginManager:":
|
2023-11-25 00:32:21 +00:00
|
|
|
const failedToStartMatch = message.match(/Failed to start (.+)/);
|
|
|
|
if (!failedToStartMatch) break;
|
|
|
|
|
|
|
|
process.exitCode = 1;
|
|
|
|
|
|
|
|
const [, name] = failedToStartMatch;
|
2022-11-11 11:37:37 +00:00
|
|
|
report.badStarts.push({
|
|
|
|
plugin: name,
|
|
|
|
error: cause
|
|
|
|
});
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2022-11-11 11:37:37 +00:00
|
|
|
break;
|
|
|
|
}
|
2023-11-25 00:32:21 +00:00
|
|
|
}
|
|
|
|
|
2024-05-22 03:47:12 +00:00
|
|
|
async function getText() {
|
|
|
|
try {
|
|
|
|
return await Promise.all(
|
|
|
|
e.args().map(async a => {
|
2023-04-18 00:54:22 +00:00
|
|
|
return await maybeGetError(a) || await a.jsonValue();
|
2024-05-22 03:47:12 +00:00
|
|
|
})
|
|
|
|
).then(a => a.join(" ").trim());
|
|
|
|
} catch {
|
|
|
|
return e.text();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isDebug) {
|
|
|
|
const text = await getText();
|
2023-04-18 00:54:22 +00:00
|
|
|
|
2024-05-22 03:47:12 +00:00
|
|
|
console.error(text);
|
|
|
|
if (text.includes("A fatal error occurred:")) {
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
} else if (level === "error") {
|
|
|
|
const text = await getText();
|
2023-05-01 07:26:27 +00:00
|
|
|
|
2023-12-14 00:41:09 +00:00
|
|
|
if (text.length && !text.startsWith("Failed to load resource: the server responded with a status of") && !text.includes("Webpack")) {
|
2023-11-25 00:32:21 +00:00
|
|
|
console.error("[Unexpected Error]", text);
|
2023-02-01 13:13:55 +00:00
|
|
|
report.otherErrors.push(text);
|
|
|
|
}
|
2022-11-11 11:37:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
page.on("error", e => console.error("[Error]", e));
|
|
|
|
page.on("pageerror", e => console.error("[Page Error]", e));
|
|
|
|
|
|
|
|
await page.setBypassCSP(true);
|
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
async function runtime(token: string) {
|
2023-11-25 00:32:21 +00:00
|
|
|
console.log("[PUP_DEBUG]", "Starting test...");
|
2022-11-11 12:06:04 +00:00
|
|
|
|
|
|
|
try {
|
2023-11-25 00:32:21 +00:00
|
|
|
// Spoof languages to not be suspicious
|
2022-11-11 12:06:04 +00:00
|
|
|
Object.defineProperty(navigator, "languages", {
|
|
|
|
get: function () {
|
|
|
|
return ["en-US", "en"];
|
2024-05-23 09:04:21 +00:00
|
|
|
}
|
2022-11-11 11:37:37 +00:00
|
|
|
});
|
|
|
|
|
2022-11-11 12:06:04 +00:00
|
|
|
// Monkey patch Logger to not log with custom css
|
2023-02-01 13:13:55 +00:00
|
|
|
// @ts-ignore
|
2024-05-02 21:52:41 +00:00
|
|
|
const originalLog = Vencord.Util.Logger.prototype._log;
|
|
|
|
// @ts-ignore
|
2022-11-11 12:06:04 +00:00
|
|
|
Vencord.Util.Logger.prototype._log = function (level, levelColor, args) {
|
|
|
|
if (level === "warn" || level === "error")
|
2024-05-02 21:52:41 +00:00
|
|
|
return console[level]("[Vencord]", this.name + ":", ...args);
|
|
|
|
|
|
|
|
return originalLog.call(this, level, levelColor, args);
|
2022-11-11 12:06:04 +00:00
|
|
|
};
|
|
|
|
|
2023-11-25 00:32:21 +00:00
|
|
|
// Force enable all plugins and patches
|
2022-11-11 12:06:04 +00:00
|
|
|
Vencord.Plugins.patches.length = 0;
|
|
|
|
Object.values(Vencord.Plugins.plugins).forEach(p => {
|
2023-01-07 02:28:40 +00:00
|
|
|
// Needs native server to run
|
|
|
|
if (p.name === "WebRichPresence (arRPC)") return;
|
|
|
|
|
2023-04-30 13:34:38 +00:00
|
|
|
Vencord.Settings.plugins[p.name].enabled = true;
|
2022-11-11 12:06:04 +00:00
|
|
|
p.patches?.forEach(patch => {
|
|
|
|
patch.plugin = p.name;
|
|
|
|
delete patch.predicate;
|
2023-12-14 00:41:09 +00:00
|
|
|
delete patch.group;
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-05-15 03:38:07 +00:00
|
|
|
Vencord.Util.canonicalizeFind(patch);
|
|
|
|
if (!Array.isArray(patch.replacement)) {
|
2022-11-11 12:06:04 +00:00
|
|
|
patch.replacement = [patch.replacement];
|
2024-05-15 03:38:07 +00:00
|
|
|
}
|
2023-11-25 00:32:21 +00:00
|
|
|
|
|
|
|
patch.replacement.forEach(r => {
|
|
|
|
delete r.predicate;
|
|
|
|
});
|
|
|
|
|
2022-11-11 12:06:04 +00:00
|
|
|
Vencord.Plugins.patches.push(patch);
|
|
|
|
});
|
|
|
|
});
|
2022-11-11 11:37:37 +00:00
|
|
|
|
2024-05-23 09:22:01 +00:00
|
|
|
// Enable eagerPatches to make all patches apply regardless of the module being required
|
2024-05-23 09:29:07 +00:00
|
|
|
Vencord.Settings.eagerPatches = true;
|
2024-05-23 09:22:01 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
let wreq: typeof Vencord.Webpack.wreq;
|
2022-11-11 12:06:04 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
const { canonicalizeMatch, Logger } = Vencord.Util;
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
const validChunks = new Set<string>();
|
|
|
|
const invalidChunks = new Set<string>();
|
2024-05-22 03:47:12 +00:00
|
|
|
const deferredRequires = new Set<string>();
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
let chunksSearchingResolve: (value: void | PromiseLike<void>) => void;
|
|
|
|
const chunksSearchingDone = new Promise<void>(r => chunksSearchingResolve = r);
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
// True if resolved, false otherwise
|
|
|
|
const chunksSearchPromises = [] as Array<() => boolean>;
|
2024-05-22 03:47:12 +00:00
|
|
|
|
|
|
|
const LazyChunkRegex = canonicalizeMatch(/(?:Promise\.all\(\[(\i\.\i\("[^)]+?"\)[^\]]+?)\]\)|(\i\.\i\("[^)]+?"\)))\.then\(\i\.bind\(\i,"([^)]+?)"\)\)/g);
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
async function searchAndLoadLazyChunks(factoryCode: string) {
|
2024-05-22 03:47:12 +00:00
|
|
|
const lazyChunks = factoryCode.matchAll(LazyChunkRegex);
|
2024-05-02 21:52:41 +00:00
|
|
|
const validChunkGroups = new Set<[chunkIds: string[], entryPoint: string]>();
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-05-22 03:47:12 +00:00
|
|
|
// Workaround for a chunk that depends on the ChannelMessage component but may be be force loaded before
|
|
|
|
// the chunk containing the component
|
|
|
|
const shouldForceDefer = factoryCode.includes(".Messages.GUILD_FEED_UNFEATURE_BUTTON_TEXT");
|
|
|
|
|
|
|
|
await Promise.all(Array.from(lazyChunks).map(async ([, rawChunkIdsArray, rawChunkIdsSingle, entryPoint]) => {
|
|
|
|
const rawChunkIds = rawChunkIdsArray ?? rawChunkIdsSingle;
|
|
|
|
const chunkIds = rawChunkIds ? Array.from(rawChunkIds.matchAll(Vencord.Webpack.ChunkIdsRegex)).map(m => m[1]) : [];
|
|
|
|
|
|
|
|
if (chunkIds.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
let invalidChunkGroup = false;
|
2023-11-25 00:32:21 +00:00
|
|
|
|
|
|
|
for (const id of chunkIds) {
|
2023-12-22 00:46:34 +00:00
|
|
|
if (wreq.u(id) == null || wreq.u(id) === "undefined.js") continue;
|
2023-11-25 00:32:21 +00:00
|
|
|
|
|
|
|
const isWasm = await fetch(wreq.p + wreq.u(id))
|
|
|
|
.then(r => r.text())
|
|
|
|
.then(t => t.includes(".module.wasm") || !t.includes("(this.webpackChunkdiscord_app=this.webpackChunkdiscord_app||[]).push"));
|
|
|
|
|
|
|
|
if (isWasm) {
|
2023-12-07 00:15:29 +00:00
|
|
|
invalidChunks.add(id);
|
2024-05-02 21:52:41 +00:00
|
|
|
invalidChunkGroup = true;
|
2023-12-07 00:15:29 +00:00
|
|
|
continue;
|
2023-11-25 00:32:21 +00:00
|
|
|
}
|
|
|
|
|
2023-12-07 00:15:29 +00:00
|
|
|
validChunks.add(id);
|
2023-11-25 00:32:21 +00:00
|
|
|
}
|
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
if (!invalidChunkGroup) {
|
|
|
|
validChunkGroups.add([chunkIds, entryPoint]);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
|
|
|
// Loads all found valid chunk groups
|
|
|
|
await Promise.all(
|
|
|
|
Array.from(validChunkGroups)
|
|
|
|
.map(([chunkIds]) =>
|
2024-05-23 06:36:53 +00:00
|
|
|
Promise.all(chunkIds.map(id => wreq.e(id).catch(() => { })))
|
2024-05-02 21:52:41 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Requires the entry points for all valid chunk groups
|
|
|
|
for (const [, entryPoint] of validChunkGroups) {
|
2023-11-25 00:32:21 +00:00
|
|
|
try {
|
2024-05-22 03:47:12 +00:00
|
|
|
if (shouldForceDefer) {
|
|
|
|
deferredRequires.add(entryPoint);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2024-05-23 06:36:53 +00:00
|
|
|
if (wreq.m[entryPoint]) wreq(entryPoint);
|
2024-05-02 21:52:41 +00:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
}
|
2023-11-25 00:32:21 +00:00
|
|
|
}
|
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
// setImmediate to only check if all chunks were loaded after this function resolves
|
|
|
|
// We check if all chunks were loaded every time a factory is loaded
|
|
|
|
// If we are still looking for chunks in the other factories, the array will have that factory's chunk search promise not resolved
|
|
|
|
// But, if all chunk search promises are resolved, this means we found every lazy chunk loaded by Discord code and manually loaded them
|
|
|
|
setTimeout(() => {
|
|
|
|
let allResolved = true;
|
2023-12-22 00:46:34 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
for (let i = 0; i < chunksSearchPromises.length; i++) {
|
|
|
|
const isResolved = chunksSearchPromises[i]();
|
2023-12-22 00:46:34 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
if (isResolved) {
|
|
|
|
// Remove finished promises to avoid having to iterate through a huge array everytime
|
|
|
|
chunksSearchPromises.splice(i--, 1);
|
|
|
|
} else {
|
|
|
|
allResolved = false;
|
|
|
|
}
|
|
|
|
}
|
2023-12-22 00:46:34 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
if (allResolved) chunksSearchingResolve();
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vencord.Webpack.waitFor(
|
2024-05-03 02:18:12 +00:00
|
|
|
Vencord.Webpack.filters.byProps("loginToken"),
|
2024-05-02 21:52:41 +00:00
|
|
|
m => {
|
|
|
|
console.log("[PUP_DEBUG]", "Logging in with token...");
|
|
|
|
m.loginToken(token);
|
2023-12-22 00:46:34 +00:00
|
|
|
}
|
2024-05-02 21:52:41 +00:00
|
|
|
);
|
2023-12-22 00:46:34 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
Vencord.Webpack.beforeInitListeners.add(async webpackRequire => {
|
|
|
|
console.log("[PUP_DEBUG]", "Loading all chunks...");
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
wreq = webpackRequire;
|
2022-11-11 12:06:04 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
Vencord.Webpack.factoryListeners.add(factory => {
|
|
|
|
let isResolved = false;
|
|
|
|
searchAndLoadLazyChunks(factory.toString()).then(() => isResolved = true);
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
chunksSearchPromises.push(() => isResolved);
|
|
|
|
});
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
// setImmediate to only search the initial factories after Discord initialized the app
|
|
|
|
// our beforeInitListeners are called before Discord initializes the app
|
|
|
|
setTimeout(() => {
|
|
|
|
for (const factoryId in wreq.m) {
|
|
|
|
let isResolved = false;
|
|
|
|
searchAndLoadLazyChunks(wreq.m[factoryId].toString()).then(() => isResolved = true);
|
|
|
|
|
|
|
|
chunksSearchPromises.push(() => isResolved);
|
2023-11-25 00:32:21 +00:00
|
|
|
}
|
2024-05-02 21:52:41 +00:00
|
|
|
}, 0);
|
|
|
|
});
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
await chunksSearchingDone;
|
2024-05-22 04:30:17 +00:00
|
|
|
wreq = wreq!;
|
2022-11-11 12:06:04 +00:00
|
|
|
|
2024-05-22 03:47:12 +00:00
|
|
|
// Require deferred entry points
|
|
|
|
for (const deferredRequire of deferredRequires) {
|
2024-05-23 06:36:53 +00:00
|
|
|
wreq(deferredRequire);
|
2024-05-22 03:47:12 +00:00
|
|
|
}
|
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
// All chunks Discord has mapped to asset files, even if they are not used anymore
|
|
|
|
const allChunks = [] as string[];
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
// Matches "id" or id:
|
2024-05-22 04:30:17 +00:00
|
|
|
for (const currentMatch of wreq.u.toString().matchAll(/(?:"(\d+?)")|(?:(\d+?):)/g)) {
|
2024-05-02 21:52:41 +00:00
|
|
|
const id = currentMatch[1] ?? currentMatch[2];
|
|
|
|
if (id == null) continue;
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
allChunks.push(id);
|
|
|
|
}
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
if (allChunks.length === 0) throw new Error("Failed to get all chunks");
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
// Chunks that are not loaded (not used) by Discord code anymore
|
|
|
|
const chunksLeft = allChunks.filter(id => {
|
|
|
|
return !(validChunks.has(id) || invalidChunks.has(id));
|
|
|
|
});
|
2023-11-27 05:56:57 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
await Promise.all(chunksLeft.map(async id => {
|
|
|
|
const isWasm = await fetch(wreq.p + wreq.u(id))
|
|
|
|
.then(r => r.text())
|
|
|
|
.then(t => t.includes(".module.wasm") || !t.includes("(this.webpackChunkdiscord_app=this.webpackChunkdiscord_app||[]).push"));
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
// Loads and requires a chunk
|
|
|
|
if (!isWasm) {
|
2024-05-23 06:36:53 +00:00
|
|
|
await wreq.e(id);
|
|
|
|
if (wreq.m[id]) wreq(id);
|
2024-05-02 21:52:41 +00:00
|
|
|
}
|
|
|
|
}));
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
console.log("[PUP_DEBUG]", "Finished loading all chunks!");
|
|
|
|
|
|
|
|
for (const patch of Vencord.Plugins.patches) {
|
|
|
|
if (!patch.all) {
|
|
|
|
new Logger("WebpackInterceptor").warn(`Patch by ${patch.plugin} found no module (Module id is -): ${patch.find}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-07 04:13:46 +00:00
|
|
|
// eslint-disable-next-line prefer-const
|
|
|
|
for (let [searchType, args] of Vencord.Webpack.webpackSearchHistory) {
|
|
|
|
args = [...args];
|
2024-05-02 21:52:41 +00:00
|
|
|
|
|
|
|
try {
|
2024-05-07 04:13:46 +00:00
|
|
|
let result = null as any;
|
2024-05-02 21:52:41 +00:00
|
|
|
|
2024-05-22 04:27:39 +00:00
|
|
|
switch (searchType) {
|
|
|
|
case "webpackDependantLazy":
|
|
|
|
case "webpackDependantLazyComponent": {
|
|
|
|
const [factory] = args;
|
|
|
|
result = factory();
|
|
|
|
break;
|
2024-05-03 02:42:42 +00:00
|
|
|
}
|
2024-05-22 04:27:39 +00:00
|
|
|
case "extractAndLoadChunks": {
|
|
|
|
const [code, matcher] = args;
|
2024-05-07 04:13:46 +00:00
|
|
|
|
2024-05-22 04:27:39 +00:00
|
|
|
const module = Vencord.Webpack.findModuleFactory(...code);
|
|
|
|
if (module) {
|
|
|
|
result = module.toString().match(Vencord.Util.canonicalizeMatch(matcher));
|
2024-05-07 04:13:46 +00:00
|
|
|
}
|
|
|
|
|
2024-05-22 04:27:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
const findResult = args.shift();
|
|
|
|
|
|
|
|
if (findResult != null) {
|
|
|
|
if (findResult.$$vencordCallbackCalled != null && findResult.$$vencordCallbackCalled()) {
|
|
|
|
result = findResult;
|
|
|
|
}
|
2024-05-07 04:13:46 +00:00
|
|
|
|
2024-05-22 04:27:39 +00:00
|
|
|
if (findResult[Vencord.Util.proxyInnerGet] != null) {
|
|
|
|
result = findResult[Vencord.Util.proxyInnerValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (findResult.$$vencordInner != null) {
|
|
|
|
result = findResult.$$vencordInner();
|
|
|
|
}
|
2024-05-07 04:13:46 +00:00
|
|
|
}
|
2024-05-22 04:27:39 +00:00
|
|
|
|
|
|
|
break;
|
2024-05-03 02:42:42 +00:00
|
|
|
}
|
2023-11-25 00:32:21 +00:00
|
|
|
}
|
2024-05-02 21:52:41 +00:00
|
|
|
|
2024-05-03 02:42:42 +00:00
|
|
|
if (result == null) {
|
|
|
|
throw "a rock at ben shapiro";
|
|
|
|
}
|
2024-05-02 21:52:41 +00:00
|
|
|
} catch (e) {
|
|
|
|
let logMessage = searchType;
|
2024-05-03 02:18:12 +00:00
|
|
|
|
|
|
|
let filterName = "";
|
|
|
|
let parsedArgs = args;
|
2024-05-07 04:13:46 +00:00
|
|
|
|
|
|
|
if (args[0].$$vencordProps != null) {
|
2024-05-07 06:01:45 +00:00
|
|
|
if (["find", "findComponent", "waitFor"].includes(searchType)) {
|
2024-05-07 06:07:03 +00:00
|
|
|
filterName = args[0].$$vencordProps[0];
|
2024-05-03 02:18:12 +00:00
|
|
|
}
|
|
|
|
|
2024-05-07 06:07:03 +00:00
|
|
|
parsedArgs = args[0].$$vencordProps.slice(1);
|
2024-05-03 02:18:12 +00:00
|
|
|
}
|
|
|
|
|
2024-05-07 04:13:46 +00:00
|
|
|
// if parsedArgs is the same as args, it means vencordProps of the filter was not available (like in normal filter functions),
|
|
|
|
// so log the filter function instead
|
2024-05-03 02:18:12 +00:00
|
|
|
if (
|
2024-05-07 06:01:45 +00:00
|
|
|
parsedArgs === args &&
|
|
|
|
["waitFor", "find", "findComponent", "webpackDependantLazy", "webpackDependantLazyComponent"].includes(searchType)
|
2024-05-03 02:18:12 +00:00
|
|
|
) {
|
2024-05-08 09:16:00 +00:00
|
|
|
let filter = parsedArgs[0].toString();
|
|
|
|
if (filter.length > 150) {
|
|
|
|
filter = filter.slice(0, 147) + "...";
|
|
|
|
}
|
|
|
|
|
|
|
|
logMessage += `(${filter})`;
|
2024-05-03 02:18:12 +00:00
|
|
|
} else if (searchType === "extractAndLoadChunks") {
|
2024-05-08 09:16:00 +00:00
|
|
|
let regexStr: string;
|
|
|
|
if (parsedArgs[1] === Vencord.Webpack.DefaultExtractAndLoadChunksRegex) {
|
|
|
|
regexStr = "DefaultExtractAndLoadChunksRegex";
|
|
|
|
} else {
|
|
|
|
regexStr = parsedArgs[1].toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
logMessage += `([${parsedArgs[0].map((arg: any) => `"${arg}"`).join(", ")}], ${regexStr})`;
|
2024-05-03 02:18:12 +00:00
|
|
|
} else {
|
|
|
|
logMessage += `(${filterName.length ? `${filterName}(` : ""}${parsedArgs.map(arg => `"${arg}"`).join(", ")})${filterName.length ? ")" : ""}`;
|
|
|
|
}
|
2024-05-02 21:52:41 +00:00
|
|
|
|
|
|
|
console.log("[PUP_WEBPACK_FIND_FAIL]", logMessage);
|
2023-11-25 00:32:21 +00:00
|
|
|
}
|
2024-05-02 21:52:41 +00:00
|
|
|
}
|
2023-11-25 00:32:21 +00:00
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
setTimeout(() => console.log("[PUPPETEER_TEST_DONE_SIGNAL]"), 1000);
|
2022-11-11 12:06:04 +00:00
|
|
|
} catch (e) {
|
2023-11-25 00:32:21 +00:00
|
|
|
console.log("[PUP_DEBUG]", "A fatal error occurred:", e);
|
2022-11-11 12:06:04 +00:00
|
|
|
}
|
2022-11-11 11:37:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
await page.evaluateOnNewDocument(`
|
|
|
|
${readFileSync("./dist/browser.js", "utf-8")}
|
|
|
|
|
2024-05-02 21:52:41 +00:00
|
|
|
;(${runtime.toString()})(${JSON.stringify(process.env.DISCORD_TOKEN)});
|
2022-11-11 11:37:37 +00:00
|
|
|
`);
|
|
|
|
|
2022-12-20 01:59:16 +00:00
|
|
|
await page.goto(CANARY ? "https://canary.discord.com/login" : "https://discord.com/login");
|