1
0
Fork 1
mirror of https://github.com/Vendicated/Vencord.git synced 2025-01-25 00:36:23 +00:00

more horror code

This commit is contained in:
sadan 2024-11-15 02:23:56 -05:00
parent 3c6a374543
commit 0250243db7
No known key found for this signature in database
5 changed files with 166 additions and 13 deletions

3
.gitignore vendored
View file

@ -22,3 +22,6 @@ src/userplugins
ExtensionCache/
settings/
# vencord companion module cache
.modules

View file

@ -18,7 +18,7 @@
import { waitFor } from "@webpack";
let NoticesModule: any;
export let NoticesModule: any;
waitFor(m => m.show && m.dismiss && !m.suppressAll, m => NoticesModule = m);
export const noticesQueue = [] as any[];

View file

@ -4,14 +4,17 @@
* SPDX-License-Identifier: GPL-3.0-or-later
*/
import { popNotice, showNotice } from "@api/Notices";
import ErrorBoundary from "@components/ErrorBoundary";
import { canonicalizeMatch, canonicalizeReplace } from "@utils/patches";
import { filters, findAll, search, wreq } from "@webpack";
import { Toasts } from "@webpack/common";
import { React, Toasts, useState } from "@webpack/common";
import { loadLazyChunks } from "debug/loadLazyChunks";
import { reporterData } from "debug/reporterData";
import { Settings } from "Vencord";
import { logger, PORT, settings } from ".";
import { extractModule, extractOrThrow, FindData, findModuleId, FindType, mkRegexFind, parseNode, PatchData, SendData, toggleEnabled, } from "./util";
import { extractModule, extractOrThrow, FindData, findModuleId, mkRegexFind, parseNode, PatchData, SendData, toggleEnabled, } from "./util";
export function stopWs() {
socket?.close(1000, "Plugin Stopped");
@ -155,14 +158,14 @@ export function initWs(isManual = false) {
}
case "search": {
let moduleId;
if (data.findType === FindType.STRING)
if (data.findType === "string")
moduleId = +findModuleId([idOrSearch.toString()]);
else
moduleId = +findModuleId(mkRegexFind(idOrSearch));
const p = extractOrThrow(moduleId);
const p2 = extractModule(moduleId, false);
console.log(p, p2, "done");
replyData({
type: "diff",
ok: true,
@ -205,7 +208,7 @@ export function initWs(isManual = false) {
}
case "search": {
let moduleId;
if (data.findType === FindType.STRING)
if (data.findType === "string")
moduleId = +findModuleId([idOrSearch.toString()]);
else
@ -280,9 +283,8 @@ export function initWs(isManual = false) {
}
case "testPatch": {
const { find, replacement } = data as PatchData;
let candidates;
if (data.findType === FindType.STRING)
if (data.findType === "string")
candidates = search(find.toString());
else
@ -319,7 +321,6 @@ export function initWs(isManual = false) {
return reply(`Replacement ${i} failed: ${err}`);
}
}
reply();
break;
}
@ -368,6 +369,138 @@ export function initWs(isManual = false) {
reply();
break;
}
case "allModules": {
const { promise, resolve, reject } = Promise.withResolvers<void>();
// wrap in try/catch to prevent crashing if notice api is not loaded
try {
let closed = false;
const close = () => {
if (closed) return;
closed = true;
popNotice();
};
// @ts-expect-error it accepts react components
showNotice(<AllModulesNoti done={promise} close={close} />, "OK", () => {
closed = true;
popNotice();
});
} catch (e) {
console.error(e);
}
loadLazyChunks()
.then(() => {
resolve();
replyData({
type: "allModules",
data: Object.keys(wreq.m),
ok: true
});
})
.catch(e => {
console.error(e);
replyData({
type: "allModules",
ok: false,
data: e.toString()
});
reject(e);
});
break;
}
// FIXME: this is just extract but with a different name
case "rawContent": {
try {
const { extractType, idOrSearch } = data;
switch (extractType) {
case "id": {
if (typeof idOrSearch !== "number")
throw new Error("Id is not a number, got :" + typeof idOrSearch);
else
replyData({
type: "rawContent",
ok: true,
data: extractModule(idOrSearch),
moduleNumber: idOrSearch
});
break;
}
case "search": {
let moduleId;
if (data.findType === "string")
moduleId = +findModuleId([idOrSearch.toString()]);
else
moduleId = +findModuleId(mkRegexFind(idOrSearch));
replyData({
type: "rawContent",
ok: true,
data: extractModule(moduleId),
moduleNumber: moduleId
});
break;
}
case "find": {
const { findType, findArgs } = data;
try {
var parsedArgs = findArgs.map(parseNode);
} catch (err) {
return reply("Failed to parse args: " + err);
}
try {
let results: any[];
switch (findType.replace("find", "").replace("Lazy", "")) {
case "":
case "Component":
results = findAll(parsedArgs[0]);
break;
case "ByProps":
results = findAll(filters.byProps(...parsedArgs));
break;
case "Store":
results = findAll(filters.byStoreName(parsedArgs[0]));
break;
case "ByCode":
results = findAll(filters.byCode(...parsedArgs));
break;
case "ModuleId":
results = Object.keys(search(parsedArgs[0]));
break;
case "ComponentByCode":
results = findAll(filters.componentByCode(...parsedArgs));
break;
default:
return reply("Unknown Find Type " + findType);
}
const uniqueResultsCount = new Set(results).size;
if (uniqueResultsCount === 0) throw "No results";
if (uniqueResultsCount > 1) throw "Found more than one result! Make this filter more specific";
// best name ever
const foundFind: string = [...results][0].toString();
replyData({
type: "rawContent",
ok: true,
find: true,
data: foundFind,
moduleNumber: +findModuleId([foundFind])
});
} catch (err) {
return reply("Failed to find: " + err);
}
break;
}
default:
reply(`Unknown Extract type. Got: ${extractType}`);
break;
}
} catch (error) {
reply(String(error));
}
break;
}
default:
reply("Unknown Type " + type);
break;
@ -375,3 +508,19 @@ export function initWs(isManual = false) {
});
}
interface AllModulesNotiProps {
done: Promise<unknown>;
close: () => void;
}
const AllModulesNoti = ErrorBoundary.wrap(function ({ done, close }: AllModulesNotiProps) {
const [state, setState] = useState<0 | 1 | -1>(0);
done.then(setState.bind(null, 1)).catch(setState.bind(null, -1));
console.log("test");
if (state === 1) setTimeout(close, 5000);
return (<>
{state === 0 && "Loading lazy modules, restarting could lead to errors"}
{state === 1 && "Loaded all lazy modules"}
{state === -1 && "Failed to load lazy modules, check console for errors"}
</>);
}, { noop: true });

View file

@ -0,0 +1,5 @@
/*
* Vencord, a Discord client mod
* Copyright (c) 2024 Vendicated and contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/

View file

@ -26,10 +26,6 @@ export interface RegexNode {
flags: string;
};
}
export enum FindType {
STRING,
REGEX
}
export interface FunctionNode {
type: "function";
value: string;