Fix Dev Companion Mostly

This commit is contained in:
thororen1234 2025-02-07 20:49:57 -05:00
parent 691b5cd2ed
commit 2aaf97518c
3 changed files with 18 additions and 4 deletions

View file

@ -24,7 +24,6 @@ import definePlugin, { OptionType, ReporterTestable } from "@utils/types";
import { initWs, socket, stopWs } from "./initWs"; import { initWs, socket, stopWs } from "./initWs";
console.log("imported"); console.log("imported");
export const PORT = 8485; export const PORT = 8485;
const NAV_ID = "dev-companion-reconnect";
export const logger = new Logger("DevCompanion"); export const logger = new Logger("DevCompanion");

View file

@ -9,20 +9,29 @@ import { Settings } from "@api/Settings";
import { canonicalizeMatch } from "@utils/patches"; import { canonicalizeMatch } from "@utils/patches";
import { CodeFilter, stringMatches, wreq } from "@webpack"; import { CodeFilter, stringMatches, wreq } from "@webpack";
import { Toasts } from "@webpack/common"; import { Toasts } from "@webpack/common";
import { AnyWebpackRequire } from "webpack";
import { settings as companionSettings } from "."; import { settings as companionSettings } from ".";
import { Recieve } from "./types"; 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 * extracts the patched module, if there is no patched module, throws an error
* @param id module id * @param id module id
*/ */
export function extractOrThrow(id: number): string { export function extractOrThrow(id: number): string {
const module = wreq.m[id]; 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); 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 * 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]; const module = wreq.m[id];
if (!module) if (!module)
throw new Error("No module found for module id:" + id); 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 { export function parseNode(node: Recieve.FindNode): any {
switch (node.type) { switch (node.type) {
case "string": case "string":

View file

@ -45,6 +45,9 @@
"@webpack": [ "@webpack": [
"./webpack/webpack" "./webpack/webpack"
], ],
"@webpack/patch": [
"./webpack/patchWebpack"
],
"@plugins": [ "@plugins": [
"./plugins" "./plugins"
], ],