From cbe7de9fd2b59c7f05036cb28957439802139331 Mon Sep 17 00:00:00 2001 From: Federico <38290480+FedeIlLeone@users.noreply.github.com> Date: Thu, 17 Oct 2024 22:45:03 +0200 Subject: [PATCH 1/3] fix: show the right badges --- src/renderer/coremods/badges/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/coremods/badges/index.tsx b/src/renderer/coremods/badges/index.tsx index 5a7d88677..1d7711003 100644 --- a/src/renderer/coremods/badges/index.tsx +++ b/src/renderer/coremods/badges/index.tsx @@ -151,7 +151,7 @@ export async function start(): Promise { } badgeElements.forEach((badgeElement) => { - if (badgeElement.id in badgeCache) { + if (badgeCache[badgeElement.id as keyof APIRepluggedBadges]) { const { component, ...props } = badgeElement; const badgeColor = badgeCache.custom.color; From 5015f750478dc7ffc7858e631e03b6190ca0ec93 Mon Sep 17 00:00:00 2001 From: Federico <38290480+FedeIlLeone@users.noreply.github.com> Date: Thu, 17 Oct 2024 22:59:28 +0200 Subject: [PATCH 2/3] feat: separate the mod's notices from the native ones --- src/renderer/coremods/notices/index.tsx | 8 ++------ src/renderer/coremods/notices/plaintextPatches.ts | 5 ++--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/renderer/coremods/notices/index.tsx b/src/renderer/coremods/notices/index.tsx index 870cb9442..70e7c9729 100644 --- a/src/renderer/coremods/notices/index.tsx +++ b/src/renderer/coremods/notices/index.tsx @@ -37,11 +37,7 @@ function Announcement({ ); } -export function AnnouncementContainer({ - originalRes, -}: { - originalRes: React.ReactElement; -}): React.ReactElement | null { +export function AnnouncementContainer(): React.ReactElement | undefined { const [announcement, setAnnouncement] = React.useState( undefined, ); @@ -57,5 +53,5 @@ export function AnnouncementContainer({ }; }, []); - return announcement ? : originalRes; + return announcement && ; } diff --git a/src/renderer/coremods/notices/plaintextPatches.ts b/src/renderer/coremods/notices/plaintextPatches.ts index e24a8da80..18089da77 100644 --- a/src/renderer/coremods/notices/plaintextPatches.ts +++ b/src/renderer/coremods/notices/plaintextPatches.ts @@ -7,9 +7,8 @@ export default [ find: /hasNotice:\w+,sidebarTheme:\w+/, replacements: [ { - match: /(\w+\.base,children:\[.{0,50})(\w+\.\w+\?null.{10,30}}\)),/, - replace: (_, prefix, noticeWrapper) => - `${prefix}${coremodStr}?.AnnouncementContainer?${coremodStr}.AnnouncementContainer({originalRes:${noticeWrapper}}):${noticeWrapper},`, + match: /\w+\.base,children:\[/, + replace: `$&${coremodStr}?.AnnouncementContainer?.(),`, }, ], }, From 91306b44a09b41108ed612aa97b92c7ba59b396c Mon Sep 17 00:00:00 2001 From: Federico <38290480+FedeIlLeone@users.noreply.github.com> Date: Thu, 17 Oct 2024 23:00:48 +0200 Subject: [PATCH 3/3] fix: constants's scope undefined, correct cssvariables module code cleanup --- src/renderer/coremods/rpc/index.ts | 3 --- src/renderer/modules/common/constants.ts | 21 ++++------------- src/renderer/modules/common/fluxHooks.ts | 30 +++++++++++++----------- 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/src/renderer/coremods/rpc/index.ts b/src/renderer/coremods/rpc/index.ts index 784353ee0..45cb5e8a8 100644 --- a/src/renderer/coremods/rpc/index.ts +++ b/src/renderer/coremods/rpc/index.ts @@ -39,9 +39,6 @@ type RPCMod = { commands: Commands }; let commands: Commands = {}; async function injectRpc(): Promise { - //const rpcValidatorMod = await waitForProps<{ - // fetchApplicationsRPC: (socket: Socket, client_id: string, origin: string) => Promise; - //}>("fetchApplicationsRPC"); const rpcValidatorMod = await waitForModule< Record Promise> >(filters.bySource("Invalid Client ID")); diff --git a/src/renderer/modules/common/constants.ts b/src/renderer/modules/common/constants.ts index d6503769e..1ca61276c 100644 --- a/src/renderer/modules/common/constants.ts +++ b/src/renderer/modules/common/constants.ts @@ -1,13 +1,11 @@ import { virtualMerge } from "src/renderer/util"; -import { filters, getExportsForProps, waitForModule } from "../webpack"; +import { filters, getExportsForProps, waitForModule, waitForProps } from "../webpack"; type StringConcat = (...rest: string[]) => string; -//const ConstantsCommon = await waitForProps>("Links", "RPCCommands"); const ConstantsCommon = await waitForModule>( filters.bySource("dis.gd/request"), ); -//const Constants = await waitForProps>("Endpoints", "Routes"); const Constants = await waitForModule>( filters.bySource("users/@me/relationships"), ); @@ -18,10 +16,7 @@ export const Permissions = getExportsForProps>(ConstantsC "MANAGE_GUILD", ]); // OAuth2Scopes -export const Scopes = getExportsForProps>(ConstantsCommon, [ - "BOT", - "GUILDS", -])!; +export const Scopes = await waitForProps>("BOT", "GUILDS"); // RPCCloseCodes export const RPCErrors = getExportsForProps>(ConstantsCommon, [ "RATELIMITED", @@ -72,16 +67,10 @@ export const UserFlags = getExportsForProps>(Con ])!; // ThemeColor -//Ambiguous: should this be the just-dashed-names or --var(css-var-strings)? -// Go with the latter for now. -/* export const CSSVariables = await waitForProps>( "TEXT_NORMAL", "BACKGROUND_PRIMARY", ); -*/ -// We *should* be able to do props, but there's so much extra junk with the current search implementation. -export const CSSVariables = await waitForModule(filters.bySource('="var(--background-floating)"')); interface ColorResponse { hex: () => string; @@ -127,11 +116,9 @@ interface ColorMod { shadows: Record; // eslint-disable-next-line @typescript-eslint/naming-convention unsafe_rawColors: Record; + layout: Record; } -// This could really be a search by props, for unsafe_rawColors. -export const ColorGenerator = await waitForModule( - filters.bySource(/\w+\.unsafe_rawColors\[\w+\]\.resolve\(\w+\)/), -); +export const ColorGenerator = await waitForProps("unsafe_rawColors", "layout"); export const Themes = ColorGenerator.themes; diff --git a/src/renderer/modules/common/fluxHooks.ts b/src/renderer/modules/common/fluxHooks.ts index e5546619d..523cb90e3 100644 --- a/src/renderer/modules/common/fluxHooks.ts +++ b/src/renderer/modules/common/fluxHooks.ts @@ -24,30 +24,32 @@ export interface FluxHooks { ) => T; } -type EqualityComparer = (a: unknown[], b: unknown[]) => boolean; +type ShallowEqual = ( + a: T, + b: T, + excludeKeys?: string[], + callback?: (message: string) => void, +) => boolean; +type AreArraysShallowEqual = (a: T, b: T) => boolean; -const FluxEquatorMod = await waitForModule(filters.bySource("shallowEqual: unequal key")); -const isEqualObject = getFunctionBySource( - FluxEquatorMod, - "shallowEqual: unequal key", -)!; -const isEqualArray = getFunctionBySource(FluxEquatorMod, ".some")!; +const shallowEqualMod = await waitForModule(filters.bySource("shallowEqual: unequal key")); +const shallowEqual = getFunctionBySource(shallowEqualMod, "shallowEqual")!; +const areArraysShallowEqual = getFunctionBySource(shallowEqualMod, ".some")!; -//const fluxHooksMod = await waitForProps("useStateFromStores"); -const fluxHooksMod = await waitForModule>>( +const useStateFromStoresMod = await waitForModule>>( filters.bySource("useStateFromStores"), ); -const useStateFromStores: FluxHooks["useStateFromStores"] = getFunctionBySource( - fluxHooksMod, +const useStateFromStores = getFunctionBySource( + useStateFromStoresMod, "useStateFromStores", )!; export default { useStateFromStores, - statesWillNeverBeEqual: getFunctionBySource(fluxHooksMod, "return!1"), + statesWillNeverBeEqual: getFunctionBySource(useStateFromStoresMod, "return!1"), useStateFromStoresArray: (stores, callback, deps) => - useStateFromStores(stores, callback, deps, isEqualArray), + useStateFromStores(stores, callback, deps, areArraysShallowEqual), useStateFromStoresObject: (stores, callback, deps) => - useStateFromStores(stores, callback, deps, isEqualObject), + useStateFromStores(stores, callback, deps, shallowEqual), } as FluxHooks;