🧹🧹🧹🧹🧹🧹

This commit is contained in:
Nuckyz 2024-08-02 20:48:44 -03:00
parent 6bdd0ba4a9
commit ca3768ca5d
No known key found for this signature in database
GPG key ID: 440BF8296E1C4AD9
9 changed files with 35 additions and 31 deletions

View file

@ -84,7 +84,6 @@ async function runReporter() {
if (findResult[SYM_PROXY_INNER_GET] != null) {
result = findResult[SYM_PROXY_INNER_VALUE];
break;
}

View file

@ -93,11 +93,11 @@ export default definePlugin({
// Ensure this is most likely the Sentry WebpackInstance.
// Function.g is a very generic property and is not uncommon for another WebpackInstance (or even a React component: <g></g>) to include it
const { stack } = new Error();
if (!stack?.includes("/assets/") || !String(this).includes("exports:{}") || this.c != null) {
if (this.c != null || !stack?.includes("http") || !String(this).includes("exports:{}")) {
return;
}
const assetPath = stack?.match(/\/assets\/.+?\.js/)?.[0];
const assetPath = stack.match(/\/assets\/.+?\.js/)?.[0];
if (!assetPath) {
return;
}

View file

@ -7,10 +7,10 @@
import ErrorBoundary from "@components/ErrorBoundary";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { findByPropsAndExtract } from "@webpack";
import { findProp } from "@webpack";
import { Button, ChannelStore, Text } from "@webpack/common";
const selectChannel = findByPropsAndExtract("selectChannel", "selectVoiceChannel");
const selectChannel = findProp("selectChannel", "selectVoiceChannel");
function jumpToMessage(channelId: string, messageId: string) {
const guildId = ChannelStore.getChannel(channelId)?.guild_id;

View file

@ -8,10 +8,10 @@ import { definePluginSettings } from "@api/Settings";
import { Devs } from "@utils/constants";
import { copyWithToast } from "@utils/misc";
import definePlugin, { OptionType } from "@utils/types";
import { findByPropsAndExtract } from "@webpack";
import { findProp } from "@webpack";
import { Menu } from "@webpack/common";
const convertNameToSurrogate = findByPropsAndExtract("convertNameToSurrogate");
const convertNameToSurrogate = findProp("convertNameToSurrogate");
interface Emoji {
type: string;

View file

@ -52,7 +52,7 @@ export default definePlugin({
{
find: ".PANEL}),nicknameIcons",
replacement: {
match: /BOT_PROFILE_CREATED_ON,.{0,100}userId:(\i\.id)}\)}\)/,
match: /USER_PROFILE_MEMBER_SINCE,.{0,100}userId:(\i\.id)}\)}\)/,
replace: "$&,$self.friendsSinceNew({userId:$1,isSidebar:true})"
}
},

View file

@ -24,11 +24,11 @@ import { definePluginSettings, migratePluginSettings } from "@api/Settings";
import { CogWheel } from "@components/Icons";
import { Devs } from "@utils/constants";
import definePlugin, { OptionType } from "@utils/types";
import { findByCode, findByPropsAndExtract, mapMangledModule } from "@webpack";
import { findByCode, findProp, mapMangledModule } from "@webpack";
import { Menu } from "@webpack/common";
import { Guild } from "discord-types/general";
const updateGuildNotificationSettings = findByPropsAndExtract("updateGuildNotificationSettings");
const updateGuildNotificationSettings = findProp("updateGuildNotificationSettings");
const { toggleShowAllChannels } = mapMangledModule(".onboardExistingMember(", {
toggleShowAllChannels: m => {
const s = String(m);

View file

@ -107,7 +107,7 @@ export const filters = {
},
byStoreName: (name: StoreNameFilter): FilterFn => {
const filter: FilterFn = m => m?.constructor?.displayName === name;
const filter: FilterFn = m => m?.constructor?.displayName === name || m?.constructor?.persistKey === name;
filter.$$vencordProps = ["byStoreName", name];
return filter;
@ -143,7 +143,7 @@ export const filters = {
}
};
export const webpackSearchHistory = [] as Array<["waitFor" | "find" | "findComponent" | "findExportedComponent" | "findComponentByCode" | "findByProps" | "findByPropsAndExtract" | "findByCode" | "findStore" | "findByFactoryCode" | "mapMangledModule" | "extractAndLoadChunks" | "webpackDependantLazy" | "webpackDependantLazyComponent", any[]]>;
export const webpackSearchHistory = [] as Array<["waitFor" | "find" | "findComponent" | "findExportedComponent" | "findComponentByCode" | "findByProps" | "findProp" | "findByCode" | "findStore" | "findByFactoryCode" | "mapMangledModule" | "extractAndLoadChunks" | "webpackDependantLazy" | "webpackDependantLazyComponent", any[]]>;
function printFilter(filter: FilterFn) {
if (filter.$$vencordProps != null) {
@ -349,19 +349,20 @@ export function findByProps<T = any>(...props: PropsFilter | [...PropsFilter, (m
/**
* Find the first prop value defined by the first prop name, which is in a module exports or export including all the given props.
*
* @example const getUser = findByPropsAndExtract("getUser", "fetchUser")
* @example const getUser = findProp("getUser", "fetchUser")
* // An object which contains the getUser and fetchUser props is found and the value of getUser is returned
*
* @param props A list of props to search the module or exports for
* @param parse A function that takes the find result as its first argument and returns something. Useful if you want to use a value from the find result, instead of all of it. Defaults to the find result itself
*/
export function findByPropsAndExtract<T = any>(...props: PropsFilter | [...PropsFilter, (module: ModuleExports) => T]) {
export function findProp<T = any>(...props: PropsFilter | [...PropsFilter, (module: ModuleExports) => T]) {
const parse = (typeof props.at(-1) === "function" ? props.pop() : m => m) as (module: ModuleExports) => T;
const newProps = props as PropsFilter;
const result = find<T>(filters.byProps(...newProps), m => parse(m[newProps[0]]), { isIndirect: true });
if (IS_REPORTER) {
webpackSearchHistory.push(["findByPropsAndExtract", [result, ...newProps]]);
webpackSearchHistory.push(["findProp", [result, ...newProps]]);
}
return result;

File diff suppressed because one or more lines are too long

View file

@ -47,36 +47,34 @@ define(Function.prototype, "m", {
set(this: AnyWebpackRequire, originalModules: AnyWebpackRequire["m"]) {
define(this, "m", { value: originalModules });
// We may also catch Discord bundled libs, React Devtools or other extensions WebpackInstance here.
// This ensures we actually got the right ones
// Ensure this is one of Discord main WebpackInstances.
// We may catch Discord bundled libs, React Devtools or other extensions WebpackInstances here.
const { stack } = new Error();
if (!stack?.includes("/assets/") || stack?.match(/at \d+? \(/) || !String(this).includes("exports:{}")) {
if (!stack?.includes("http") || stack.match(/at \d+? \(/) || !String(this).includes("exports:{}")) {
return;
}
const fileName = stack?.match(/\/assets\/(.+?\.js)/)?.[1];
const fileName = stack.match(/\/assets\/(.+?\.js)/)?.[1];
logger.info("Found Webpack module factories" + interpolateIfDefined` in ${fileName}`);
allWebpackInstances.add(this);
// Define a setter for the bundlePath property of WebpackRequire. Only the main Webpack has this property.
// Define a setter for the ensureChunk property of WebpackRequire. Only the main Webpack (which is the only that includes chunk loading) has this property.
// So if the setter is called, this means we can initialize the internal references to WebpackRequire.
define(this, "p", {
define(this, "e", {
enumerable: false,
set(this: WebpackRequire, bundlePath: WebpackRequire["p"]) {
define(this, "p", { value: bundlePath });
set(this: WebpackRequire, ensureChunk: WebpackRequire["e"]) {
define(this, "e", { value: ensureChunk });
clearTimeout(setterTimeout);
if (bundlePath !== "/assets/") return;
logger.info("Main Webpack found" + interpolateIfDefined` in ${fileName}` + ", initializing internal references to WebpackRequire");
_initWebpack(this);
}
});
// setImmediate to clear this property setter if this is not the main Webpack.
// If this is the main Webpack, wreq.p will always be set before the timeout runs.
const setterTimeout = setTimeout(() => Reflect.deleteProperty(this, "p"), 0);
// If this is the main Webpack, wreq.e will always be set before the timeout runs.
const setterTimeout = setTimeout(() => Reflect.deleteProperty(this, "e"), 0);
// Patch the pre-populated factories
for (const id in originalModules) {
@ -278,7 +276,7 @@ function wrapAndPatchFactory(id: PropertyKey, originalFactory: AnyModuleFactory)
}
exports = module.exports;
if (exports == null) return;
if (exports == null) return factoryReturn;
// There are (at the time of writing) 11 modules exporting the window
// Make these non enumerable to improve webpack search performance
@ -394,7 +392,13 @@ function patchFactory(id: PropertyKey, factory: AnyModuleFactory) {
patchedBy.add(patch.plugin);
const executePatch = traceFunctionWithResults(`patch by ${patch.plugin}`, (match: string | RegExp, replace: string) => code.replace(match, replace));
const executePatch = traceFunctionWithResults(`patch by ${patch.plugin}`, (match: string | RegExp, replace: string) => {
if (match instanceof RegExp && match.global) {
match.lastIndex = 0;
}
return code.replace(match, replace);
});
const previousCode = code;
const previousFactory = factory;