fix(metro): uncached not founds
This commit is contained in:
parent
945955dce8
commit
c89dc175e3
8 changed files with 29 additions and 35 deletions
|
|
@ -14,7 +14,7 @@ export const PyoncordIcon = _PyoncordIcon as string;
|
|||
|
||||
export default function initSettings() {
|
||||
registerSection({
|
||||
name: "Bunny" + (__DEV__ ? " (DEV)" : ""),
|
||||
name: "Bunny",
|
||||
items: [
|
||||
{
|
||||
key: "BUNNY",
|
||||
|
|
|
|||
|
|
@ -29,18 +29,10 @@ export const initVendettaObject = (): any => {
|
|||
metro: {
|
||||
modules: window.modules,
|
||||
find: (filter: (m: any) => boolean) => {
|
||||
const { stack } = new Error();
|
||||
return metro.find(metro.createSimpleFilter(
|
||||
filter,
|
||||
SparkMD5.hash(stack!)
|
||||
));
|
||||
return metro.find(metro.createSimpleFilter(filter, SparkMD5.hash(new Error().stack!)));
|
||||
},
|
||||
findAll: (filter: (m: any) => boolean) => {
|
||||
const { stack } = new Error();
|
||||
return metro.findAll(metro.createSimpleFilter(
|
||||
filter,
|
||||
SparkMD5.hash(stack!)
|
||||
));
|
||||
return metro.findAll(metro.createSimpleFilter(filter, SparkMD5.hash(new Error().stack!)));
|
||||
},
|
||||
findByProps: (...props: any) => {
|
||||
// Decor fix hack
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { View } from "react-native";
|
|||
|
||||
const bySingularProp = createFilterDefinition<[string]>(
|
||||
([prop], m) => m[prop] && Object.keys(m).length === 1,
|
||||
prop => `pyoncord.makldlksdjks(${prop})`
|
||||
prop => `bunny.ui.bySingularProp(${prop})`
|
||||
);
|
||||
|
||||
const findSingular = (prop: string) => find(bySingularProp(prop))?.[prop];
|
||||
|
|
|
|||
|
|
@ -68,7 +68,12 @@ const saveCache = throttle(() => {
|
|||
|
||||
export function registerModuleFindCacheId(uniqueId: string, moduleId: number, all: boolean) {
|
||||
(metroCache.findIndex[uniqueId] ??= { _: undefined })[moduleId] = 1;
|
||||
if (all) metroCache.findIndex[uniqueId]!._ ||= 1;
|
||||
if (all) metroCache.findIndex[uniqueId]!._ = 1;
|
||||
saveCache();
|
||||
}
|
||||
|
||||
export function registerModuleFindFinished(uniqueId: string) {
|
||||
metroCache.findIndex[uniqueId] ??= { _: undefined };
|
||||
saveCache();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ export const commands = findByProps("getBuiltInCommands");
|
|||
export const navigation = findByProps("pushLazy");
|
||||
export const toasts = find(createSimpleFilter(
|
||||
m => m.open && m.close && !m.startDrag && !m.init && !m.openReplay && !m.setAlwaysOnTop && !m.setAccountFlag,
|
||||
"pyoncord.metro.common.toasts"
|
||||
"bunny.metro.common.toasts"
|
||||
));
|
||||
export const messageUtil = findByProps("sendBotMessage");
|
||||
export const navigationStack = findByProps("createStackNavigator");
|
||||
|
|
|
|||
|
|
@ -61,30 +61,30 @@ export function createSimpleFilter(
|
|||
|
||||
export const byProps = createFilterDefinition<string[]>(
|
||||
(props, m) => props.length === 0 ? m[props[0]] : props.every(p => m[p]),
|
||||
props => `pyoncord.metro.byProps(${props.join(",")})`
|
||||
props => `bunny.metro.byProps(${props.join(",")})`
|
||||
);
|
||||
|
||||
export const byName = createFilterDefinition<[string]>(
|
||||
([name], m) => m.name === name,
|
||||
name => `pyoncord.metro.byName(${name})`
|
||||
name => `bunny.metro.byName(${name})`
|
||||
);
|
||||
|
||||
export const byDisplayName = createFilterDefinition<[string]>(
|
||||
([displayName], m) => m.displayName === displayName,
|
||||
name => `pyoncord.metro.byDisplayName(${name})`
|
||||
name => `bunny.metro.byDisplayName(${name})`
|
||||
);
|
||||
|
||||
export const byTypeName = createFilterDefinition<[string]>(
|
||||
([typeName], m) => m.type?.name === typeName,
|
||||
name => `pyoncord.metro.byTypeName(${name})`
|
||||
name => `bunny.metro.byTypeName(${name})`
|
||||
);
|
||||
|
||||
export const byStoreName = createFilterDefinition<[string]>(
|
||||
([name], m) => m.getName?.length === 0 && m.getName() === name,
|
||||
name => `pyoncord.metro.byStoreName(${name})`
|
||||
name => `bunny.metro.byStoreName(${name})`
|
||||
);
|
||||
|
||||
export const byMutableProp = createFilterDefinition<[string]>(
|
||||
([prop], m) => m?.[prop] && !Object.getOwnPropertyDescriptor(m, prop)?.get,
|
||||
prop => `pyoncord.metro.byMutableProp(${prop})`
|
||||
prop => `bunny.metro.byMutableProp(${prop})`
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { getFuncUniqCall, registerModuleFindCacheId } from "./caches";
|
||||
import { registerModuleFindCacheId, registerModuleFindFinished } from "./caches";
|
||||
import { FilterFn } from "./filters";
|
||||
import { getModules } from "./modules";
|
||||
|
||||
|
|
@ -14,15 +14,15 @@ function testExports<A extends unknown[]>(moduleExports: any, filter: FilterFn<A
|
|||
* @param filter find calls filter once for each enumerable module's exports until it finds one where filter returns a thruthy value.
|
||||
*/
|
||||
export function find<A extends unknown[]>(filter: FilterFn<A>) {
|
||||
const uniq = filter.serialized || getFuncUniqCall();
|
||||
|
||||
for (const [id, moduleExports] of getModules(uniq, false)) {
|
||||
for (const [id, moduleExports] of getModules(filter.serialized, false)) {
|
||||
const testedExports = testExports(moduleExports, filter);
|
||||
if (testedExports !== undefined) {
|
||||
registerModuleFindCacheId(uniq, id, false);
|
||||
registerModuleFindCacheId(filter.serialized, id, false);
|
||||
return testedExports;
|
||||
}
|
||||
}
|
||||
|
||||
registerModuleFindFinished(filter.serialized);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -31,14 +31,15 @@ export function find<A extends unknown[]>(filter: FilterFn<A>) {
|
|||
*/
|
||||
export function findAll<A extends unknown[]>(filter: FilterFn<A>) {
|
||||
const foundExports: any[] = [];
|
||||
const uniq = filter.serialized || getFuncUniqCall();
|
||||
|
||||
for (const [id, moduleExports] of getModules(uniq, true)) {
|
||||
for (const [id, moduleExports] of getModules(filter.serialized, true)) {
|
||||
const testedExports = testExports(moduleExports, filter);
|
||||
if (testedExports !== undefined) {
|
||||
foundExports.push(testedExports);
|
||||
registerModuleFindCacheId(uniq, id, true);
|
||||
registerModuleFindCacheId(filter.serialized, id, true);
|
||||
}
|
||||
}
|
||||
|
||||
registerModuleFindFinished(filter.serialized);
|
||||
return foundExports;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -151,15 +151,11 @@ export function requireModule(id: Metro.ModuleID) {
|
|||
return moduleExports;
|
||||
}
|
||||
|
||||
export function* getModules(uniqueId: string | null, all = false) {
|
||||
export function* getModules(uniqueId: string, all = false) {
|
||||
yield [-1, require("@metro/polyfills/redesign")];
|
||||
|
||||
let cache = null;
|
||||
|
||||
if (uniqueId) {
|
||||
cache = getMetroCache().findIndex[uniqueId];
|
||||
if (all && !cache?._) cache = undefined;
|
||||
}
|
||||
let cache = getMetroCache().findIndex[uniqueId];
|
||||
if (all && !cache?._) cache = undefined;
|
||||
|
||||
for (const id in cache ?? modules) {
|
||||
const exports = requireModule(id);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue