diff --git a/apps/app/src/electron/app.ts b/apps/app/src/electron/app.ts index 2a5bdbe4..51f2837a 100644 --- a/apps/app/src/electron/app.ts +++ b/apps/app/src/electron/app.ts @@ -7,7 +7,10 @@ import { createApp, h } from 'vue' import { createPinia } from 'pinia' import createTray from '@/teams/tray/electron-tray' import ElectronWindowManager from '@/modules/electron-window-manager' -import { createMessengerGameOverlayWindow, createMessengerWindow } from '@/teams/messenger/electron/background' +import { + createMessengerGameOverlayWindow, + createMessengerWindow, +} from '@/teams/messenger/electron/background' import { createSpeechWorkerWindow } from '@/teams/speech-worker/electron/background' import { bridgeModules } from '@/electron/bridge' import registerElectronStartup from '@/modules/electron-startup/register' @@ -27,25 +30,26 @@ const App = () => { const createWindows = () => app .whenReady() - .then(async () => Promise.all([ - ElectronWindowManager.registerInstance( - 'messenger', - createMessengerWindow, - ), - ElectronWindowManager.registerInstance( - 'overlay', - createOverlayWindow, - ), - ElectronWindowManager.registerInstance( - 'speech-worker', - createSpeechWorkerWindow, - ), - ElectronWindowManager.registerInstance( - 'messenger-game-overlay', - createMessengerGameOverlayWindow, - ), - ])) - + .then(async () => + Promise.all([ + ElectronWindowManager.registerInstance( + 'messenger', + createMessengerWindow, + ), + ElectronWindowManager.registerInstance( + 'overlay', + createOverlayWindow, + ), + ElectronWindowManager.registerInstance( + 'speech-worker', + createSpeechWorkerWindow, + ), + ElectronWindowManager.registerInstance( + 'messenger-game-overlay', + createMessengerGameOverlayWindow, + ), + ]), + ) const registerElectronPinia = () => { createApp(h({})).use( @@ -54,9 +58,7 @@ const App = () => { } const startGameOverlay = async () => - app.whenReady().then(() => - gameOverlay.start(), - ) + app.whenReady().then(() => gameOverlay.start()) const startAppServer = async () => app.whenReady().then(async () => @@ -89,7 +91,7 @@ const App = () => { } function exec(description: string, action: () => any) { - console.log(`[app]: ${ description }`) + console.log(`[app]: ${description}`) return action() } @@ -164,7 +166,10 @@ const App = () => { app.on('web-contents-created', (_, webContents) => { webContents.on('preload-error', (_, preloadPath, error) => { - console.error(`Preload script error:\nPath: ${ preloadPath }\nError:`, error) + console.error( + `Preload script error:\nPath: ${preloadPath}\nError:`, + error, + ) }) }) } diff --git a/apps/app/src/electron/game-overlay.ts b/apps/app/src/electron/game-overlay.ts index 978f9d27..af011435 100644 --- a/apps/app/src/electron/game-overlay.ts +++ b/apps/app/src/electron/game-overlay.ts @@ -37,8 +37,7 @@ class GameOverlay { private markQuit = false private scaleFactor = 1.0 - constructor() { - } + constructor() {} public isReady = () => ready.promise @@ -89,12 +88,12 @@ class GameOverlay { const { top, left, right, bottom } = this.WinControl.getByPid( payload.pid, ).getDimensions() - const width = right-left - const height = bottom-top + const width = right - left + const height = bottom - top mouse.getPosition().then(async (initialPosition) => { await mouse.setPosition( - new Point(left+width / 2, top+height / 2), + new Point(left + width / 2, top + height / 2), ) await mouse.leftClick() await mouse.setPosition(initialPosition) @@ -254,9 +253,7 @@ class GameOverlay { public injectByProcess(processInfo: ProcessInfo) { for (const window of this.Overlay.getTopWindows()) { if (window.processId === processInfo.pid) { - console.log( - `[game-overlay] Injecting ${ JSON.stringify(window) }`, - ) + console.log(`[game-overlay] Injecting ${JSON.stringify(window)}`) this.Overlay.injectProcess(window) this.hookedProcesses.push(processInfo) } @@ -267,7 +264,11 @@ class GameOverlay { const databasesStore = useDatabasesStore() const gameOverlayStore = useGameOverlayStore() /* Importing win-control in preload breaks reload so we import it dynamically on start instead */ - return Promise.all([import('@packages/electron-game-overlay'), import('win-control'), gameOverlayStore.$whenReady()]).then(([Overlay, WinControl]) => { + return Promise.all([ + import('@packages/electron-game-overlay'), + import('win-control'), + gameOverlayStore.$whenReady(), + ]).then(([Overlay, WinControl]) => { this.WinControl = WinControl this.Overlay = Overlay.default this.scaleFactor = screen.getDisplayNearestPoint({ @@ -277,35 +278,62 @@ class GameOverlay { this.startOverlay() - - watch(() => [gameOverlayStore.enableGameOverlay, gameOverlayStore.allowlist, gameOverlayStore.denylist, databasesStore.data], () => { - if (!gameOverlayStore.enableGameOverlay) return - console.log('[game-overlay] Creating process watcher process') - const child = fork(path.join(EXTERNALS_DIR, 'detect-game.js')) - child.on('message', (processInfo: ProcessEvent) => { - if (processInfo.type === 'process-creation') { - const { filepath } = processInfo.payload - const isGame = micromatch.isMatch(filepath, [...gameOverlayStore.allowlist, ...(databasesStore.data['game-overlay-allowlist'] || [])].filter(Boolean)) - && !micromatch.isMatch(filepath, [...gameOverlayStore.denylist, ...(databasesStore.data['game-overlay-denylist'] || [])].filter(Boolean)) - if (isGame) { - console.log('[game-overlay]: Game launched', filepath) - // require('windows-tlist').getProcessInfo(processInfo.payload.pid).then(({ modules }: any) => console.log(modules.map(({ path }: any) => path.substring(path.lastIndexOf('\\')+1)))) - this.injectByProcessOnceFocused(processInfo.payload) + watch( + () => [ + gameOverlayStore.enableGameOverlay, + gameOverlayStore.allowlist, + gameOverlayStore.denylist, + databasesStore.data, + ], + () => { + if (!gameOverlayStore.enableGameOverlay) return + console.log('[game-overlay] Creating process watcher process') + const child = fork(path.join(EXTERNALS_DIR, 'detect-game.js')) + child.on('message', (processInfo: ProcessEvent) => { + if (processInfo.type === 'process-creation') { + const { filepath } = processInfo.payload + const isGame = + micromatch.isMatch( + filepath, + [ + ...gameOverlayStore.allowlist, + ...(databasesStore.data['game-overlay-allowlist'] || []), + ].filter(Boolean), + ) && + !micromatch.isMatch( + filepath, + [ + ...gameOverlayStore.denylist, + ...(databasesStore.data['game-overlay-denylist'] || []), + ].filter(Boolean), + ) + if (isGame) { + console.log('[game-overlay]: Game launched', filepath) + // require('windows-tlist').getProcessInfo(processInfo.payload.pid).then(({ modules }: any) => console.log(modules.map(({ path }: any) => path.substring(path.lastIndexOf('\\')+1)))) + this.injectByProcessOnceFocused(processInfo.payload) + } } - } - if (processInfo.type === 'process-deletion') { - if (this.hookedProcesses.find((process) => process.pid === processInfo.payload.pid)) { - this.hookedProcesses = this.hookedProcesses.filter((process) => process.pid !== processInfo.payload.pid) + if (processInfo.type === 'process-deletion') { + if ( + this.hookedProcesses.find( + (process) => process.pid === processInfo.payload.pid, + ) + ) { + this.hookedProcesses = this.hookedProcesses.filter( + (process) => process.pid !== processInfo.payload.pid, + ) + } } - } - }) - onWatcherCleanup(() => { - child.kill() - }) - }, { - deep: true, - immediate: true, - }) + }) + onWatcherCleanup(() => { + child.kill() + }) + }, + { + deep: true, + immediate: true, + }, + ) onIPCGameOverlayStartIntercept(() => { this.startIntercept() diff --git a/apps/app/src/teams/messenger/modules/electron-messenger-window/index.ts b/apps/app/src/teams/messenger/modules/electron-messenger-window/index.ts index 096ad281..168de149 100644 --- a/apps/app/src/teams/messenger/modules/electron-messenger-window/index.ts +++ b/apps/app/src/teams/messenger/modules/electron-messenger-window/index.ts @@ -3,7 +3,10 @@ import { mouse } from '@/modules/node-mouse' import throttle from 'lodash/throttle' import { Hitbox } from '@/modules/vue-hitboxes/types' import { BrowserWindow, screen, shell } from 'electron' -import { useMessengerStore, useMessengerWindowStore } from '@/teams/messenger/store' +import { + useMessengerStore, + useMessengerWindowStore, +} from '@/teams/messenger/store' import { useSettingsStore } from '@/features/settings/store' import { useHitboxesStore } from '@/modules/vue-hitboxes/hitboxes.store' import { Deferred } from '@packages/toolbox' @@ -184,9 +187,9 @@ export const ElectronMessengerWindow = () => { .filter(({ w, h }) => w && h) .some(({ x, y, w, h }: Hitbox) => { const isWithinXHitbox = - mouseX >= windowX+x && mouseX <= windowX+x+w + mouseX >= windowX + x && mouseX <= windowX + x + w const isWithinYHitbox = - mouseY >= windowY+y && mouseY <= windowY+y+h + mouseY >= windowY + y && mouseY <= windowY + y + h return isWithinXHitbox && isWithinYHitbox }) if (isWithinAnyHitboxes) { @@ -200,7 +203,9 @@ export const ElectronMessengerWindow = () => { const toggleWindow = throttle((context: 'mouse' | 'keyboard') => { const foregroundWindowPid = WinControl?.getForeground()?.getPid() - const hookedProcess = gameOverlay.hookedProcesses.find((process) => process.pid === foregroundWindowPid) + const hookedProcess = gameOverlay.hookedProcesses.find( + (process) => process.pid === foregroundWindowPid, + ) if (hookedProcess && !gameOverlay.intercepting) { gameOverlay.startIntercept() return @@ -293,7 +298,7 @@ export const ElectronMessengerWindow = () => { setDisplay(localSettingsStore.display) }) ready.resolve(window) - import('win-control').then((module) => WinControl = module) + import('win-control').then((module) => (WinControl = module)) } isReady().then(() => {