Fix MessagePopoverAPI and any error Fake Nitro client theme bypass might have (#665)
This commit is contained in:
parent
1368c25824
commit
7923a790e6
@ -27,11 +27,11 @@ export default definePlugin({
|
|||||||
find: "Messages.MESSAGE_UTILITIES_A11Y_LABEL",
|
find: "Messages.MESSAGE_UTILITIES_A11Y_LABEL",
|
||||||
replacement: {
|
replacement: {
|
||||||
// foo && !bar ? createElement(blah,...makeElement(addReactionData))
|
// foo && !bar ? createElement(blah,...makeElement(addReactionData))
|
||||||
match: /(\i&&!\i)\?\(0,\i\.jsxs?\)\(.{0,200}renderPopout:.{0,300}?(\i)\(.{3,20}\{key:"add-reaction".+?\}/,
|
match: /\i&&!\i\?\(0,\i\.jsxs?\)\(.{0,200}renderPopout:.{0,300}?(\i)\(.{3,20}\{key:"add-reaction".+?\}/,
|
||||||
replace: (m, bools, makeElement) => {
|
replace: (m, makeElement) => {
|
||||||
const msg = m.match(/message:(.{1,3}),/)?.[1];
|
const msg = m.match(/message:(.{1,3}),/)?.[1];
|
||||||
if (!msg) throw new Error("Could not find message variable");
|
if (!msg) throw new Error("Could not find message variable");
|
||||||
return `...(${bools}?Vencord.Api.MessagePopover._buildPopoverElements(${msg},${makeElement}):[]),${m}`;
|
return `...Vencord.Api.MessagePopover._buildPopoverElements(${msg},${makeElement}),${m}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
|
@ -21,6 +21,7 @@ import { migratePluginSettings, Settings } from "@api/settings";
|
|||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import { ApngDisposeOp, getGifEncoder, importApngJs } from "@utils/dependencies";
|
import { ApngDisposeOp, getGifEncoder, importApngJs } from "@utils/dependencies";
|
||||||
import { getCurrentGuild } from "@utils/discord";
|
import { getCurrentGuild } from "@utils/discord";
|
||||||
|
import { proxyLazy } from "@utils/proxyLazy";
|
||||||
import definePlugin, { OptionType } from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { findByCodeLazy, findByPropsLazy, findLazy, findStoreLazy } from "@webpack";
|
import { findByCodeLazy, findByPropsLazy, findLazy, findStoreLazy } from "@webpack";
|
||||||
import { ChannelStore, FluxDispatcher, PermissionStore, UserStore } from "@webpack/common";
|
import { ChannelStore, FluxDispatcher, PermissionStore, UserStore } from "@webpack/common";
|
||||||
@ -28,7 +29,21 @@ import { ChannelStore, FluxDispatcher, PermissionStore, UserStore } from "@webpa
|
|||||||
const DRAFT_TYPE = 0;
|
const DRAFT_TYPE = 0;
|
||||||
const promptToUpload = findByCodeLazy("UPLOAD_FILE_LIMIT_ERROR");
|
const promptToUpload = findByCodeLazy("UPLOAD_FILE_LIMIT_ERROR");
|
||||||
const UserSettingsProtoStore = findStoreLazy("UserSettingsProtoStore");
|
const UserSettingsProtoStore = findStoreLazy("UserSettingsProtoStore");
|
||||||
const ProtoPreloadedUserSettings = findLazy(m => m.typeName === "discord_protos.discord_users.v1.PreloadedUserSettings");
|
const PreloadedUserSettingsProtoHandler = findLazy(m => m.ProtoClass?.typeName === "discord_protos.discord_users.v1.PreloadedUserSettings");
|
||||||
|
const ReaderFactory = findByPropsLazy("readerFactory");
|
||||||
|
|
||||||
|
function searchProtoClass(localName: string, parentProtoClass: any) {
|
||||||
|
if (!parentProtoClass) return;
|
||||||
|
|
||||||
|
const field = parentProtoClass.fields.find(field => field.localName === localName);
|
||||||
|
if (!field) return;
|
||||||
|
|
||||||
|
const getter: any = Object.values(field).find(value => typeof value === "function");
|
||||||
|
return getter?.();
|
||||||
|
}
|
||||||
|
|
||||||
|
const AppearanceSettingsProto = proxyLazy(() => searchProtoClass("appearance", PreloadedUserSettingsProtoHandler.ProtoClass));
|
||||||
|
const ClientThemeSettingsProto = proxyLazy(() => searchProtoClass("clientThemeSettings", AppearanceSettingsProto));
|
||||||
|
|
||||||
const USE_EXTERNAL_EMOJIS = 1n << 18n;
|
const USE_EXTERNAL_EMOJIS = 1n << 18n;
|
||||||
const USE_EXTERNAL_STICKERS = 1n << 37n;
|
const USE_EXTERNAL_STICKERS = 1n << 37n;
|
||||||
@ -167,8 +182,8 @@ export default definePlugin({
|
|||||||
{
|
{
|
||||||
find: "updateTheme:function",
|
find: "updateTheme:function",
|
||||||
replacement: {
|
replacement: {
|
||||||
match: /(function \i\(\i\){var (\i)=\i\.backgroundGradientPresetId.+?)\i\.\i\.updateAsync.+?theme=(.+?);.+?\),\i\)/,
|
match: /(function \i\(\i\){var (\i)=\i\.backgroundGradientPresetId.+?)(\i\.\i\.updateAsync.+?theme=(.+?);.+?\),\i\))/,
|
||||||
replace: (_, rest, backgroundGradientPresetId, theme) => `${rest}$self.handleGradientThemeSelect(${backgroundGradientPresetId},${theme});`
|
replace: (_, rest, backgroundGradientPresetId, originalCall, theme) => `${rest}$self.handleGradientThemeSelect(${backgroundGradientPresetId},${theme},()=>${originalCall});`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@ -219,48 +234,56 @@ export default definePlugin({
|
|||||||
},
|
},
|
||||||
|
|
||||||
handleProtoChange(proto: any, user: any) {
|
handleProtoChange(proto: any, user: any) {
|
||||||
const premiumType: number = user?.premium_type ?? UserStore.getCurrentUser()?.premiumType ?? 0;
|
if ((!proto.appearance && !AppearanceSettingsProto) || !UserSettingsProtoStore) return;
|
||||||
|
|
||||||
if (premiumType === 0) {
|
const premiumType: number = user?.premium_type ?? UserStore?.getCurrentUser()?.premiumType ?? 0;
|
||||||
const appearanceDummyProto = ProtoPreloadedUserSettings.create({
|
|
||||||
appearance: {}
|
|
||||||
});
|
|
||||||
|
|
||||||
proto.appearance ??= appearanceDummyProto.appearance;
|
if (premiumType !== 2) {
|
||||||
|
proto.appearance ??= AppearanceSettingsProto.create();
|
||||||
|
|
||||||
if (UserSettingsProtoStore.settings.appearance?.theme != null) {
|
if (UserSettingsProtoStore.settings.appearance?.theme != null) {
|
||||||
proto.appearance.theme = UserSettingsProtoStore.settings.appearance.theme;
|
proto.appearance.theme = UserSettingsProtoStore.settings.appearance.theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UserSettingsProtoStore.settings.appearance?.clientThemeSettings?.backgroundGradientPresetId?.value != null) {
|
if (UserSettingsProtoStore.settings.appearance?.clientThemeSettings?.backgroundGradientPresetId?.value != null && ClientThemeSettingsProto) {
|
||||||
const clientThemeSettingsDummyProto = ProtoPreloadedUserSettings.create({
|
const clientThemeSettingsDummyProto = ClientThemeSettingsProto.create({
|
||||||
appearance: {
|
|
||||||
clientThemeSettings: {
|
|
||||||
backgroundGradientPresetId: {
|
backgroundGradientPresetId: {
|
||||||
value: UserSettingsProtoStore.settings.appearance.clientThemeSettings.backgroundGradientPresetId.value
|
value: UserSettingsProtoStore.settings.appearance.clientThemeSettings.backgroundGradientPresetId.value
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
proto.appearance.clientThemeSettings ??= clientThemeSettingsDummyProto.appearance.clientThemeSettings;
|
proto.appearance.clientThemeSettings ??= clientThemeSettingsDummyProto;
|
||||||
proto.appearance.clientThemeSettings.backgroundGradientPresetId = clientThemeSettingsDummyProto.appearance.clientThemeSettings.backgroundGradientPresetId;
|
proto.appearance.clientThemeSettings.backgroundGradientPresetId = clientThemeSettingsDummyProto.backgroundGradientPresetId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
handleGradientThemeSelect(backgroundGradientPresetId: number | undefined, theme: number) {
|
handleGradientThemeSelect(backgroundGradientPresetId: number | undefined, theme: number, original: () => void) {
|
||||||
const proto = ProtoPreloadedUserSettings.create({
|
const premiumType = UserStore?.getCurrentUser()?.premiumType ?? 0;
|
||||||
appearance: {
|
if (premiumType === 2 || backgroundGradientPresetId == null) return original();
|
||||||
theme,
|
|
||||||
clientThemeSettings: {
|
if (!AppearanceSettingsProto || !ClientThemeSettingsProto || !ReaderFactory) return;
|
||||||
backgroundGradientPresetId: backgroundGradientPresetId != null ? {
|
|
||||||
|
const currentAppearanceProto = PreloadedUserSettingsProtoHandler.getCurrentValue().appearance;
|
||||||
|
|
||||||
|
const newAppearanceProto = currentAppearanceProto != null
|
||||||
|
? AppearanceSettingsProto.fromBinary(AppearanceSettingsProto.toBinary(currentAppearanceProto), ReaderFactory)
|
||||||
|
: AppearanceSettingsProto.create();
|
||||||
|
|
||||||
|
newAppearanceProto.theme = theme;
|
||||||
|
|
||||||
|
const clientThemeSettingsDummyProto = ClientThemeSettingsProto.create({
|
||||||
|
backgroundGradientPresetId: {
|
||||||
value: backgroundGradientPresetId
|
value: backgroundGradientPresetId
|
||||||
} : void 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
newAppearanceProto.clientThemeSettings ??= clientThemeSettingsDummyProto;
|
||||||
|
newAppearanceProto.clientThemeSettings.backgroundGradientPresetId = clientThemeSettingsDummyProto.backgroundGradientPresetId;
|
||||||
|
|
||||||
|
const proto = PreloadedUserSettingsProtoHandler.ProtoClass.create();
|
||||||
|
proto.appearance = newAppearanceProto;
|
||||||
|
|
||||||
FluxDispatcher.dispatch({
|
FluxDispatcher.dispatch({
|
||||||
type: "USER_SETTINGS_PROTO_UPDATE",
|
type: "USER_SETTINGS_PROTO_UPDATE",
|
||||||
local: true,
|
local: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user