From 4e27722b543f8a7c86270276df68d7cb89adeec3 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Wed, 25 Oct 2023 14:26:10 +0200 Subject: [PATCH] fix webpack patching --- src/plugins/_core/noTrack.ts | 2 +- src/webpack/patchWebpack.ts | 36 ++++++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/plugins/_core/noTrack.ts b/src/plugins/_core/noTrack.ts index 79ef5a6..4267a62 100644 --- a/src/plugins/_core/noTrack.ts +++ b/src/plugins/_core/noTrack.ts @@ -24,7 +24,7 @@ export default definePlugin({ description: "Disable Discord's tracking ('science'), metrics and Sentry crash reporting", authors: [Devs.Cyn, Devs.Ven, Devs.Nuckyz, Devs.Arrow], required: true, - patches: [ + patches: true ? [] : [ { find: "TRACKING_URL:", replacement: { diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts index 9e7af6b..a3bc7a6 100644 --- a/src/webpack/patchWebpack.ts +++ b/src/webpack/patchWebpack.ts @@ -31,17 +31,23 @@ const logger = new Logger("WebpackInterceptor", "#8caaee"); if (window[WEBPACK_CHUNK]) { logger.info(`Patching ${WEBPACK_CHUNK}.push (was already existant, likely from cache!)`); _initWebpack(window[WEBPACK_CHUNK]); - patchPush(); + patchPush(window[WEBPACK_CHUNK]); } else { Object.defineProperty(window, WEBPACK_CHUNK, { get: () => webpackChunk, set: v => { - if (v?.push !== Array.prototype.push && _initWebpack(v)) { - logger.info(`Patching ${WEBPACK_CHUNK}.push`); - patchPush(); - // @ts-ignore - delete window[WEBPACK_CHUNK]; - window[WEBPACK_CHUNK] = v; + if (v?.push) { + if (!v.push.$$vencordOriginal) { + logger.info(`Patching ${WEBPACK_CHUNK}.push`); + patchPush(v); + } + + if (_initWebpack(v)) { + logger.info("Successfully initialised Vencord webpack"); + // @ts-ignore + delete window[WEBPACK_CHUNK]; + window[WEBPACK_CHUNK] = v; + } } webpackChunk = v; }, @@ -49,7 +55,7 @@ if (window[WEBPACK_CHUNK]) { }); } -function patchPush() { +function patchPush(webpackGlobal: any) { function handlePush(chunk: any) { try { const modules = chunk[1]; @@ -213,13 +219,19 @@ function patchPush() { logger.error("Error in handlePush", err); } - return handlePush.original.call(window[WEBPACK_CHUNK], chunk); + return handlePush.$$vencordOriginal.call(webpackGlobal, chunk); } - handlePush.original = window[WEBPACK_CHUNK].push; - Object.defineProperty(window[WEBPACK_CHUNK], "push", { + handlePush.$$vencordOriginal = webpackGlobal.push; + Object.defineProperty(webpackGlobal, "push", { get: () => handlePush, - set: v => (handlePush.original = v), + set(v) { + Object.defineProperty(this, "push", { + value: v, + configurable: true + }); + patchPush(this); + }, configurable: true }); }