From 6398dd25d20e6bc3e02425b709233066baf64e0c Mon Sep 17 00:00:00 2001 From: Vendicated Date: Tue, 27 Sep 2022 14:34:57 +0200 Subject: [PATCH] Unbrick Vencord - Pt 1 --- src/plugins/STFU.ts | 4 ++-- src/plugins/apiMessageEvents.ts | 8 ++++---- src/plugins/cumcord.ts | 14 -------------- src/plugins/ify.ts | 9 +++------ src/plugins/messageActions.ts | 2 +- src/plugins/noTrack.ts | 6 +++--- src/plugins/settings.ts | 20 +++++++------------- src/utils/patchWebpack.ts | 8 +++++--- src/webpack/webpack.ts | 11 +++++++++-- 9 files changed, 34 insertions(+), 48 deletions(-) delete mode 100644 src/plugins/cumcord.ts diff --git a/src/plugins/STFU.ts b/src/plugins/STFU.ts index ee9c90f38..afa29f501 100644 --- a/src/plugins/STFU.ts +++ b/src/plugins/STFU.ts @@ -7,8 +7,8 @@ export default definePlugin({ patches: [{ find: "setDevtoolsCallbacks", replacement: { - match: /\.default=function.+$/, - replace: ".default=function(){}}" + match: /\.setDevtoolsCallbacks\(.+?else/, + replace: ".setDevtoolsCallbacks(null,null);else" } }] }); diff --git a/src/plugins/apiMessageEvents.ts b/src/plugins/apiMessageEvents.ts index 79acd3241..98144e218 100644 --- a/src/plugins/apiMessageEvents.ts +++ b/src/plugins/apiMessageEvents.ts @@ -8,20 +8,20 @@ export default definePlugin({ { find: "sendMessage:function", replacement: [{ - match: /(?<=sendMessage:function\(.{1,2},.{1,2},.{1,2},.{1,2}\)){/, + match: /(?<=_sendMessage:function\([^)]+\)){/, replace: "{Vencord.Api.MessageEvents._handlePreSend(...arguments);" }, { - match: /(?<=editMessage:function\(.{1,2},.{1,2},.{1,2}\)){/, + match: /(?<=\beditMessage:function\([^)]+\)){/, replace: "{Vencord.Api.MessageEvents._handlePreEdit(...arguments);" }] }, { find: "if(e.altKey){", replacement: { - match: /\.useClickMessage=function\((.{1,2}),(.{1,2})\).+?function\((.{1,2})\){/, + match: /var \w=(\w)\.id,\w=(\w)\.id;return .{1,2}\.useCallback\(\(?function\((.{1,2})\){/, replace: (m, message, channel, event) => // the message param is shadowed by the event param, so need to alias them - `${m.replace("{", `{var _msg=${message};var _chan=${channel};`)}Vencord.Api.MessageEvents._handleClick(_msg, _chan, ${event});` + `var _msg=${message},_chan=${channel};${m}Vencord.Api.MessageEvents._handleClick(_msg, _chan, ${event});` } } ] diff --git a/src/plugins/cumcord.ts b/src/plugins/cumcord.ts deleted file mode 100644 index 626079b4f..000000000 --- a/src/plugins/cumcord.ts +++ /dev/null @@ -1,14 +0,0 @@ -import definePlugin from "../utils/types"; - -export default definePlugin({ - name: "cumcord", - description: "Loads cumcord. That's it", - author: "Vendicated", - async start() { - const cum = await fetch("https://raw.githubusercontent.com/Cumcord/Cumcord/stable/dist/build.js"); - (0, eval)(await cum.text()); - }, - stop() { - window.cumcord?.uninject(); - }, -}); diff --git a/src/plugins/ify.ts b/src/plugins/ify.ts index 76cfa59b4..e0d54816e 100644 --- a/src/plugins/ify.ts +++ b/src/plugins/ify.ts @@ -7,17 +7,14 @@ export default definePlugin({ patches: [ { find: '.displayName="SpotifyStore"', - replacement: { + replacement: [{ match: /\.isPremium=.;/, replace: ".isPremium=true;", - }, - }, - { - find: '.displayName="SpotifyStore"', - replacement: ["SPEAKING", "VOICE_STATE_UPDATES", "MEDIA_ENGINE_SET_DESKTOP_SOURCE"].map(event => ({ + }, ...["SPEAKING", "VOICE_STATE_UPDATES", "MEDIA_ENGINE_SET_DESKTOP_SOURCE"].map(event => ({ match: new RegExp(`${event}:function\\(.\\){.+?}(,|}\\))`), replace: (_, ending) => `${event}:function(){}${ending}`, })), + ], }, ] }); diff --git a/src/plugins/messageActions.ts b/src/plugins/messageActions.ts index 42f2e2f72..569d3a9b8 100644 --- a/src/plugins/messageActions.ts +++ b/src/plugins/messageActions.ts @@ -16,7 +16,7 @@ export default definePlugin({ start() { const { deleteMessage, startEditMessage } = findByProps("deleteMessage"); const { can } = findByProps("can", "initialize"); - const { Permissions: { MANAGE_MESSAGES } } = find(m => m.Permissions?.MANAGE_MESSAGES); + const { MANAGE_MESSAGES } = find(m => typeof m.MANAGE_MESSAGES === "bigint"); const { isEditing } = findByProps("isEditing"); document.addEventListener("keydown", keydown); diff --git a/src/plugins/noTrack.ts b/src/plugins/noTrack.ts index ff4b95c49..49f542e6a 100644 --- a/src/plugins/noTrack.ts +++ b/src/plugins/noTrack.ts @@ -9,14 +9,14 @@ export default definePlugin({ { find: "TRACKING_URL:", replacement: { - match: /=\(0,.\.analyticsTrackingStoreMaker\)/, - replace: "=(function(){})", + match: /^.+$/, + replace: "()=>{}", }, }, { find: "window.DiscordSentry=", replacement: { - match: /window\.DiscordSentry=\(0,.\.initSentry\)\(\)/, + match: /window\.DiscordSentry=function.+\}\(\)/, replace: "", } } diff --git a/src/plugins/settings.ts b/src/plugins/settings.ts index 7d6af2dd5..1281f4edc 100644 --- a/src/plugins/settings.ts +++ b/src/plugins/settings.ts @@ -7,33 +7,27 @@ export default definePlugin({ author: "Vendicated", required: true, patches: [{ - find: "default.versionHash", + find: "().versionHash", replacement: [ { - match: /return .{1,2}\("div"/, - replace: (m) => { - return `var versions=VencordNative.getVersions();${m}`; - } - }, - { - match: /\w\.createElement.+?["']Host ["'].+?\):null/, + match: /\w\.createElement\(.{1,2}.Fragment,.{0,30}\{[^}]+\},"Host ".+?\):null/, replace: m => { const idx = m.indexOf("Host") - 1; const template = m.slice(0, idx); return `${m}, ${template}"Vencord ", "${gitHash}"), " "), ` + - `${template} "Electron ", versions.electron), " "), ` + - `${template} "Chrome ", versions.chrome), " ")`; + `${template} "Electron ",VencordNative.getVersions().electron)," "), ` + + `${template} "Chrome ",VencordNative.getVersions().chrome)," ")`; } } ] }, { find: "Messages.ACTIVITY_SETTINGS", replacement: { - match: /\{section:(.{1,2})\.SectionTypes\.HEADER,\s*label:(.{1,2})\.default\.Messages\.ACTIVITY_SETTINGS\}/, + match: /\{section:(.{1,2})\.ID\.HEADER,\s*label:(.{1,2})\..{1,2}\.Messages\.ACTIVITY_SETTINGS\}/, replace: (m, mod) => - `{section:${mod}.SectionTypes.HEADER,label:"Vencord"},` + + `{section:${mod}.ID.HEADER,label:"Vencord"},` + `{section:"Vencord",label:"Vencord",element:Vencord.Components.Settings},` + - `{section:${mod}.SectionTypes.DIVIDER},${m}` + `{section:${mod}.ID.DIVIDER},${m}` } }] diff --git a/src/utils/patchWebpack.ts b/src/utils/patchWebpack.ts index 488e430fe..ce29c82dd 100644 --- a/src/utils/patchWebpack.ts +++ b/src/utils/patchWebpack.ts @@ -65,9 +65,11 @@ function patchPush() { if (filter(exports)) { subscriptions.delete(filter); callback(exports); - } else if (exports.default && filter(exports.default)) { - subscriptions.delete(filter); - callback(exports.default); + } else for (const nested in exports) { + if (exports[nested] && filter(exports[nested])) { + subscriptions.delete(filter); + callback(exports[nested]); + } } } catch (err) { logger.error("Error while firing callback for webpack chunk", err); diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts index 27306de53..a1fd2fb2a 100644 --- a/src/webpack/webpack.ts +++ b/src/webpack/webpack.ts @@ -32,15 +32,22 @@ export function find(filter: FilterFn, getDefault = true) { for (const key in cache) { const mod = cache[key]; - if (mod?.exports && filter(mod.exports)) + if (!mod?.exports) continue; + + if (filter(mod.exports)) return mod.exports; - if (mod?.exports?.default && filter(mod.exports.default)) + if (mod.exports.default && filter(mod.exports.default)) return getDefault ? mod.exports.default : mod.exports; + for (const nestedMod in mod.exports) { + const nested = mod.exports[nestedMod]; + if (nested && filter(nested)) return nested; + } } return null; } +// TODO fix export function findAll(filter: FilterFn, getDefault = true) { if (typeof filter !== "function") throw new Error("Invalid filter. Expected a function got", filter);