This repository was archived by the owner on Mar 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
246 lines (216 loc) · 8.12 KB
/
main.js
File metadata and controls
246 lines (216 loc) · 8.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
// Modules to control application life and create native browser window
const {app, ipcMain, BrowserWindow, BrowserView} = require('electron');
const { write } = require('fs');
const { type } = require('os');
const path = require('path')
const advancedfx_gui_native = require('bindings')('advancedfx_gui_native')
const jsonrpc = require('./modules/jsonrpc.js');
app.disableHardwareAcceleration()
let writePipe
let readPipe
function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
preload: path.join(__dirname, 'preload.js')
}
})
let overlayWindow;
let overlayWindowDidFinishLoad = false;
let overlayTexture;
// and load the index.html of the app.
mainWindow.loadFile('index.html')
// Open the DevTools.
// mainWindow.webContents.openDevTools()
serverWritePipe = new advancedfx_gui_native.AnonymousPipe();
serverReadPipe = new advancedfx_gui_native.AnonymousPipe();
clientWritePipe = new advancedfx_gui_native.AnonymousPipe();
clientReadPipe = new advancedfx_gui_native.AnonymousPipe();
mainWindow.on('closed', function(){
})
let serverWritePipeReadHandle = serverWritePipe.nativeReadHandleToLong();
let serverReadPipeWriteHandle = serverReadPipe.nativeWriteHandleToLong();
let jsonRpcServer = new jsonrpc.JsonRpc_2_0_Server(async () => { return await serverReadPipe.readString(); }, async(value) => { await serverWritePipe.writeString(value); });
jsonRpcServer.on('GetAfxHookSourceServerReadHandle', async () => {
return clientWritePipe.nativeReadHandle();
});
jsonRpcServer.on('GetAfxHookSourceServerWriteHandle', async () => {
return clientReadPipe.nativeWriteHandle();
});
jsonRpcServer.on('DrawingWindowCreated', async (adapterLuid,width,height) => {
overlayTexture = new advancedfx_gui_native.SharedTexture(adapterLuid,width,height);
clientWritePipe.writeString(JSON.stringify({
"jsonrpc": "2.0",
"method": "SetSharedTextureHandle",
"params": [overlayTexture.getSharedHandle()]
}));
clientReadPipe.readString();
overlayWindow = new BrowserWindow({
"x": 0,
"y": 0,
"width": width,
"height": height,
show: false,
frame: false,
transparent: true,
paintWhenInitiallyHidden: false,
webPreferences: {
backgroundThrottling: false,
offscreen: true,
preload: path.join(__dirname, 'overlay_preload.js')
}
})
overlayWindow.webContents.on('did-finish-load', ()=>{
overlayWindowDidFinishLoad = true;
overlayWindow.webContents.send('checkInputCaptured','dummy');
});
overlayWindow.webContents.on("paint", (event, dirty, image) => {
console.log("paint");
if(overlayTexture) {
/*clientWritePipe.writeString(JSON.stringify({
"jsonrpc": "2.0",
"method": "LockSharedTexture",
"params": []
}));*/
console.log(dirty);
overlayTexture.update(dirty,image.getBitmap());
/*clientWritePipe.writeString(JSON.stringify({
"jsonrpc": "2.0",
"method": "UnlockSharedTexture",
"params": []
}));*/
}
})
overlayWindow.webContents.on("cursor-changed", (event,type) => {
clientWritePipe.writeString(JSON.stringify({
"jsonrpc": "2.0",
"method": "SetMouseCursor",
"params": [type]
}));
clientReadPipe.readString().then((result)=>{
})
})
overlayWindow.webContents.loadFile("overlay_index.html")
});
jsonRpcServer.on('DrawingWindowDestroyed', async() =>{
clientWritePipe.writeString(JSON.stringify({
"jsonrpc": "2.0",
"method": "SetSharedTextureHandle",
"params": [advancedfx_gui_native.getInvalidHandleValue()]
}));
clientReadPipe.readString();
if(overlayWindow) {
overlayWindowDidFinishLoad = false;
overlayWindow.destroy();
overlayWindow = null;
}
if(overlayTexture) {
overlayTexture.delete();
overlayTexture = null;
}
});
async function overlayRendererInvoke(overlayWindow,channel,...args) {
return await new Promise((resolve,reject)=>{
ipcMain.once("advancedfxAck-"+overlayWindow.webContents.id, (event,...args)=>{
resolve(args);
});
overlayWindow.webContents.send(channel, overlayWindow.webContents.id, ...args);
})
}
jsonRpcServer.on('SendMouseInputEvent', async(ev)=>{
if(overlayWindowDidFinishLoad) {
if(overlayWindow.isFocusable() && !overlayWindow.isFocused()) overlayWindow.focus();
overlayWindow.webContents.sendInputEvent(ev);
console.log("waiting: "+ev.type);
result = await overlayRendererInvoke(overlayWindow,"afxEndInput");
console.log(result);
return result[0];
}
return false;
});
jsonRpcServer.on('SendMouseWheelInputEvent', async(ev)=>{
if(overlayWindowDidFinishLoad) {
if(overlayWindow.isFocusable() && !overlayWindow.isFocused()) overlayWindow.focus();
if(ev.globalX !== undefined && ev.globalY !== undefined) {
// work around electron bug:
ev.x -= ev.globalX - ev.x;
ev.y -= ev.globalY - ev.y;
}
overlayWindow.webContents.sendInputEvent(ev);
console.log("waiting: "+ev.type);
result = await overlayRendererInvoke(overlayWindow,"afxEndInput");
console.log(result);
return result[0];
}
return false;
});
jsonRpcServer.on('SendKeyboardInputEvent', async(ev)=>{
if(overlayWindowDidFinishLoad) {
if(overlayWindow.isFocusable() && !overlayWindow.isFocused()) overlayWindow.focus();
overlayWindow.webContents.sendInputEvent(ev);
console.log("waiting: "+ev.type);
result = await overlayRendererInvoke(overlayWindow,"afxEndInput");
console.log(result);
return result[0];
}
return false;
});
let pump = jsonRpcServer.pump();
const { execFile }= require('child_process');
execFile('C:\\source\\advancedfx-v3\\build\\Release\\bin\\hlae.exe', [
'-customLoader',
'-noGui',
'-autoStart',
'-addEnv', 'SteamPath=C:\\Program Files (x86)\\Steam',
'-addEnv', 'SteamClientLaunch=1',
'-addEnv', 'SteamGameId=730',
'-addEnv', 'SteamAppId=730',
'-addEnv', 'SteamOverlayGameId=730',
'-addEnv', 'USRLOCALCSGO=C:\\Users\\Dominik\\Desktop\\mmcfg',
'-addEnv', `AFXGUI_PIPE_READ=${serverWritePipeReadHandle}`,
'-addEnv', `AFXGUI_PIPE_WRITE=${serverReadPipeWriteHandle}`,
'-hookDllPath', 'C:\\source\\advancedfx-v3\\build\\Release\\bin\\AfxHookSource.dll',
'-programPath', 'C:\\Program Files (x86)\\Steam\\steamapps\\common\\Counter-Strike Global Offensive\\csgo.exe',
'-cmdLine', '-steam -insecure +sv_lan 1 -window -console -game csgo +echo "Hello World" -w 1280 -h 720'
], (error, stdout, stderr) => {
if (error) {
throw error;
}
console.log(stdout);
});
}
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
createWindow()
app.on('activate', function () {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', function () {
async function asyncWindowAllClosed(){
if(serverWritePipe) await serverWritePipe.close();
if(serverReadPipe) await serverReadPipe.close();
if(clientWritePipe) await clientWritePipe.close();
if(clientReadPipe) await clientReadPipe.close();
await pump;
if (process.platform !== 'darwin') app.quit()
}
asyncWindowAllClosed();
})
app.on('will-quit', function() {
})
// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.
ipcMain.handle('jsonRequest', async (event,value) => {
//await writePipe.writeString(value);
//return await readPipe.readString();
})