From c3ff092162ef1a98bea78213e473be3207998d72 Mon Sep 17 00:00:00 2001 From: ArjixWasTaken <53124886+ArjixWasTaken@users.noreply.github.com> Date: Wed, 31 Aug 2022 21:53:36 +0300 Subject: [PATCH] Add nitro bypass (#4) --- .vscode/settings.json | 1 + package.json | 1 + pnpm-lock.yaml | 38 +++++++++++++++-- src/api/MessageClicks.ts | 17 -------- src/api/MessageEvents.ts | 73 +++++++++++++++++++++++++++++++++ src/api/index.ts | 2 +- src/patcher.ts | 8 ++-- src/plugins/apiMessageClicks.ts | 16 -------- src/plugins/apiMessageEvents.ts | 28 +++++++++++++ src/plugins/messageActions.ts | 4 +- src/plugins/nitroBypass.ts | 58 ++++++++++++++++++++++++++ 11 files changed, 204 insertions(+), 42 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 src/api/MessageClicks.ts create mode 100644 src/api/MessageEvents.ts delete mode 100644 src/plugins/apiMessageClicks.ts create mode 100644 src/plugins/apiMessageEvents.ts create mode 100644 src/plugins/nitroBypass.ts diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..9e26dfeeb --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/package.json b/package.json index 1e9c135c9..6b842a1cd 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "esbuild": "^0.15.5" }, "dependencies": { + "discord-types": "^1.3.26", "electron-devtools-installer": "^3.2.0", "jsposed": "^1.0.2", "prettier": "^2.7.1" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ab8208bab..f1774b509 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,9 +1,10 @@ -lockfileVersion: 5.3 +lockfileVersion: 5.4 specifiers: '@types/flux': ^3.1.11 '@types/node': ^18.7.13 '@types/react': ^18.0.17 + discord-types: ^1.3.26 electron: ^20.1.0 electron-devtools-installer: ^3.2.0 esbuild: ^0.15.5 @@ -11,6 +12,7 @@ specifiers: prettier: ^2.7.1 dependencies: + discord-types: 1.3.26 electron-devtools-installer: 3.2.0 jsposed: 1.0.2 prettier: 2.7.1 @@ -74,6 +76,12 @@ packages: '@types/react': 18.0.17 dev: true + /@types/keyv/3.1.4: + resolution: {integrity: sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg==} + dependencies: + '@types/node': 18.7.13 + dev: true + /@types/node/16.11.56: resolution: {integrity: sha512-aFcUkv7EddxxOa/9f74DINReQ/celqH8DiB3fRYgVDM2Xm5QJL8sl80QKuAnGvwAsMn+H3IFA6WCrQh1CY7m1A==} dev: true @@ -84,7 +92,13 @@ packages: /@types/prop-types/15.7.5: resolution: {integrity: sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==} - dev: true + + /@types/react/17.0.2: + resolution: {integrity: sha512-Xt40xQsrkdvjn1EyWe1Bc0dJLcil/9x2vAuW7ya+PuQip4UYUaXyhzWmAbwRsdMgwOFHpfp7/FFZebDU6Y8VHA==} + dependencies: + '@types/prop-types': 15.7.5 + csstype: 3.1.0 + dev: false /@types/react/18.0.17: resolution: {integrity: sha512-38ETy4tL+rn4uQQi7mB81G7V1g0u2ryquNmsVIOKUAEIDK+3CUjZ6rSRpdvS99dNBnkLFL83qfmtLacGOTIhwQ==} @@ -94,6 +108,12 @@ packages: csstype: 3.1.0 dev: true + /@types/responselike/1.0.0: + resolution: {integrity: sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==} + dependencies: + '@types/node': 18.7.13 + dev: true + /@types/scheduler/0.16.2: resolution: {integrity: sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==} dev: true @@ -163,7 +183,6 @@ packages: /csstype/3.1.0: resolution: {integrity: sha512-uX1KG+x9h5hIJsaKR9xHUeUraxf8IODOwq9JLNPq6BwB04a/xgpq3rcx47l5BZu5zBPlgD342tdke3Hom/nJRA==} - dev: true /debug/4.3.4: resolution: {integrity: sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==} @@ -202,6 +221,13 @@ packages: dev: true optional: true + /discord-types/1.3.26: + resolution: {integrity: sha512-ToG51AOCH+JTQf7b+8vuYQe5Iqwz7nZ7StpECAZ/VZcI1ZhQk13pvt9KkRTfRv1xNvwJ2qib4e3+RifQlo8VPQ==} + dependencies: + '@types/react': 17.0.2 + moment: 2.29.4 + dev: false + /duplexer3/0.1.5: resolution: {integrity: sha512-1A8za6ws41LQgv9HrE/66jyC5yuSjQ3L/KOpFtoBilsAK2iA2wuS5rTt1OCzIvtS2V7nVmedsUU+DGRcjBmOYA==} dev: true @@ -577,6 +603,8 @@ packages: dependencies: '@sindresorhus/is': 0.14.0 '@szmarczak/http-timer': 1.1.2 + '@types/keyv': 3.1.4 + '@types/responselike': 1.0.0 cacheable-request: 6.1.0 decompress-response: 3.3.0 duplexer3: 0.1.5 @@ -732,6 +760,10 @@ packages: minimist: 1.2.6 dev: false + /moment/2.29.4: + resolution: {integrity: sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==} + dev: false + /ms/2.1.2: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} dev: true diff --git a/src/api/MessageClicks.ts b/src/api/MessageClicks.ts deleted file mode 100644 index 476896d85..000000000 --- a/src/api/MessageClicks.ts +++ /dev/null @@ -1,17 +0,0 @@ -type Listener = (message, channel, event) => void; - -const listeners = new Set(); - -export function _handleClick(message, channel, event) { - for (const listener of listeners) { - listener(message, channel, event); - } -} - -export function addListener(listener: Listener) { - listeners.add(listener); -} - -export function removeListener(listener: Listener) { - return listeners.delete(listener); -} \ No newline at end of file diff --git a/src/api/MessageEvents.ts b/src/api/MessageEvents.ts new file mode 100644 index 000000000..9ee54a6a4 --- /dev/null +++ b/src/api/MessageEvents.ts @@ -0,0 +1,73 @@ +import type { Message, Channel } from 'discord-types/general'; +import Logger from '../utils/logger'; + +const MessageEventsLogger = new Logger("MessageEvents", "#e5c890"); + +interface Emoji { + require_colons: boolean, + originalName: string, + animated: boolean + guildId: string, + name: string, + url: string, + id: string, +} + +interface MessageObject { + content: string, + validNonShortcutEmojis: Emoji[] +} + +type SendListener = (channelId: string, messageObj: MessageObject, extra: any) => void; +type EditListener = (channelId: string, messageId: string, messageObj: MessageObject) => void; + +const sendListeners = new Set(); +const editListeners = new Set(); + +export function _handlePreSend(channelId: string, messageObj: MessageObject, extra: any) { + for (const listener of sendListeners) { + try { + listener(channelId, messageObj, extra); + } catch (e) { MessageEventsLogger.error(`MessageSendHandler: Listener encoutered an unknown error. (${e})`) } + } +} + +export function _handlePreEdit(channeld: string, messageId: string, messageObj: MessageObject) { + for (const listener of editListeners) { + try { + listener(channeld, messageId, messageObj); + } catch (e) { MessageEventsLogger.error(`MessageEditHandler: Listener encoutered an unknown error. (${e})`) } + } +} + +/** + * Note: This event fires off before a message is sent, allowing you to edit the message. + */ +export function addPreSendListener(listener: SendListener) { sendListeners.add(listener) } +/** + * Note: This event fires off before a message's edit is applied, allowing you to further edit the message. + */ +export function addPreEditListener(listener: EditListener) { editListeners.add(listener) } +export function removePreSendListener(listener: SendListener) { sendListeners.delete(listener) } +export function removePreEditListener(listener: EditListener) { editListeners.delete(listener) } + +// Message clicks +type ClickListener = (message: Message, channel: Channel, event: MouseEvent) => void; + +const listeners = new Set(); + +export function _handleClick(message, channel, event) { + for (const listener of listeners) { + try { + listener(message, channel, event); + } catch (e) { MessageEventsLogger.error(`MessageClickHandler: Listener encoutered an unknown error. (${e})`) } + } +} + +export function addClickListener(listener: ClickListener) { + listeners.add(listener); +} + +export function removeClickListener(listener: ClickListener) { + return listeners.delete(listener); +} \ No newline at end of file diff --git a/src/api/index.ts b/src/api/index.ts index 6688927a6..617241873 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1 +1 @@ -export * as MessageClicks from "./MessageClicks"; \ No newline at end of file +export * as MessageEvents from "./MessageEvents"; \ No newline at end of file diff --git a/src/patcher.ts b/src/patcher.ts index e991377d9..72562f2c1 100644 --- a/src/patcher.ts +++ b/src/patcher.ts @@ -3,8 +3,10 @@ import electron, { app, BrowserWindowConstructorOptions } from "electron"; import installExt, { REACT_DEVELOPER_TOOLS } from "electron-devtools-installer"; import { join } from "path"; import { initIpc } from './ipcMain'; +import Logger from "./utils/logger"; -console.log("[Vencord] Starting up..."); +const logger = new Logger("Patcher", "#700b90") +logger.log("[Vencord] Starting up..."); class BrowserWindow extends electron.BrowserWindow { constructor(options: BrowserWindowConstructorOptions) { @@ -48,8 +50,8 @@ process.env.DATA_DIR = join(app.getPath("userData"), "..", "Vencord"); electron.app.whenReady().then(() => { installExt(REACT_DEVELOPER_TOOLS) - .then(() => console.log("Installed React DevTools")) - .catch((err) => console.error("Failed to install React DevTools", err)); + .then(() => logger.log("Installed React DevTools")) + .catch((err) => logger.error("Failed to install React DevTools", err)); // Remove CSP electron.session.defaultSession.webRequest.onHeadersReceived(({ responseHeaders, url }, cb) => { diff --git a/src/plugins/apiMessageClicks.ts b/src/plugins/apiMessageClicks.ts deleted file mode 100644 index 7155b943a..000000000 --- a/src/plugins/apiMessageClicks.ts +++ /dev/null @@ -1,16 +0,0 @@ -import definePlugin from "../utils/types"; - -export default definePlugin({ - name: "MessageClicksApi", - description: "Api required by anything using message click actions", - author: "Vendicated", - patches: [{ - find: "if(e.altKey){", - replacement: { - match: /\.useClickMessage=function\((.{1,2}),(.{1,2})\).+?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.MessageClicks._handleClick(_msg, _chan, ${event});` - } - }] -}); diff --git a/src/plugins/apiMessageEvents.ts b/src/plugins/apiMessageEvents.ts new file mode 100644 index 000000000..79acd3241 --- /dev/null +++ b/src/plugins/apiMessageEvents.ts @@ -0,0 +1,28 @@ +import definePlugin from "../utils/types"; + +export default definePlugin({ + name: "MessageEventsAPI", + description: "Api required by anything using message events.", + author: "ArjixWasTaken", + patches: [ + { + find: "sendMessage:function", + replacement: [{ + match: /(?<=sendMessage:function\(.{1,2},.{1,2},.{1,2},.{1,2}\)){/, + replace: "{Vencord.Api.MessageEvents._handlePreSend(...arguments);" + }, { + match: /(?<=editMessage:function\(.{1,2},.{1,2},.{1,2}\)){/, + replace: "{Vencord.Api.MessageEvents._handlePreEdit(...arguments);" + }] + }, + { + find: "if(e.altKey){", + replacement: { + match: /\.useClickMessage=function\((.{1,2}),(.{1,2})\).+?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});` + } + } + ] +}); diff --git a/src/plugins/messageActions.ts b/src/plugins/messageActions.ts index 5519cf735..88e625e5d 100644 --- a/src/plugins/messageActions.ts +++ b/src/plugins/messageActions.ts @@ -1,4 +1,4 @@ -import { MessageClicks } from "../api"; +import { addClickListener } from "../api/MessageEvents"; import definePlugin from "../utils/types"; import { find, findByProps } from "../webpack"; @@ -21,7 +21,7 @@ export default definePlugin({ if (e.key === "Backspace") isDeletePressed = false; }); - MessageClicks.addListener((msg, chan, event) => { + addClickListener((msg, chan, event) => { const isMe = msg.author.id === getCurrentUser().id; if (!isDeletePressed) { if (isMe && event.detail >= 2) { diff --git a/src/plugins/nitroBypass.ts b/src/plugins/nitroBypass.ts new file mode 100644 index 000000000..25c1aa66e --- /dev/null +++ b/src/plugins/nitroBypass.ts @@ -0,0 +1,58 @@ +import { addPreSendListener, addPreEditListener } from "../api/MessageEvents"; +import { findByProps } from "../utils/webpack"; +import definePlugin from "../utils/types" + +export default definePlugin({ + name: "Nitro Bypass", + author: "ArjixWasTaken", + description: "Allows you to stream in nitro quality and send fake emojis.", + patches: [ + { + find: `canUseAnimatedEmojis:function`, + replacement: [ + "canUseAnimatedEmojis", + "canUseEmojisEverywhere", + "canUseHigherFramerate" + ].map(func => { + return { + match: new RegExp(`${func}:function\\(.+?}`), + replace: `${func}:function (e) { return true; }` + } + }) + }, + ], + start() { + const { getCustomEmojiById } = findByProps("getCustomEmojiById"); + + // Remove any nitro requirements for any of the streaming settings. + findByProps("ApplicationStreamPresets") + .ApplicationStreamSettingRequirements + .forEach(x => { + delete x.userPremiumType; + delete x.guildPremiumTier + }); + + addPreSendListener((_, messageObj) => { + const guildId = window.location.href.split("channels/")[1].split("/")[0]; + for (const emoji of messageObj.validNonShortcutEmojis) { + if (!emoji.require_colons) continue; + if (emoji.guildId === guildId && !emoji.animated) continue; + + const emojiString = `<${emoji.animated ? 'a' : ''}:${emoji.originalName || emoji.name}:${emoji.id}>`; + const url = emoji.url.replace(/\?size=[0-9]+/, `?size=48`); + messageObj.content = messageObj.content.replace(emojiString, ` ${url} `); + } + }) + addPreEditListener((_, __, messageObj) => { + const guildId = window.location.href.split("channels/")[1].split("/")[0]; + + for (const [emojiStr, _, emojiId] of messageObj.content.matchAll(/(?/ig)) { + const emoji = getCustomEmojiById(emojiId); + if (emoji == null || (emoji.guildId === guildId && !emoji.animated)) continue; + + const url = emoji.url.replace(/\?size=[0-9]+/, `?size=48`); + messageObj.content = messageObj.content.replace(emojiStr, ` ${url} `); + } + }) + }, +})