diff --git a/src/api/UserSettingDefinitions.ts b/src/api/UserSettingDefinitions.ts index a4dd5147f..f87df9973 100644 --- a/src/api/UserSettingDefinitions.ts +++ b/src/api/UserSettingDefinitions.ts @@ -65,7 +65,7 @@ export function getUserSettingDefinition(group: string, name: string): } /** - * {@link getUserSettingDefinition}, lazy. + * Lazy version of {@link getUserSettingDefinition} * * Get the definition for a setting. * diff --git a/src/components/VencordSettings/PatchHelperTab.tsx b/src/components/VencordSettings/PatchHelperTab.tsx index e09a1dbf3..857b976e9 100644 --- a/src/components/VencordSettings/PatchHelperTab.tsx +++ b/src/components/VencordSettings/PatchHelperTab.tsx @@ -56,7 +56,7 @@ function ReplacementComponent({ module, match, replacement, setReplacementError const [compileResult, setCompileResult] = React.useState<[boolean, string]>(); const [patchedCode, matchResult, diff] = React.useMemo(() => { - const src: string = fact.toString().replaceAll("\n", ""); + const src = String(fact).replaceAll("\n", ""); try { new RegExp(match); diff --git a/src/debug/loadLazyChunks.ts b/src/debug/loadLazyChunks.ts index 64c3e0ead..abaef263d 100644 --- a/src/debug/loadLazyChunks.ts +++ b/src/debug/loadLazyChunks.ts @@ -111,14 +111,14 @@ export async function loadLazyChunks() { Webpack.factoryListeners.add(factory => { let isResolved = false; - searchAndLoadLazyChunks(factory.toString()).then(() => isResolved = true); + searchAndLoadLazyChunks(String(factory)).then(() => isResolved = true); chunksSearchPromises.push(() => isResolved); }); for (const factoryId in wreq.m) { let isResolved = false; - searchAndLoadLazyChunks(wreq.m[factoryId].toString()).then(() => isResolved = true); + searchAndLoadLazyChunks(String(wreq.m[factoryId])).then(() => isResolved = true); chunksSearchPromises.push(() => isResolved); } diff --git a/src/debug/runReporter.ts b/src/debug/runReporter.ts index 4c903bddc..e02e29a36 100644 --- a/src/debug/runReporter.ts +++ b/src/debug/runReporter.ts @@ -33,10 +33,8 @@ async function runReporter() { await Promise.all(Webpack.webpackSearchHistory.map(async ([searchType, args]) => { args = [...args]; - let result: any; + let result = null as any; try { - let result = null as any; - switch (searchType) { case "webpackDependantLazy": case "webpackDependantLazyComponent": { @@ -45,13 +43,12 @@ async function runReporter() { break; } case "extractAndLoadChunks": { - const [code, matcher] = args; - result = true; + const extractAndLoadChunks = args.shift(); - /* result = await Webpack.extractAndLoadChunks(code, matcher); + result = await extractAndLoadChunks(); if (result === false) { result = null; - } */ + } break; } @@ -65,6 +62,14 @@ async function runReporter() { if (findResult[SYM_PROXY_INNER_GET] != null) { result = findResult[SYM_PROXY_INNER_VALUE]; + + if (result != null && searchType === "mapMangledModule") { + for (const innerMap in result) { + if (result[innerMap][SYM_PROXY_INNER_GET] != null) { + throw new Error("Webpack Find Fail"); + } + } + } } if (findResult[SYM_LAZY_COMPONENT_INNER] != null) { @@ -77,7 +82,7 @@ async function runReporter() { } if (result == null) { - throw "a rock at ben shapiro"; + throw new Error("Webpack Find Fail"); } } catch (e) { let logMessage = searchType; @@ -99,23 +104,44 @@ async function runReporter() { parsedArgs === args && ["waitFor", "find", "findComponent", "webpackDependantLazy", "webpackDependantLazyComponent"].includes(searchType) ) { - let filter = parsedArgs[0].toString(); + let filter = String(parsedArgs[0]); if (filter.length > 150) { filter = filter.slice(0, 147) + "..."; } logMessage += `(${filter})`; } else if (searchType === "extractAndLoadChunks") { + const [code, matcher] = parsedArgs; + let regexStr: string; - if (parsedArgs[1] === Webpack.DefaultExtractAndLoadChunksRegex) { + if (matcher === Webpack.DefaultExtractAndLoadChunksRegex) { regexStr = "DefaultExtractAndLoadChunksRegex"; } else { - regexStr = parsedArgs[1].toString(); + regexStr = String(matcher); } - logMessage += `([${parsedArgs[0].map((arg: any) => `"${arg}"`).join(", ")}], ${regexStr})`; + logMessage += `(${JSON.stringify(code)}, ${regexStr})`; + } else if (searchType === "mapMangledModule") { + const [code, mappers] = parsedArgs; + + const parsedFailedMappers = Object.entries(mappers) + .filter(([key]) => result == null || result[key][SYM_PROXY_INNER_GET] != null) + .map(([key, filter]) => { + let parsedFilter: string; + + if (filter.$$vencordProps != null) { + const filterName = filter.$$vencordProps[0]; + parsedFilter = `${filterName}(${filter.$$vencordProps.slice(1).map((arg: any) => JSON.stringify(arg)).join(", ")})`; + } else { + parsedFilter = String(filter).slice(0, 147) + "..."; + } + + return [key, parsedFilter]; + }); + + logMessage += `(${JSON.stringify(code)}, {\n${parsedFailedMappers.map(([key, parsedFilter]) => `\t${key}: ${parsedFilter}`).join(",\n")}\n})`; } else { - logMessage += `(${filterName.length ? `${filterName}(` : ""}${parsedArgs.map(arg => `"${arg}"`).join(", ")})${filterName.length ? ")" : ""}`; + logMessage += `(${filterName.length ? `${filterName}(` : ""}${parsedArgs.map(arg => JSON.stringify(arg)).join(", ")})${filterName.length ? ")" : ""}`; } ReporterLogger.log("Webpack Find Fail:", logMessage); diff --git a/src/plugins/decor/ui/index.ts b/src/plugins/decor/ui/index.ts index 776fbff02..6890b7d37 100644 --- a/src/plugins/decor/ui/index.ts +++ b/src/plugins/decor/ui/index.ts @@ -10,5 +10,5 @@ import { extractAndLoadChunksLazy, findByProps } from "@webpack"; export const cl = classNameFactory("vc-decor-"); export const DecorationModalStyles = findByProps("modalFooterShopButton"); -export const requireAvatarDecorationModal = extractAndLoadChunksLazy([".COLLECTIBLES_SHOP_FULLSCREEN&&"]); -export const requireCreateStickerModal = extractAndLoadChunksLazy(["stickerInspected]:"]); +export const requireAvatarDecorationModal = extractAndLoadChunksLazy(".COLLECTIBLES_SHOP_FULLSCREEN&&"); +export const requireCreateStickerModal = extractAndLoadChunksLazy("stickerInspected]:"); diff --git a/src/plugins/devCompanion.dev/index.tsx b/src/plugins/devCompanion.dev/index.tsx index c00dd0786..7842655ba 100644 --- a/src/plugins/devCompanion.dev/index.tsx +++ b/src/plugins/devCompanion.dev/index.tsx @@ -160,7 +160,7 @@ function initWs(isManual = false) { return reply("Expected exactly one 'find' matches, found " + keys.length); const mod = candidates[keys[0]]; - let src = String(mod.original ?? mod).replaceAll("\n", ""); + let src = String(mod).replaceAll("\n", ""); if (src.startsWith("function(")) { src = "0," + src; diff --git a/src/plugins/fakeProfileThemes/index.tsx b/src/plugins/fakeProfileThemes/index.tsx index 093824e46..860463086 100644 --- a/src/plugins/fakeProfileThemes/index.tsx +++ b/src/plugins/fakeProfileThemes/index.tsx @@ -111,7 +111,7 @@ interface ProfileModalProps { const ColorPicker = findComponentByCode(".Messages.USER_SETTINGS_PROFILE_COLOR_SELECT_COLOR", ".BACKGROUND_PRIMARY)"); const ProfileModal = findComponentByCode('"ProfileCustomizationPreview"'); -const requireColorPicker = extractAndLoadChunksLazy(["USER_SETTINGS_PROFILE_COLOR_DEFAULT_BUTTON.format"], /createPromise:\(\)=>\i\.\i\("?(.+?)"?\).then\(\i\.bind\(\i,"?(.+?)"?\)\)/); +const requireColorPicker = extractAndLoadChunksLazy("USER_SETTINGS_PROFILE_COLOR_DEFAULT_BUTTON.format", /createPromise:\(\)=>\i\.\i\("?(.+?)"?\).then\(\i\.bind\(\i,"?(.+?)"?\)\)/); export default definePlugin({ name: "FakeProfileThemes", diff --git a/src/plugins/pinDms/components/CreateCategoryModal.tsx b/src/plugins/pinDms/components/CreateCategoryModal.tsx index be4294cb7..f9b8d0395 100644 --- a/src/plugins/pinDms/components/CreateCategoryModal.tsx +++ b/src/plugins/pinDms/components/CreateCategoryModal.tsx @@ -33,7 +33,7 @@ interface ColorPickerWithSwatchesProps { const ColorPicker = findComponentByCode(".Messages.USER_SETTINGS_PROFILE_COLOR_SELECT_COLOR", ".BACKGROUND_PRIMARY)"); const ColorPickerWithSwatches = findExportedComponent("ColorPicker", "CustomColorPicker"); -export const requireSettingsMenu = extractAndLoadChunksLazy(['name:"UserSettings"'], /createPromise:.{0,20}Promise\.all\((\[\i\.\i\("?.+?"?\).+?\])\).then\(\i\.bind\(\i,"?(.+?)"?\)\).{0,50}"UserSettings"/); +export const requireSettingsMenu = extractAndLoadChunksLazy('name:"UserSettings"', /createPromise:.{0,20}Promise\.all\((\[\i\.\i\("?.+?"?\).+?\])\).then\(\i\.bind\(\i,"?(.+?)"?\)\).{0,50}"UserSettings"/); const cl = classNameFactory("vc-pindms-modal-"); diff --git a/src/webpack/webpack.tsx b/src/webpack/webpack.tsx index 36f243300..e3f9aaccc 100644 --- a/src/webpack/webpack.tsx +++ b/src/webpack/webpack.tsx @@ -782,7 +782,7 @@ export function extractAndLoadChunksLazy(code: string | string[], matcher: RegEx }); if (IS_REPORTER) { - webpackSearchHistory.push(["extractAndLoadChunks", [extractAndLoadChunks]]); + webpackSearchHistory.push(["extractAndLoadChunks", [extractAndLoadChunks, code, matcher]]); } return extractAndLoadChunks;