From 8d31f3cf622771eb3e06d5a7b2f9a7e8f591cd8b Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Wed, 12 Jun 2024 22:14:52 -0300 Subject: [PATCH] Use $$vencordOriginal as fallback --- src/webpack/patchWebpack.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts index 1394d7fac..0ebf6f7ca 100644 --- a/src/webpack/patchWebpack.ts +++ b/src/webpack/patchWebpack.ts @@ -209,6 +209,7 @@ function defineModulesFactoryGetter(id: PropertyKey, factory: PatchedModuleFacto }, set(v: AnyModuleFactory) { if (factory.$$vencordOriginal != null) { + factory.toString = v.toString.bind(v); factory.$$vencordOriginal = v; } else { factory = v; @@ -367,7 +368,7 @@ function patchFactory(id: PropertyKey, factory: AnyModuleFactory) { } if (IS_DEV) { - return originalFactory.apply(this, args); + return patchedFactory.$$vencordOriginal?.apply(this, args); } } @@ -377,15 +378,19 @@ function patchFactory(id: PropertyKey, factory: AnyModuleFactory) { factoryReturn = factory.apply(this, args); } catch (err) { // Just re-throw Discord errors - if (factory === originalFactory) throw err; + if (factory === originalFactory) { + throw err; + } logger.error("Error in patched module factory", err); - return originalFactory.apply(this, args); + return patchedFactory.$$vencordOriginal?.apply(this, args); } // Webpack sometimes sets the value of module.exports directly, so assign exports to it to make sure we properly handle it exports = module?.exports; - if (exports == null) return factoryReturn; + if (exports == null) { + return factoryReturn; + } // There are (at the time of writing) 11 modules exporting the window // Make these non enumerable to improve webpack search performance