2023-01-14 16:05:08 +00:00
|
|
|
import { RNConstants } from "@types";
|
2023-01-10 23:30:46 +00:00
|
|
|
import { ReactNative as RN } from "@metro/common";
|
2022-10-22 22:44:42 +01:00
|
|
|
import { after } from "@lib/patcher";
|
2022-10-23 00:51:18 +01:00
|
|
|
import { getAssetIDByName } from "@ui/assets";
|
|
|
|
|
import { showToast } from "@ui/toasts";
|
2022-10-20 07:58:17 +01:00
|
|
|
import logger from "@lib/logger";
|
2022-10-19 23:11:44 +01:00
|
|
|
export let socket: WebSocket;
|
|
|
|
|
|
2022-10-28 18:50:40 +01:00
|
|
|
export function connectToDebugger(url: string) {
|
2022-10-19 23:11:44 +01:00
|
|
|
if (socket !== undefined && socket.readyState !== WebSocket.CLOSED) {
|
|
|
|
|
socket.close();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-23 00:51:18 +01:00
|
|
|
if (url === "") {
|
|
|
|
|
showToast("Invalid debugger URL!", getAssetIDByName("Small"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 23:11:44 +01:00
|
|
|
socket = new WebSocket(`ws://${url}`);
|
|
|
|
|
|
2022-10-23 00:51:18 +01:00
|
|
|
socket.addEventListener("open", () => showToast("Connected to debugger.", getAssetIDByName("Check")));
|
|
|
|
|
|
2022-10-19 23:11:44 +01:00
|
|
|
socket.addEventListener("message", (message: any) => {
|
|
|
|
|
try {
|
2023-01-08 22:33:41 +00:00
|
|
|
(0, eval)(message.data);
|
2022-10-19 23:11:44 +01:00
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e);
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-10-23 00:51:18 +01:00
|
|
|
|
|
|
|
|
socket.addEventListener("error", (err: any) => {
|
|
|
|
|
console.log(`Debugger error: ${err.message}`);
|
|
|
|
|
showToast("An error occurred with the debugger connection!", getAssetIDByName("Small"));
|
|
|
|
|
});
|
2022-10-19 23:11:44 +01:00
|
|
|
}
|
|
|
|
|
|
2023-02-04 02:30:46 +00:00
|
|
|
export function patchLogHook() {
|
|
|
|
|
const unpatch = after("nativeLoggingHook", globalThis, (args) => {
|
|
|
|
|
if (socket?.readyState === WebSocket.OPEN) socket.send(JSON.stringify({ message: args[0], level: args[1] }));
|
2022-10-19 23:11:44 +01:00
|
|
|
logger.log(args[0]);
|
|
|
|
|
});
|
2023-02-04 02:30:46 +00:00
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
socket && socket.close();
|
|
|
|
|
unpatch();
|
|
|
|
|
}
|
2022-10-19 23:11:44 +01:00
|
|
|
}
|
2023-01-10 23:30:46 +00:00
|
|
|
|
|
|
|
|
export const versionHash = "__vendettaVersion";
|
|
|
|
|
|
2023-01-14 02:39:10 +00:00
|
|
|
export function getDebugInfo() {
|
2023-01-30 22:56:48 +00:00
|
|
|
// Discord
|
2023-01-10 23:30:46 +00:00
|
|
|
const InfoDictionaryManager = RN.NativeModules.InfoDictionaryManager;
|
2023-01-30 22:56:48 +00:00
|
|
|
const DCDDeviceManager = RN.NativeModules.DCDDeviceManager;
|
|
|
|
|
|
|
|
|
|
// Hermes
|
2023-01-10 23:30:46 +00:00
|
|
|
const hermesProps = window.HermesInternal.getRuntimeProperties();
|
2023-01-30 22:56:48 +00:00
|
|
|
const hermesVer = hermesProps["OSS Release Version"];
|
|
|
|
|
const padding = "for RN ";
|
|
|
|
|
|
|
|
|
|
// RN
|
2023-01-14 16:05:08 +00:00
|
|
|
const PlatformConstants = RN.Platform.constants as RNConstants;
|
2023-01-10 23:28:54 -05:00
|
|
|
const rnVer = PlatformConstants.reactNativeVersion;
|
2023-01-10 23:30:46 +00:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
vendetta: {
|
|
|
|
|
version: versionHash,
|
2023-02-13 20:14:09 +00:00
|
|
|
loader: window.__vendetta_loader?.name ?? "Unknown",
|
2023-01-10 23:30:46 +00:00
|
|
|
},
|
|
|
|
|
discord: {
|
|
|
|
|
version: InfoDictionaryManager.Version,
|
|
|
|
|
build: InfoDictionaryManager.Build,
|
|
|
|
|
},
|
|
|
|
|
react: {
|
|
|
|
|
version: React.version,
|
2023-01-30 22:56:48 +00:00
|
|
|
nativeVersion: hermesVer.startsWith(padding) ? hermesVer.substring(padding.length) : `${rnVer.major}.${rnVer.minor}.${rnVer.patch}`,
|
2023-01-10 23:30:46 +00:00
|
|
|
},
|
|
|
|
|
hermes: {
|
2023-01-30 22:56:48 +00:00
|
|
|
version: hermesVer,
|
2023-01-10 23:30:46 +00:00
|
|
|
buildType: hermesProps["Build"],
|
|
|
|
|
bytecodeVersion: hermesProps["Bytecode Version"],
|
2023-01-10 23:28:54 -05:00
|
|
|
},
|
|
|
|
|
...RN.Platform.select(
|
|
|
|
|
{
|
|
|
|
|
android: {
|
|
|
|
|
os: {
|
|
|
|
|
name: "Android",
|
|
|
|
|
version: PlatformConstants.Release,
|
|
|
|
|
sdk: PlatformConstants.Version
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
ios: {
|
|
|
|
|
os: {
|
|
|
|
|
name: PlatformConstants.systemName,
|
|
|
|
|
version: PlatformConstants.osVersion
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)!,
|
|
|
|
|
...RN.Platform.select(
|
|
|
|
|
{
|
|
|
|
|
android: {
|
|
|
|
|
device: {
|
|
|
|
|
manufacturer: PlatformConstants.Manufacturer,
|
|
|
|
|
brand: PlatformConstants.Brand,
|
2023-01-11 01:12:26 -05:00
|
|
|
model: PlatformConstants.Model,
|
|
|
|
|
codename: DCDDeviceManager.device
|
2023-01-10 23:28:54 -05:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
ios: {
|
|
|
|
|
device: {
|
|
|
|
|
manufacturer: DCDDeviceManager.deviceManufacturer,
|
|
|
|
|
brand: DCDDeviceManager.deviceBrand,
|
2023-01-11 01:12:26 -05:00
|
|
|
model: DCDDeviceManager.deviceModel,
|
|
|
|
|
codename: DCDDeviceManager.device
|
2023-01-10 23:28:54 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
)!
|
2023-01-10 23:30:46 +00:00
|
|
|
}
|
|
|
|
|
}
|