diff --git a/src/def.d.ts b/src/def.d.ts index 36dcef4..85f8727 100644 --- a/src/def.d.ts +++ b/src/def.d.ts @@ -280,7 +280,7 @@ interface VendettaObject { findByPropsAll: PropsFinderAll; findByDisplayName: (name: string, defaultExp?: boolean) => any; findByDisplayNameAll: (name: string, defaultExp?: boolean) => any[]; - findByStoreName: (storeName: string) => any; + findByStoreName: (name: string) => any; common: { constants: PropIntellisense<"API_HOST">; channels: PropIntellisense<"getVoiceChannelId">; diff --git a/src/lib/metro/filters.ts b/src/lib/metro/filters.ts index 6ef5dd7..32fcd11 100644 --- a/src/lib/metro/filters.ts +++ b/src/lib/metro/filters.ts @@ -17,7 +17,7 @@ function blacklist(id: number) { // Blacklist any "bad-actor" modules, e.g. the dreaded null proxy, the window itself, or undefined modules for (const key in window.modules) { const id = Number(key); - const module = window.modules[id].publicModule.exports; + const module = window.modules[id]?.publicModule?.exports; if (!module || module === window || module["proxygone"] === null) { blacklist(id); @@ -34,7 +34,7 @@ const filterModules = (modules: MetroModules, single = false) => (filter: (m: an for (const key in modules) { const id = Number(key); - const module = modules[id].publicModule.exports; + const module = modules[id]?.publicModule?.exports; if (!modules[id].isInitialized) try { __r(id); @@ -58,7 +58,7 @@ const filterModules = (modules: MetroModules, single = false) => (filter: (m: an else found.push(module); } } catch (e: Error | any) { - console.error(`Failed to getModule... ${e.stack || e.toString()}`); + console.error(`Failed to filter modules... ${e.stack || e.toString()}`); } } @@ -70,10 +70,12 @@ export const find = filterModules(modules, true); export const findAll = filterModules(modules); const propsFilter = (props: (string | symbol)[]) => (m: any) => props.every((p) => m[p] !== undefined); -const dNameFilter = (name: string, defaultExp: boolean) => (defaultExp ? (m: any) => m.name === name : (m: any) => m?.default?.name === name); +// TODO: This uses .name, not .displayName. We should fix this SOON. Changing it directly WILL break plugins, though. +const dNameFilter = (name: string, defaultExp: boolean) => (defaultExp ? (m: any) => m?.name === name : (m: any) => m?.default?.name === name); +const storeFilter = (name: string) => (m: any) => m.getName && m.getName.length === 0 && m.getName() === name; export const findByProps: PropsFinder = (...props) => find(propsFilter(props)); export const findByPropsAll: PropsFinderAll = (...props) => findAll(propsFilter(props)); export const findByDisplayName = (name: string, defaultExp = true) => find(dNameFilter(name, defaultExp)); export const findByDisplayNameAll = (name: string, defaultExp = true) => findAll(dNameFilter(name, defaultExp)); -export const findByStoreName = (storeName: string) => find((m: any) => m.getName?.() === storeName); \ No newline at end of file +export const findByStoreName = (name: string) => find(storeFilter(name)); \ No newline at end of file diff --git a/src/lib/metro/hoist.ts b/src/lib/metro/hoist.ts index 71b3019..09f4bb4 100644 --- a/src/lib/metro/hoist.ts +++ b/src/lib/metro/hoist.ts @@ -2,7 +2,7 @@ // This used to be in filters.ts, but things became convoluted // Early find logic -const basicFind = (prop: string) => Object.values(window.modules).find(m => m.publicModule.exports?.[prop]).publicModule.exports; +const basicFind = (prop: string) => Object.values(window.modules).find(m => m?.publicModule.exports?.[prop])?.publicModule?.exports; // Hoist React on window window.React = basicFind("createElement") as typeof import("react");; @@ -11,7 +11,7 @@ window.React = basicFind("createElement") as typeof import("react");; export const ReactNative = basicFind("Text") as typeof import("react-native"); // Export Discord's constants -export const constants = basicFind("ThemeColorMap"); +export const constants = basicFind("AbortCodes"); // Export moment export const moment = basicFind("isMoment");