diff --git a/src/def.d.ts b/src/def.d.ts index 1b0dbc9..d565e3a 100644 --- a/src/def.d.ts +++ b/src/def.d.ts @@ -28,6 +28,15 @@ interface FindInTreeOptions { maxDepth?: number; } +interface Asset { + name: string; + id: number; +} + +interface Assets { + [id: string]: Asset; +} + interface VendettaObject { patcher: { after: typeof _spitroast.after; @@ -49,6 +58,15 @@ interface VendettaObject { AsyncStorage: typeof _AsyncStorage; }; }; + ui: { + assets: { + all: Assets; + find: (filter: (a: any) => void) => Asset | null | undefined; + getAssetByName: (name: string) => Asset; + getAssetByID: (name: string) => Asset; + getAssetIDByName: (name: string) => number; + } + }; logger: Logger; } diff --git a/src/index.ts b/src/index.ts index 4237e39..3e2cb61 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,8 @@ import patcher from "@lib/patcher"; import logger from "@lib/logger"; import * as metro from "@metro/filters"; import * as common from "@metro/common"; +import { all, find, getAssetByID, getAssetByName, getAssetIDByName } from "@ui/assets"; +import patchAssets from "@ui/assets"; import initSettings from "@ui/settings"; import { patchLogHook } from "@lib/debug"; @@ -10,12 +12,22 @@ let erroredOnLoad = false; try { initSettings(); + patchAssets(); patchLogHook(); window.vendetta = { patcher: patcher, metro: { ...metro, common: common }, logger: logger, + ui: { + assets: { + all: all, + find: find, + getAssetByID: getAssetByID, + getAssetByName: getAssetByName, + getAssetIDByName: getAssetIDByName, + }, + }, }; } catch (e: Error | any) { erroredOnLoad = true; diff --git a/src/ui/assets.ts b/src/ui/assets.ts new file mode 100644 index 0000000..9b83c32 --- /dev/null +++ b/src/ui/assets.ts @@ -0,0 +1,27 @@ +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]; + all[asset.name] = { ...asset, id }; + }); + + 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]; +export const getAssetByID = (name: string): Asset => assetsModule.getAssetByID(name); +export const getAssetIDByName = (name: string) => all[name].id; \ No newline at end of file