@@ -144,6 +144,66 @@ int send_auth_to_obs(std::string payload) {
144
144
return 0 ;
145
145
}
146
146
147
+ int open_obs_mp_window ()
148
+ {
149
+ int pipe_number = 0 ;
150
+ std::string pipe_name = " elgato_cloud" ;
151
+ std::string base_name = " \\\\ .\\ pipe\\ " + pipe_name;
152
+ std::string attempt_name;
153
+ HANDLE pipe = INVALID_HANDLE_VALUE;
154
+ SECURITY_ATTRIBUTES sa;
155
+ SECURITY_DESCRIPTOR sd;
156
+ InitializeSecurityDescriptor (&sd, SECURITY_DESCRIPTOR_REVISION);
157
+ SetSecurityDescriptorDacl (&sd, TRUE , NULL , FALSE );
158
+ sa.nLength = sizeof (sa);
159
+ sa.lpSecurityDescriptor = &sd;
160
+ sa.bInheritHandle = FALSE ;
161
+
162
+ int connect_attempts_remaining = 60 ;
163
+
164
+ printf (" Waiting for OBS to launch..." );
165
+
166
+ while (connect_attempts_remaining-- > 0 &&
167
+ pipe == INVALID_HANDLE_VALUE) {
168
+ pipe_number = 0 ;
169
+ attempt_name = base_name + std::to_string (pipe_number);
170
+ printf (" Attempting %s\n " , attempt_name.c_str ());
171
+ pipe = CreateFileA (attempt_name.c_str (), GENERIC_WRITE,
172
+ 0 , &sa, OPEN_EXISTING, 0 , NULL );
173
+ if (pipe != INVALID_HANDLE_VALUE) {
174
+ printf (" Success\n " );
175
+ break ;
176
+ }
177
+ if (pipe == INVALID_HANDLE_VALUE) {
178
+ Sleep (1000 );
179
+ }
180
+ }
181
+ if (pipe == INVALID_HANDLE_VALUE) {
182
+ printf (" Could not connect to OBS!" );
183
+ return 1 ;
184
+ }
185
+ DWORD mode = PIPE_READMODE_MESSAGE;
186
+ auto success = SetNamedPipeHandleState (pipe, &mode, NULL , NULL );
187
+ if (!success) {
188
+ CloseHandle (pipe);
189
+ printf (" Could not configure named pipe!" );
190
+ return 1 ;
191
+ }
192
+
193
+ DWORD written = 0 ;
194
+ std::string payload = " elgatolink://open" ;
195
+ success = WriteFile (pipe, payload.c_str (), static_cast <DWORD>(payload.size ()), &written,
196
+ NULL );
197
+ if (!success || written < payload.size ()) {
198
+ printf (" Failed to write to named pipe!" );
199
+ CloseHandle (pipe);
200
+ return 1 ;
201
+ }
202
+
203
+ CloseHandle (pipe);
204
+ return 0 ;
205
+ }
206
+
147
207
int launch_obs ()
148
208
{
149
209
DWORD buffer_size = BUFFER_SIZE;
@@ -216,8 +276,10 @@ int main(int argc, char *argv[]) {
216
276
// Send auth to OBS which requested it.
217
277
return send_auth_to_obs (payload);
218
278
} else {
219
- return launch_obs ();
279
+ int resp = launch_obs ();
280
+ open_obs_mp_window ();
281
+ // return open_obs_mp_window();
220
282
}
221
283
printf (" No obs found to launch." );
222
- return 1 ;
284
+ // return 1;
223
285
}
0 commit comments