diff --git a/src/plugins/devCompanion.dev/index.tsx b/src/plugins/devCompanion.dev/index.tsx index b73be57e..50afbb0f 100644 --- a/src/plugins/devCompanion.dev/index.tsx +++ b/src/plugins/devCompanion.dev/index.tsx @@ -24,7 +24,6 @@ import definePlugin, { OptionType, ReporterTestable } from "@utils/types"; import { initWs, socket, stopWs } from "./initWs"; console.log("imported"); export const PORT = 8485; -const NAV_ID = "dev-companion-reconnect"; export const logger = new Logger("DevCompanion"); diff --git a/src/plugins/devCompanion.dev/util.tsx b/src/plugins/devCompanion.dev/util.tsx index 95d6c403..841d49bc 100644 --- a/src/plugins/devCompanion.dev/util.tsx +++ b/src/plugins/devCompanion.dev/util.tsx @@ -9,20 +9,29 @@ import { Settings } from "@api/Settings"; import { canonicalizeMatch } from "@utils/patches"; import { CodeFilter, stringMatches, wreq } from "@webpack"; import { Toasts } from "@webpack/common"; +import { AnyWebpackRequire } from "webpack"; import { settings as companionSettings } from "."; import { Recieve } from "./types"; +const SYM_PATCHED_SOURCE = Symbol("WebpackPatcher.patchedSource"); + +function getFactoryPatchedSource(id: PropertyKey, webpackRequire = wreq as AnyWebpackRequire) { + return webpackRequire.m[id]?.[SYM_PATCHED_SOURCE]; +} + /** * extracts the patched module, if there is no patched module, throws an error * @param id module id */ export function extractOrThrow(id: number): string { const module = wreq.m[id]; - if (!module?.$$vencordPatchedSource) + const patchedSource = getFactoryPatchedSource(id); + if (!patchedSource) throw new Error("No patched module found for module id " + id); - return module.$$vencordPatchedSource; + return patchedSource; } + /** * attempts to extract the module, throws if not found * @@ -35,8 +44,11 @@ export function extractModule(id: number, patched = companionSettings.store.useP const module = wreq.m[id]; if (!module) throw new Error("No module found for module id:" + id); - return patched ? module.$$vencordPatchedSource ?? module.original.toString() : module.original.toString(); + const original = module.toString(); + const patchedSource = getFactoryPatchedSource(id); + return patched ? patchedSource ?? original : original; } + export function parseNode(node: Recieve.FindNode): any { switch (node.type) { case "string": diff --git a/tsconfig.json b/tsconfig.json index 2e8eb8ef..feeaa8b4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -45,6 +45,9 @@ "@webpack": [ "./webpack/webpack" ], + "@webpack/patch": [ + "./webpack/patchWebpack" + ], "@plugins": [ "./plugins" ],