Revenge/src/ui/assets.ts

27 lines
954 B
TypeScript
Raw Normal View History

2022-10-22 22:26:06 +00:00
import { Asset, Assets } from "@types";
import { after } from "@lib/patcher";
import { findByProps } from "@metro/filters";
const assetsModule = findByProps("registerAsset");
export const all: Assets = {};
export default function patchAssets() {
try {
after("registerAsset", assetsModule, (args: Asset[], id: number) => {
const asset = args[0];
2022-10-22 22:43:51 +00:00
all[asset.name] = { ...asset, id: id };
2022-10-22 22:26:06 +00:00
});
for (let id = 1; ; id++) {
const asset = assetsModule.getAssetByID(id);
if (!asset) break;
if (all[asset.name]) continue;
};
} catch {};
}
export const find = (filter: (a: any) => void): Asset | null | undefined => Object.values(all).find(filter);
export const getAssetByName = (name: string): Asset => all[name];
2022-10-22 23:05:04 +00:00
export const getAssetByID = (id: number): Asset => assetsModule.getAssetByID(id);
2022-10-22 22:43:51 +00:00
export const getAssetIDByName = (name: string) => all[name]?.id;