Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/game-overlay' into feat/gam…
Browse files Browse the repository at this point in the history
…e-overlay
  • Loading branch information
Wurielle committed Jan 15, 2025
2 parents 7e3f13d + 1e9c51e commit 94c886e
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions apps/app/src/electron/game-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { Window } from 'win-control'
import { Deferred } from '@packages/toolbox'

type ProcessInfo = {
process: string,
pid: number,
filepath: string,
process: string
pid: number
filepath: string
user: string
}

Expand All @@ -33,8 +33,7 @@ class GameOverlay {
private markQuit = false
private scaleFactor = 1.0

constructor() {
}
constructor() {}

public isReady = () => ready.promise

Expand Down Expand Up @@ -85,12 +84,12 @@ class GameOverlay {
const { top, left, right, bottom } = Window.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)
Expand Down Expand Up @@ -251,7 +250,7 @@ class GameOverlay {
for (const window of this.Overlay.getTopWindows()) {
if (window.processId === processInfo.pid) {
console.log(
`--------------------\n injecting ${ JSON.stringify(window) }`,
`--------------------\n injecting ${JSON.stringify(window)}`,
)
this.Overlay.injectProcess(window)
this.hookedProcesses.push(processInfo)
Expand All @@ -260,34 +259,33 @@ class GameOverlay {
}

public start() {
return import('@packages/electron-game-overlay')
.then((Overlay) => {
this.Overlay = Overlay.default
this.scaleFactor = screen.getDisplayNearestPoint({
x: 0,
y: 0,
}).scaleFactor

this.startOverlay()
return import('@packages/electron-game-overlay').then((Overlay) => {
this.Overlay = Overlay.default
this.scaleFactor = screen.getDisplayNearestPoint({
x: 0,
y: 0,
}).scaleFactor

const child = fork(path.join(EXTERNALS_DIR, 'detect-game.js'))
this.startOverlay()

child.on('message', (processInfo: ProcessEvent) => {
if (processInfo.type === 'game-detection') {
this.injectByProcessOnceFocused(processInfo.payload)
}
})
const child = fork(path.join(EXTERNALS_DIR, 'detect-game.js'))

onIPCGameOverlayStartIntercept(() => {
this.startIntercept()
})
child.on('message', (processInfo: ProcessEvent) => {
if (processInfo.type === 'game-detection') {
this.injectByProcessOnceFocused(processInfo.payload)
}
})

onIPCGameOverlayStopIntercept(() => {
this.stopIntercept()
})
onIPCGameOverlayStartIntercept(() => {
this.startIntercept()
})

return ready.resolve(true)
onIPCGameOverlayStopIntercept(() => {
this.stopIntercept()
})

return ready.resolve(true)
})
}

public quit() {
Expand Down

0 comments on commit 94c886e

Please sign in to comment.