To enable an electron app to have the ability to show its web browser window in another game process, we need to injecting a module (dll in Windows) to the game, make an IPC connection with our electron process, copy the screenshot of our electron app's browser window and render it over the game's surface.
Then, since we also want our injected web page can reponse to user's input, we need to intercept the game's input so that we can pass the input to out electron app and send it the the browser window.
This is the most important module (a dll), it will be injected into game process so that we can communicate with a game process and draw our own stuff on game window.
This is a helper process which do the real dll injecting work for use.
This is the node addon used in our electron app, use it to communicate with game process (n_overlay.dll), like sending electron webview framebuffer and recieve game input data.
It also doing do injecting using n_ovhelper.exe, get the system's foreground window(we can check if it's the game window to decide when we will do injecting).
so with the modules, basicly what we need to do is
- make sure your compile x86 and x64 version native modules for the game you want to inejct
- build
game-overlay.slnwith Release config for x86 or x64 version, you'll getn_ovhelper.exeandn_overlay.dllfor x86 version (orn_ovhelper.x64.exeandn_overlay.x64.dllfor the x64 version) - add
electron-overlayaddons to your electron ap's dependency, nodejs should automatically build them, if not cd to their directory and build them manually. - copy
n_ovhelper.exeandn_overlay.dlltonode_modules/electron-overlay.
- build
- prepare a game
- the electron app
- Create an electorn app
- import
electron-overlayaddon (asIOverlayfor example),- use
IOverlay.start()to start the overlay server - set up hotkeys and event callbacks (
game.inputis the most important one)
- use
- create a transparent browser window (so we can capture it surface and pass it to the game)
- after create the transparent browser window, use
IOverlay.addWindow(...)to add it to the overlay windows - listen on its paint event and send the framebuffer to overlay use
IOverlay.sendFrameBuffer
- after create the transparent browser window, use
- on
game.inputevent, translate the event to electron's format useIOverlay.translateInputEvent, and pass to electorn's windowwindow.webContents.sendInputEvent(inputEvent) - don't forget to handle window's
resizeevents
- do injecting.
- call
injectProcessto help us inject then_overlay.dllmodule to the game process
- call
- if everything is ok ,you should see the injected browser window in game process
check out hot the demo (client/src/main/electron/app-entry.ts) uses hotkeys by this.Overlay!.setHotkeys
if we look at the demo, we can find that on the topleft, a small browser window is always show in the game and other windows will show or hide responding to our hotkey.
Actually we can decide which window will always stay in game and which will only appear if we calls it.
Now, I do it in the n_overlay module, so if you want to do some customizing you need to change to code in n_overlay.