diff --git a/src/plugins/consoleShortcuts/index.ts b/src/plugins/consoleShortcuts/index.ts index e8150f8f..feeada9e 100644 --- a/src/plugins/consoleShortcuts/index.ts +++ b/src/plugins/consoleShortcuts/index.ts @@ -74,6 +74,22 @@ function makeShortcuts() { }; } + function findStoreWrapper(findStore: typeof Webpack.findStore) { + const cache = new Map(); + + return function (storeName: string) { + const cacheKey = String(storeName); + if (cache.has(cacheKey)) return cache.get(cacheKey); + + let store: unknown; + try { + store = findStore(storeName); + } catch { } + if (store) cache.set(cacheKey, store); + return store; + }; + } + let fakeRenderWin: WeakRef | undefined; const find = newFindWrapper(f => f); const findByProps = newFindWrapper(filters.byProps); @@ -98,7 +114,7 @@ function makeShortcuts() { findComponentByCode: newFindWrapper(filters.componentByCode), findAllComponentsByCode: (...code: string[]) => findAll(filters.componentByCode(...code)), findExportedComponent: (...props: string[]) => findByProps(...props)[props[0]], - findStore: newFindWrapper(filters.byStoreName), + findStore: findStoreWrapper(Webpack.findStore), PluginsApi: { getter: () => Vencord.Plugins }, plugins: { getter: () => Vencord.Plugins.plugins }, Settings: { getter: () => Vencord.Settings }, diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts index ec9e99be..98e7d4d1 100644 --- a/src/webpack/webpack.ts +++ b/src/webpack/webpack.ts @@ -468,6 +468,29 @@ export function findStore(name: StoreNameFilter) { } } + try { + const getLibdiscore = findByCode("libdiscoreWasm is not initialized"); + const libdiscoreExports = getLibdiscore(); + + for (const libdiscoreExportName in libdiscoreExports) { + if (!libdiscoreExportName.endsWith("Store")) { + continue; + } + + const storeName = libdiscoreExportName; + const store = libdiscoreExports[storeName]; + + if (storeName === name) { + res = store; + } + + if (fluxStores[storeName] == null) { + fluxStores[storeName] = store; + } + } + + } catch { } + if (res == null) { res = find(filters.byStoreName(name), { isIndirect: true }); }