From 8f0755c4e7c6ffb464d4a3c4fa193f71b5ea9c4b Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Wed, 2 Jul 2025 21:46:13 +0700 Subject: [PATCH] fix: get turbo modules from turbo module proxy --- lib/assets/src/caches.ts | 2 +- lib/discord/src/native.ts | 25 ++-- lib/discord/src/types/native.ts | 210 ++++++++++++++++---------------- lib/modules/src/caches.ts | 2 +- lib/types/types.d.ts | 3 +- src/index.ts | 7 +- 6 files changed, 131 insertions(+), 118 deletions(-) diff --git a/lib/assets/src/caches.ts b/lib/assets/src/caches.ts index 2493e8f..65f6507 100644 --- a/lib/assets/src/caches.ts +++ b/lib/assets/src/caches.ts @@ -7,7 +7,7 @@ import type { Metro } from '@revenge-mod/modules/types' import type { Asset } from './types' const Version = 1 -const Key = `${Version}.${ClientInfoModule.Build}` +const Key = `${Version}.${ClientInfoModule.getConstants().Build}` // In-memory cache export const cache: Cache = {} diff --git a/lib/discord/src/native.ts b/lib/discord/src/native.ts index 5373070..05f2eff 100644 --- a/lib/discord/src/native.ts +++ b/lib/discord/src/native.ts @@ -11,15 +11,20 @@ import type { DiscordNativeModules } from './types/native' const nmp = nativeModuleProxy -export const CacheModule = - nmp.NativeCacheModule as DiscordNativeModules.CacheModule -export const FileModule = - nmp.NativeFileModule as DiscordNativeModules.FileModule -export const ClientInfoModule = - nmp.NativeClientInfoModule as DiscordNativeModules.ClientInfoModule -export const DeviceModule = - nmp.NativeDeviceModule as DiscordNativeModules.DeviceModule +export const CacheModule = __turboModuleProxy( + 'NativeCacheModule', +) as DiscordNativeModules.CacheModule +export const FileModule = __turboModuleProxy( + 'NativeFileModule', +) as DiscordNativeModules.FileModule +export const ClientInfoModule = __turboModuleProxy( + 'NativeClientInfoModule', +) as DiscordNativeModules.ClientInfoModule +export const DeviceModule = __turboModuleProxy( + 'NativeDeviceModule', +) as DiscordNativeModules.DeviceModule export const BundleUpdaterManager = nmp.BundleUpdaterManager as DiscordNativeModules.BundleUpdaterManager -export const ThemeModule = - nmp.NativeThemeModule as DiscordNativeModules.ThemeModule +export const ThemeModule = __turboModuleProxy( + 'NativeThemeModule', +) as DiscordNativeModules.ThemeModule diff --git a/lib/discord/src/types/native.ts b/lib/discord/src/types/native.ts index 203fbfc..25430ae 100644 --- a/lib/discord/src/types/native.ts +++ b/lib/discord/src/types/native.ts @@ -93,7 +93,7 @@ export namespace DiscordNativeModules { storageDir: 'cache' | 'documents', path: string, ): Promise - getConstants: () => { + getConstants(): { /** * The path the `documents` storage dir (see {@link writeFile}) represents. */ @@ -106,50 +106,52 @@ export namespace DiscordNativeModules { * Client information */ export interface ClientInfoModule { - /** - * Sentry ingestion DSN URL for alpha/beta builds - */ - SentryAlphaBetaDsn: string - /** - * Sentry ingestion DSN URL for staff builds (?) - */ - SentryStaffDsn: string - /** - * Sentry ingestion DSN URL for stable builds - */ - SentryDsn: string - DeviceVendorID: string - Manifest: string - /** - * Version code - * - * Follows the format of `{MINOR}{CHANNEL}{PATCH}` for `{MINOR}.{PATCH} ({CHANNEL})` - * - `248200` for `248.0 (alpha)` - * - `247105` for `247.5 (beta)` - * - `246011` for `246.11 (stable)` - */ - Build: string - /** - * Version string - * - * Eg. `248.0` - */ - Version: string - /** - * Release channel - */ - ReleaseChannel: string - /** - * Matches `Version` - */ - OTABuild: string - /** - * Identifier for the installed client - * - * - **Android**: Package name - * - **iOS**: Bundle ID - */ - Identifier: string + getConstants(): { + /** + * Sentry ingestion DSN URL for alpha/beta builds + */ + SentryAlphaBetaDsn: string + /** + * Sentry ingestion DSN URL for staff builds (?) + */ + SentryStaffDsn: string + /** + * Sentry ingestion DSN URL for stable builds + */ + SentryDsn: string + DeviceVendorID: string + Manifest: string + /** + * Version code + * + * Follows the format of `{MINOR}{CHANNEL}{PATCH}` for `{MINOR}.{PATCH} ({CHANNEL})` + * - `248200` for `248.0 (alpha)` + * - `247105` for `247.5 (beta)` + * - `246011` for `246.11 (stable)` + */ + Build: string + /** + * Version string + * + * Eg. `248.0` + */ + Version: string + /** + * Release channel + */ + ReleaseChannel: string + /** + * Matches `Version` + */ + OTABuild: string + /** + * Identifier for the installed client + * + * - **Android**: Package name + * - **iOS**: Bundle ID + */ + Identifier: string + } } /** @@ -170,64 +172,66 @@ export namespace DiscordNativeModules { * Returns the screen size of the device */ getScreenSize(): { width: number; height: number } - /** - * Maximum CPU frequency - * @example "2.00" - */ - maxCpuFreq: string - /** - * The brand of the device - * - On Android, returns the value of `ro.product.brand` - */ - deviceBrand: string - /** - * Whether the device is using gesture navigation - */ - isGestureNavigationEnabled: boolean - /** - * The manufacturer of the device - * - On Android, returns the value of `ro.product.manufacturer` - */ - deviceManufacturer: string - /** - * RAM size in gigabytes (most likely an approximation) - * @example "3.62" - */ - ramSize: string - /** - * The device's DPI setting - */ - smallestScreenWidth: number - /** - * The version of the system - * - On Android, returns the value of `ro.build.version.sdk` - */ - systemVersion: string - /** - * Whether the system taskbar navigation is enabled - */ - isTaskBarEnabled: boolean - /** - * The name of the device product - * - On Android, returns the value of `ro.product.name` - */ - deviceProduct: string - /** - * The model of the device - * - On Android, returns the value of `ro.product.model` - */ - deviceModel: string - /** - * The name of the device - * - On Android, returns the value of `ro.product.device` - */ - device: string - /** - * The name of the device board - * - On Android, returns the value of `{ro.product.manufacturer}_{ro.soc.model}` - * @example "Google_Tensor G4" // ro.product.manufacturer=Google; ro.soc.model=Tensor G4 - */ - socName: string + getConstants(): { + /** + * Maximum CPU frequency + * @example "2.00" + */ + maxCpuFreq: string + /** + * The brand of the device + * - On Android, returns the value of `ro.product.brand` + */ + deviceBrand: string + /** + * Whether the device is using gesture navigation + */ + isGestureNavigationEnabled: boolean + /** + * The manufacturer of the device + * - On Android, returns the value of `ro.product.manufacturer` + */ + deviceManufacturer: string + /** + * RAM size in gigabytes (most likely an approximation) + * @example "3.62" + */ + ramSize: string + /** + * The device's DPI setting + */ + smallestScreenWidth: number + /** + * The version of the system + * - On Android, returns the value of `ro.build.version.sdk` + */ + systemVersion: string + /** + * Whether the system taskbar navigation is enabled + */ + isTaskBarEnabled: boolean + /** + * The name of the device product + * - On Android, returns the value of `ro.product.name` + */ + deviceProduct: string + /** + * The model of the device + * - On Android, returns the value of `ro.product.model` + */ + deviceModel: string + /** + * The name of the device + * - On Android, returns the value of `ro.product.device` + */ + device: string + /** + * The name of the device board + * - On Android, returns the value of `{ro.product.manufacturer}_{ro.soc.model}` + * @example "Google_Tensor G4" // ro.product.manufacturer=Google; ro.soc.model=Tensor G4 + */ + socName: string + } } /** diff --git a/lib/modules/src/caches.ts b/lib/modules/src/caches.ts index 0051dc7..7be0255 100644 --- a/lib/modules/src/caches.ts +++ b/lib/modules/src/caches.ts @@ -7,7 +7,7 @@ import type { FilterResultFlag } from './finders/_internal' import type { Filter } from './finders/filters' const Version = 1 -const Key = `${Version}.${ClientInfoModule.Build}` +const Key = `${Version}.${ClientInfoModule.getConstants().Build}` // In-memory cache export const cache: Cache = {} diff --git a/lib/types/types.d.ts b/lib/types/types.d.ts index 5f776fc..042c089 100644 --- a/lib/types/types.d.ts +++ b/lib/types/types.d.ts @@ -69,7 +69,6 @@ declare global { /// METRO declare global { - var nativeModuleProxy: Record var __r: Metro.RequireFn var __c: Metro.ClearFn var __d: Metro.DefineFn @@ -78,6 +77,8 @@ declare global { /// REACT NATIVE declare global { + var nativeModuleProxy: Record + function __turboModuleProxy(name: string): unknown function nativeLoggingHook(str: string, level: number): void function alert(message: unknown): void diff --git a/src/index.ts b/src/index.ts index fe3bd8c..11ba166 100644 --- a/src/index.ts +++ b/src/index.ts @@ -58,10 +58,13 @@ function runCatching(fn: () => void) { const { ClientInfoModule, DeviceModule } = require('@revenge-mod/discord/native') as typeof import('@revenge-mod/discord/native') + const Client = ClientInfoModule.getConstants() + const Device = DeviceModule.getConstants() + alert( `Failed to load Revenge (${__BUILD_VERSION__}-${__BUILD_COMMIT__}-${__BUILD_BRANCH__} (${__BUILD_ENV__}))\n` + - `Discord: ${ClientInfoModule.Version} (${ClientInfoModule.Build})\n` + - `Device: ${DeviceModule.deviceManufacturer} ${DeviceModule.deviceModel}\n\n` + + `Discord: ${Client.Version} (${Client.Build})\n` + + `Device: ${Device.deviceManufacturer} ${Device.deviceModel}\n\n` + getErrorStack(e), ) }