From e29bbf73aa789f5560e37eaee0a146facd69e354 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Tue, 21 Mar 2023 06:03:28 -0300 Subject: [PATCH] Fix Nitro Themes with FakeNitro (#639) --- src/plugins/fakeNitro.ts | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/plugins/fakeNitro.ts b/src/plugins/fakeNitro.ts index bba6aca2..7e583d70 100644 --- a/src/plugins/fakeNitro.ts +++ b/src/plugins/fakeNitro.ts @@ -22,11 +22,12 @@ import { Devs } from "@utils/constants"; import { ApngDisposeOp, getGifEncoder, importApngJs } from "@utils/dependencies"; import { getCurrentGuild } from "@utils/discord"; import definePlugin, { OptionType } from "@utils/types"; -import { findByCodeLazy, findByPropsLazy } from "@webpack"; +import { findByCodeLazy, findByPropsLazy, findStoreLazy } from "@webpack"; import { ChannelStore, PermissionStore, UserStore } from "@webpack/common"; const DRAFT_TYPE = 0; const promptToUpload = findByCodeLazy("UPLOAD_FILE_LIMIT_ERROR"); +const UserSettingsProtoStore = findStoreLazy("UserSettingsProtoStore"); const USE_EXTERNAL_EMOJIS = 1n << 18n; const USE_EXTERNAL_STICKERS = 1n << 37n; @@ -148,6 +149,19 @@ export default definePlugin({ match: /canUseClientThemes:function\(\i\){/, replace: "$&return true;" } + }, + { + find: '.displayName="UserSettingsProtoStore"', + replacement: [ + { + match: /CONNECTION_OPEN:function\((\i)\){/, + replace: (m, props) => `${m}$self.handleProtoChange(${props}.userSettingsProto,${props}.user);` + }, + { + match: /=(\i)\.local;/, + replace: (m, props) => `${m}${props}.local||$self.handleProtoChange(${props}.settings.proto);` + } + ] } ], @@ -196,6 +210,21 @@ export default definePlugin({ return (UserStore.getCurrentUser().premiumType ?? 0) > 1; }, + handleProtoChange(proto: any, user: any) { + const premiumType = user?.premium_type ?? UserStore.getCurrentUser().premiumType ?? 0; + + if (premiumType === 0) { + const themeId = UserSettingsProtoStore.settings.appearance?.clientThemeSettings?.backgroundGradientPresetId?.value; + + if (themeId != null) { + proto.appearance ??= {}; + proto.appearance.clientThemeSettings ??= {}; + proto.appearance.clientThemeSettings.backgroundGradientPresetId ??= {}; + proto.appearance.clientThemeSettings.backgroundGradientPresetId.value = themeId; + } + } + }, + hasPermissionToUseExternalEmojis(channelId: string) { const channel = ChannelStore.getChannel(channelId);