2022-10-05 18:42:58 -04:00
|
|
|
import { addPreSendListener, addPreEditListener, removePreSendListener, removePreEditListener } from "../api/MessageEvents";
|
2022-08-31 14:55:58 -04:00
|
|
|
import { findByProps } from "../webpack";
|
2022-10-21 07:37:53 -04:00
|
|
|
import definePlugin, { OptionType } from "../utils/types";
|
2022-10-05 18:42:58 -04:00
|
|
|
import { Devs } from "../utils/constants";
|
|
|
|
import { UserStore } from "../webpack/common";
|
2022-10-21 07:37:53 -04:00
|
|
|
import { Settings } from "../Vencord";
|
2022-08-31 14:53:36 -04:00
|
|
|
|
|
|
|
export default definePlugin({
|
2022-10-01 11:04:57 -04:00
|
|
|
name: "NitroBypass",
|
2022-09-30 20:27:28 -04:00
|
|
|
authors: [Devs.Arjix],
|
2022-08-31 14:53:36 -04:00
|
|
|
description: "Allows you to stream in nitro quality and send fake emojis.",
|
2022-08-31 14:58:21 -04:00
|
|
|
dependencies: ["MessageEventsAPI"],
|
2022-08-31 14:53:36 -04:00
|
|
|
patches: [
|
|
|
|
{
|
2022-10-05 18:42:58 -04:00
|
|
|
find: "canUseAnimatedEmojis:function",
|
2022-10-21 07:37:53 -04:00
|
|
|
predicate: () => Settings.plugins.NitroBypass.enableEmojiBypass === true,
|
2022-08-31 14:53:36 -04:00
|
|
|
replacement: [
|
|
|
|
"canUseAnimatedEmojis",
|
2022-10-21 07:37:53 -04:00
|
|
|
"canUseEmojisEverywhere"
|
|
|
|
].map(func => {
|
|
|
|
return {
|
|
|
|
match: new RegExp(`${func}:function\\(.+?}`),
|
|
|
|
replace: `${func}:function (e) { return true; }`
|
|
|
|
};
|
|
|
|
})
|
|
|
|
},
|
|
|
|
{
|
|
|
|
find: "canUseAnimatedEmojis:function",
|
|
|
|
predicate: () => Settings.plugins.NitroBypass.enableStreamQualityBypass === true,
|
|
|
|
replacement: [
|
2022-10-19 06:27:20 -04:00
|
|
|
"canUseHighVideoUploadQuality",
|
2022-10-06 10:33:30 -04:00
|
|
|
"canStreamHighQuality",
|
|
|
|
"canStreamMidQuality"
|
2022-08-31 14:53:36 -04:00
|
|
|
].map(func => {
|
|
|
|
return {
|
|
|
|
match: new RegExp(`${func}:function\\(.+?}`),
|
|
|
|
replace: `${func}:function (e) { return true; }`
|
2022-08-31 14:55:58 -04:00
|
|
|
};
|
2022-08-31 14:53:36 -04:00
|
|
|
})
|
|
|
|
},
|
2022-10-01 11:04:57 -04:00
|
|
|
{
|
|
|
|
find: "STREAM_FPS_OPTION.format",
|
2022-10-21 07:37:53 -04:00
|
|
|
predicate: () => Settings.plugins.NitroBypass.enableStreamQualityBypass === true,
|
2022-10-01 11:04:57 -04:00
|
|
|
replacement: {
|
|
|
|
match: /(userPremiumType|guildPremiumTier):.{0,10}TIER_\d,?/g,
|
|
|
|
replace: ""
|
|
|
|
}
|
|
|
|
}
|
2022-08-31 14:53:36 -04:00
|
|
|
],
|
2022-10-21 07:37:53 -04:00
|
|
|
options: {
|
|
|
|
enableEmojiBypass: {
|
|
|
|
description: "Allow sending fake emojis",
|
|
|
|
type: OptionType.BOOLEAN,
|
|
|
|
default: true,
|
|
|
|
restartNeeded: true,
|
|
|
|
},
|
|
|
|
enableStreamQualityBypass: {
|
|
|
|
description: "Allow streaming in nitro quality",
|
|
|
|
type: OptionType.BOOLEAN,
|
|
|
|
default: true,
|
|
|
|
restartNeeded: true,
|
|
|
|
}
|
|
|
|
},
|
2022-08-31 16:08:05 -04:00
|
|
|
|
2022-10-01 11:04:57 -04:00
|
|
|
get guildId() {
|
|
|
|
return window.location.href.split("channels/")[1].split("/")[0];
|
|
|
|
},
|
|
|
|
|
|
|
|
get canUseEmotes() {
|
|
|
|
return Boolean(UserStore.getCurrentUser().premiumType);
|
|
|
|
},
|
|
|
|
|
2022-08-31 14:53:36 -04:00
|
|
|
start() {
|
2022-10-21 07:37:53 -04:00
|
|
|
if (!Settings.plugins.NitroBypass.enableEmojiBypass) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-01 11:04:57 -04:00
|
|
|
if (this.canUseEmotes) {
|
|
|
|
console.info("[NitroBypass] Skipping start because you have nitro");
|
|
|
|
return;
|
|
|
|
}
|
2022-08-31 14:53:36 -04:00
|
|
|
|
2022-10-01 11:04:57 -04:00
|
|
|
const { getCustomEmojiById } = findByProps("getCustomEmojiById");
|
2022-08-31 14:53:36 -04:00
|
|
|
|
2022-10-02 16:12:48 -04:00
|
|
|
function getWordBoundary(origStr, offset) {
|
|
|
|
return (!origStr[offset] || /\s/.test(origStr[offset])) ? "" : " ";
|
|
|
|
}
|
|
|
|
|
2022-08-31 16:08:05 -04:00
|
|
|
this.preSend = addPreSendListener((_, messageObj) => {
|
2022-10-08 14:36:57 -04:00
|
|
|
const { guildId } = this;
|
2022-08-31 14:53:36 -04:00
|
|
|
for (const emoji of messageObj.validNonShortcutEmojis) {
|
|
|
|
if (!emoji.require_colons) continue;
|
|
|
|
if (emoji.guildId === guildId && !emoji.animated) continue;
|
|
|
|
|
2022-10-05 18:42:58 -04:00
|
|
|
const emojiString = `<${emoji.animated ? "a" : ""}:${emoji.originalName || emoji.name}:${emoji.id}>`;
|
|
|
|
const url = emoji.url.replace(/\?size=[0-9]+/, "?size=48");
|
2022-10-02 16:12:48 -04:00
|
|
|
messageObj.content = messageObj.content.replace(emojiString, (match, offset, origStr) => {
|
2022-10-05 18:11:32 -04:00
|
|
|
return `${getWordBoundary(origStr, offset - 1)}${url}${getWordBoundary(origStr, offset + match.length)}`;
|
2022-10-02 16:12:48 -04:00
|
|
|
});
|
2022-08-31 14:53:36 -04:00
|
|
|
}
|
2022-08-31 14:55:58 -04:00
|
|
|
});
|
2022-10-01 11:04:57 -04:00
|
|
|
|
2022-08-31 16:08:05 -04:00
|
|
|
this.preEdit = addPreEditListener((_, __, messageObj) => {
|
2022-10-08 14:36:57 -04:00
|
|
|
const { guildId } = this;
|
2022-08-31 14:53:36 -04:00
|
|
|
|
|
|
|
for (const [emojiStr, _, emojiId] of messageObj.content.matchAll(/(?<!\\)<a?:(\w+):(\d+)>/ig)) {
|
|
|
|
const emoji = getCustomEmojiById(emojiId);
|
|
|
|
if (emoji == null || (emoji.guildId === guildId && !emoji.animated)) continue;
|
2022-10-02 16:12:48 -04:00
|
|
|
if (!emoji.require_colons) continue;
|
2022-08-31 14:53:36 -04:00
|
|
|
|
2022-10-05 18:42:58 -04:00
|
|
|
const url = emoji.url.replace(/\?size=[0-9]+/, "?size=48");
|
2022-10-02 16:12:48 -04:00
|
|
|
messageObj.content = messageObj.content.replace(emojiStr, (match, offset, origStr) => {
|
2022-10-05 18:11:32 -04:00
|
|
|
return `${getWordBoundary(origStr, offset - 1)}${url}${getWordBoundary(origStr, offset + match.length)}`;
|
2022-10-02 16:12:48 -04:00
|
|
|
});
|
2022-08-31 14:53:36 -04:00
|
|
|
}
|
2022-08-31 14:55:58 -04:00
|
|
|
});
|
2022-08-31 14:53:36 -04:00
|
|
|
},
|
2022-08-31 16:08:05 -04:00
|
|
|
|
|
|
|
stop() {
|
|
|
|
removePreSendListener(this.preSend);
|
|
|
|
removePreEditListener(this.preEdit);
|
|
|
|
}
|
2022-08-31 14:55:58 -04:00
|
|
|
});
|