From e737b1ff5c1b527ce9a25d8c101175ae9ef805d3 Mon Sep 17 00:00:00 2001 From: SammCheese Date: Tue, 20 Dec 2022 14:12:15 +0100 Subject: [PATCH] Better Modal & Component Loading. Higher Stability --- manifest.json | 2 +- src/components/DecryptionModal.tsx | 53 ++++++++++++++-------- src/components/EncryptionModal.tsx | 67 ++++++++++++++-------------- src/components/Modals.tsx | 71 +++++++++++++----------------- src/index.ts | 19 +++++--- src/plaintextPatches.ts | 2 +- 6 files changed, 114 insertions(+), 100 deletions(-) diff --git a/manifest.json b/manifest.json index 2da71f6..de4ede9 100644 --- a/manifest.json +++ b/manifest.json @@ -7,7 +7,7 @@ "discordID": "372148345894076416", "github": "SammCheese" }, - "version": "1.0.3", + "version": "1.0.4", "updater": { "type": "github", "id": "SammCheese/invisible-chat" diff --git a/src/components/DecryptionModal.tsx b/src/components/DecryptionModal.tsx index e652e33..5e2aa4c 100644 --- a/src/components/DecryptionModal.tsx +++ b/src/components/DecryptionModal.tsx @@ -3,8 +3,8 @@ import { ModalContent, ModalFooter, ModalHeader, + ModalProps, ModalRoot, - ModalSize, closeModal, openModal, } from "./Modals"; @@ -12,41 +12,52 @@ import { import { buildEmbed, decrypt } from "../index"; const { React } = common; -let TextInput: any; +const rawTextInput: any = webpack.waitForModule( + webpack.filters.byProps("defaultProps", "Sizes", "contextType"), +); + +const rawButton = webpack.waitForModule(webpack.filters.byProps("Hovers", "Looks", "Sizes")); + let Button: any; -setTimeout(() => { - TextInput = webpack.getByProps(["defaultProps", "Sizes", "contextType"]); - Button = webpack.getByProps(["Hovers", "Looks", "Sizes"]); -}, 3500); +let TextInput: any; + +export async function initDecModal() { + TextInput = webpack.getExportsForProps(await rawTextInput, ["contextType"]); + Button = webpack.getExportsForProps(await rawButton, ["Link"]); +} -export function buildDecModal(msg: any) { - let secret: string = msg?.content; - let password: string = "password"; - if (!TextInput || !Button) return; - if (!ModalRoot || !ModalContent || !ModalHeader || !ModalFooter) return; - const s = openModal!((props = msg) => ( - +let modalKey: any; + +function DecModal(props: ModalProps) { + // @ts-ignore + let secret: string = props?.message?.content; + let [password, setPassword] = React.useState("password"); + + return ( +
Decrypt Message
Secret
- +
Password
{ - password = e; + setPassword(e); }}> +
@@ -54,11 +65,15 @@ export function buildDecModal(msg: any) { style={{ left: 15, position: "absolute" }} onClick={() => { // @ts-ignore - closeModal(s); + closeModal(modalKey); }}> Cancel - )); + ); +} + +export function buildDecModal(msg: any): any { + modalKey = openModal((props) => ); } diff --git a/src/components/EncryptionModal.tsx b/src/components/EncryptionModal.tsx index b0763c2..b9a287d 100644 --- a/src/components/EncryptionModal.tsx +++ b/src/components/EncryptionModal.tsx @@ -1,8 +1,9 @@ -import { webpack, common } from "replugged"; +import { common, webpack } from "replugged"; import { ModalContent, ModalFooter, ModalHeader, + ModalProps, ModalRoot, ModalSize, closeModal, @@ -13,30 +14,30 @@ import { encrypt } from "../index"; const { React } = common; -let TextInput: any; +const rawTextInput: any = webpack.waitForModule( + webpack.filters.byProps("defaultProps", "Sizes", "contextType"), +); + +const rawButton = webpack.waitForModule(webpack.filters.byProps("Hovers", "Looks", "Sizes")); + let Button: any; -setTimeout(() => { - TextInput = webpack.getByProps(["defaultProps", "Sizes", "contextType"]); - Button = webpack.getByProps(["Hovers", "Looks", "Sizes"]); -}, 3500); +let TextInput: any; -export function buildEncModal() { - let secret: string; - let cover: string; - let password: string = "password"; - let valid: boolean = false; - if (!TextInput || !Button) return; - if (!ModalRoot || !ModalContent || !ModalHeader || !ModalFooter) return; +export async function initEncModal() { + TextInput = webpack.getExportsForProps(await rawTextInput, ["contextType"]); + Button = webpack.getExportsForProps(await rawButton, ["Link"]); +} - function isValid() { - if (secret && cover && cover.match(/\w \w/)) { - valid = true; - } else { - valid = false; - } // Enforcing the 2 words, space is NOT a valid thing - } +let modalKey: any; - const s = openModal!((props) => ( +export function EncModal(props: ModalProps) { + let [secret, setSecret] = React.useState(""); + let [cover, setCover] = React.useState(""); + let [password, setPassword] = React.useState("password"); + + const valid = secret && cover && /\w \w/.test(cover); + + return (
Encrypt Message
@@ -45,30 +46,26 @@ export function buildEncModal() {
Secret
{ - secret = e; - isValid(); + setSecret(e); }}>
Cover (2 or more Words!!)
{ - cover = e; - isValid(); + setCover(e); }}>
Password
{ - isValid(); - password = e; + setPassword(e); }}> @@ -84,11 +81,15 @@ export function buildEncModal() { style={{ left: 15, position: "absolute" }} onClick={() => { // @ts-ignore - closeModal(s); + closeModal(modalKey); }}> Cancel
- )); + ); +} + +export function buildEncModal(): any { + modalKey = openModal((props) => ); } diff --git a/src/components/Modals.tsx b/src/components/Modals.tsx index e67398b..60ca59f 100644 --- a/src/components/Modals.tsx +++ b/src/components/Modals.tsx @@ -47,6 +47,7 @@ interface Modals { interface ModalRootProps { transitionState?: ModalTransitionState; + /* eslint-disable */ children: React.ReactNode; size?: ModalSize; role?: "alertdialog" | "dialog"; @@ -59,46 +60,34 @@ type RenderFunction = (props: ModalProps) => React.ReactNode; export let ModalAPI: any; export let Modals: Modals; -try { - setTimeout(() => { - // Populate ModalAPI - ModalAPI = { - openModal: webpack.getFunctionBySource( - "onCloseRequest:null!=", - webpack.getBySource("onCloseRequest:null!=")!, - ), - closeModal: webpack.getFunctionBySource( - "onCloseCallback&&", - webpack.getBySource("onCloseRequest:null!=")!, - ), - }; - // Populate Modal Types - - Modals = { - ModalRoot: webpack.getFunctionBySource( - "().root", - webpack.getBySource("().closeWithCircleBackground")!, - ), - ModalHeader: webpack.getFunctionBySource( - "().header", - webpack.getBySource("().closeWithCircleBackground")!, - ), - ModalContent: webpack.getFunctionBySource( - "().content", - webpack.getBySource("().closeWithCircleBackground")!, - ), - ModalFooter: webpack.getFunctionBySource( - "().footerSeparator", - webpack.getBySource("().closeWithCircleBackground")!, - ), - ModalCloseButton: webpack.getFunctionBySource( - "().closeWithCircleBackground", - webpack.getBySource("().closeWithCircleBackground")!, - ), - }; - }, 1500); -} catch (e) { - console.log(e); +export async function initModals() { + let rawModalModule = webpack.waitForModule(webpack.filters.bySource("onCloseRequest:null!=")); + let rawModalsModule = webpack.waitForModule( + webpack.filters.bySource("().closeWithCircleBackground"), + ); + + ModalAPI = { + // @ts-ignore + openModal: webpack.getFunctionBySource("onCloseRequest:null!=", await rawModalModule), + // @ts-ignore + closeModal: webpack.getFunctionBySource("onCloseCallback&&", await rawModalModule), + }; + + Modals = { + // @ts-ignore + ModalRoot: webpack.getFunctionBySource("().root", await rawModalsModule), + // @ts-ignore + ModalHeader: webpack.getFunctionBySource("().header", await rawModalsModule)!, + // @ts-ignore + ModalContent: webpack.getFunctionBySource("().content", await rawModalsModule)!, + // @ts-ignore + ModalFooter: webpack.getFunctionBySource("().footerSeparator", await rawModalsModule)!, + ModalCloseButton: webpack.getFunctionBySource( + "().closeWithCircleBackground", + // @ts-ignore + await rawModalsModule, + )!, + }; } export const ModalRoot = (props: ModalRootProps) => ; @@ -111,7 +100,7 @@ export function openModal( render: RenderFunction, options?: ModalOptions, contextKey?: string, -): void { +): string { return ModalAPI.openModal(render, options, contextKey); } diff --git a/src/index.ts b/src/index.ts index 0d24d43..0085813 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,8 +4,11 @@ import { popoverIcon } from "./assets/popoverIcon"; import { chatbarLock } from "./assets/chatbarLock"; import { Indicator } from "./assets/indicator"; -import { buildDecModal } from "./components/DecryptionModal"; +import { buildDecModal, initDecModal } from "./components/DecryptionModal"; +import { initModals } from "./components/Modals"; + import StegCloak from "./lib/stegcloak.js"; +import { initEncModal } from "./components/EncryptionModal"; const inject = new Injector(); const steggo: StegCloak = new StegCloak(true, false); @@ -21,9 +24,11 @@ const URL_DETECTION = new RegExp( /(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/, ); -// eslint-disable-next-line @typescript-eslint/require-await export async function start(): Promise { - console.log("%c [Invisible Chat] Started!", "color: aquamarine"); + // Prepare Modals + await initModals(); + await initDecModal(); + await initEncModal(); // Register the Message Receiver // @ts-expect-error We are adding to Window @@ -34,11 +39,13 @@ export async function start(): Promise { chatbarLock, Indicator, }; + + console.log("%c [Invisible Chat] Started!", "color: aquamarine"); } // Grab the data from the above Plantext Patches function receiver(message: unknown): void { - buildDecModal(message); + void buildDecModal({ message }); } // Gets the Embed of a Link @@ -98,7 +105,9 @@ export function stop(): void { } export function encrypt(secret: string, password: string, cover: string): string { - return steggo.hide(secret, password, cover); + // Add Identifier unicode to secret (\u200b) + // eslint-disable-next-line no-irregular-whitespace + return steggo.hide(`${secret}​`, password, cover); } export function decrypt(secret: string, password: string): string { diff --git a/src/plaintextPatches.ts b/src/plaintextPatches.ts index 3f03562..32b80c7 100644 --- a/src/plaintextPatches.ts +++ b/src/plaintextPatches.ts @@ -11,7 +11,7 @@ const patches: types.PlaintextPatch[] = [ }, { // Chatbar Lock - match: /.=.\.activeCommand,.=.\.activeCommandOption,.{0,155},(.)=\[\];/, + match: /.=.\.activeCommand,.=.\.activeCommandOption,.{0,155}(.)=\[\];/, replace: "$&;$1.push(window.invisiblechat.chatbarLock);", }, {