From 5e2ec368ad6136b8b6e4d71011e1d4187ea81aa8 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Thu, 2 Mar 2023 21:16:03 +0100 Subject: [PATCH] patches: Make $self more robust --- src/utils/patches.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/utils/patches.ts b/src/utils/patches.ts index 8ecd68e80..0f83d4003 100644 --- a/src/utils/patches.ts +++ b/src/utils/patches.ts @@ -27,9 +27,13 @@ export function canonicalizeMatch(match: RegExp | string) { return new RegExp(canonSource, match.flags); } -export function canonicalizeReplace(replace: string | ReplaceFn, pluginName: string) { - if (typeof replace === "function") return replace; - return replace.replaceAll("$self", `Vencord.Plugins.plugins.${pluginName}`); +export function canonicalizeReplace(replace: string | ReplaceFn, pluginName: string): string | ReplaceFn { + const self = `Vencord.Plugins.plugins[${JSON.stringify(pluginName)}]`; + + if (typeof replace !== "function") + return replace.replaceAll("$self", self); + + return (...args) => replace(...args).replaceAll("$self", self); } export function canonicalizeDescriptor(descriptor: TypedPropertyDescriptor, canonicalize: (value: T) => T) {