From e215e7230c612ff66be44da7dd492e9137ec266b Mon Sep 17 00:00:00 2001 From: sadan4 <117494111+sadan4@users.noreply.github.com> Date: Fri, 12 Jun 2026 22:49:41 -0400 Subject: [PATCH] DevCompaion: fix bug where extracting via find will sometimes search for `[object Object]` (#1173) --- src/plugins/devCompanion.dev/initWs.tsx | 32 ++++++++++++------------- src/plugins/devCompanion.dev/util.tsx | 31 +++++++++++++++++++++++- 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/src/plugins/devCompanion.dev/initWs.tsx b/src/plugins/devCompanion.dev/initWs.tsx index 49e931808..4908524d1 100644 --- a/src/plugins/devCompanion.dev/initWs.tsx +++ b/src/plugins/devCompanion.dev/initWs.tsx @@ -17,7 +17,7 @@ import { React, Toasts, useState } from "@webpack/common"; import { CLIENT_VERSION, logger, PORT, settings } from "."; import { Recieve } from "./types"; import { FullOutgoingMessage, OutgoingMessage } from "./types/send"; -import { extractModule, extractOrThrow, findModuleId, getModulePatchedBy, mkRegexFind, parseNode, toggleEnabled, } from "./util"; +import { extractModule, extractOrThrow, findAllModuleIds, findModuleId, getModulePatchedBy, mkRegexFind, parseNode, toggleEnabled, } from "./util"; export function stopWs() { socket?.close(1000, "Plugin Stopped"); @@ -256,47 +256,47 @@ export function initWs(isManual = false) { } try { - let results: any[]; + let moduleIds: string[]; switch (m.findType.replace("find", "").replace("Lazy", "")) { case "": case "Component": - results = findAll(parsedArgs[0]); + moduleIds = findAllModuleIds(parsedArgs[0]); break; case "CssClasses": - results = findAll(filters.byClassNames(...parsedArgs), { topLevelOnly: true }); + moduleIds = findAllModuleIds(filters.byClassNames(...parsedArgs), { topLevelOnly: true }); break; case "ByProps": - results = findAll(filters.byProps(...parsedArgs)); + moduleIds = findAllModuleIds(filters.byProps(...parsedArgs)); break; case "Store": - results = findAll(filters.byStoreName(parsedArgs[0])); + moduleIds = findAllModuleIds(filters.byStoreName(parsedArgs[0])); break; case "ByCode": - results = findAll(filters.byCode(...parsedArgs)); + moduleIds = findAllModuleIds(filters.byCode(...parsedArgs)); break; case "ModuleId": - results = Object.keys(search(parsedArgs[0])); + moduleIds = Object.keys(search(parsedArgs[0])); break; case "ComponentByCode": - results = findAll(filters.componentByCode(...parsedArgs)); + moduleIds = findAllModuleIds(filters.componentByCode(...parsedArgs)); break; default: return reply("Unknown Find Type " + m.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"; + const uniqueModuleIds = new Set(moduleIds).size; + if (uniqueModuleIds === 0) throw "No results"; + if (uniqueModuleIds > 1) throw "Found more than one result! Make this filter more specific"; // best name ever - const foundFind: string = [...results][0].toString(); + const [foundId] = moduleIds; replyData({ type: "extract", ok: true, data: { - module: foundFind, + module: extractModule(foundId), find: true, - moduleNumber: +findModuleId([foundFind]), - patchedBy: getModulePatchedBy(foundFind) + moduleNumber: +foundId, + patchedBy: getModulePatchedBy(foundId) }, }); } catch (err) { diff --git a/src/plugins/devCompanion.dev/util.tsx b/src/plugins/devCompanion.dev/util.tsx index 7611b8081..75dedb241 100644 --- a/src/plugins/devCompanion.dev/util.tsx +++ b/src/plugins/devCompanion.dev/util.tsx @@ -8,7 +8,8 @@ import { showNotice } from "@api/Notices"; import { plugins, startDependenciesRecursive, startPlugin, stopPlugin } from "@api/PluginManager"; import { Settings } from "@api/Settings"; import { canonicalizeMatch } from "@utils/patches"; -import { CodeFilter, stringMatches, wreq } from "@webpack"; +import { Module } from "@vencord/discord-types/webpack"; +import { CodeFilter, FilterFn, stringMatches, wreq } from "@webpack"; import { Toasts } from "@webpack/common"; import { WebpackPatcher } from "../../Vencord"; @@ -193,3 +194,31 @@ export function toggleEnabled(name: string, beforeReload: (error?: string) => vo settings.enabled = !wasEnabled; beforeReturn(); } + +export function findAllModuleIds(filter: FilterFn, { topLevelOnly = false }: { topLevelOnly?: boolean; } = {}): string[] { + const { c } = wreq; + const ret: string[] = []; + + outer: for (const key in c) { + const mod: Module | undefined = c[key]; + if (!mod?.loaded || mod.exports == null) { + continue; + } + if (filter(mod.exports)) { + ret.push(key); + continue; + } + if (typeof mod.exports !== "object" || topLevelOnly) { + continue; + } + for (const nestedMod in mod.exports) { + const nested = mod.exports[nestedMod]; + if (nested && filter(nested)) { + ret.push(key); + continue outer; + } + } + } + + return ret; +}