-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetDevices.cs
333 lines (321 loc) · 15.3 KB
/
GetDevices.cs
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
// Decompiled with JetBrains decompiler
// Type: OculusTrayTool.GetDevices
// Assembly: OculusTrayTool, Version=0.87.8.0, Culture=neutral, PublicKeyToken=null
// MVID: E8946A27-16D6-4BF6-9D7B-70CB25A977E0
// Assembly location: C:\Program Files (x86)\Oculus Tray Tool\OculusTrayTool.exe
using CoreAudio;
using Microsoft.VisualBasic.CompilerServices;
using OculusTrayTool.My;
using System;
using System.Windows.Forms;
#nullable disable
namespace OculusTrayTool
{
[StandardModule]
internal sealed class GetDevices
{
private static MMDeviceEnumerator devenum = new MMDeviceEnumerator();
private static MMDeviceCollection AudioDevices;
private static MMDeviceCollection MicDevices;
public static int AudioDevCount = 0;
public static int MicdevCount = 0;
public static void GetAllAudioDevices()
{
try
{
Log.WriteToLog("Getting list of available audio devices");
GetDevices.AudioDevices = GetDevices.devenum.EnumerateAudioEndPoints(EDataFlow.eRender, DEVICE_STATE.DEVICE_STATE_ACTIVE);
GetDevices.AudioDevCount = GetDevices.AudioDevices.Count;
MyProject.Forms.FrmSetFallback.ComboAudioFallback.DataSource = (object) null;
MyProject.Forms.FrmSetFallback.ComboAudioFallbackSource.Clear();
MyProject.Forms.FrmSetFallback.ComboAudioFallback.Items.Clear();
MyProject.Forms.FrmSetFallback.ComboCommFallback.DataSource = (object) null;
MyProject.Forms.FrmSetFallback.ComboCommFallback.Items.Clear();
MyProject.Forms.FrmSetFallback.ComboBox4.DataSource = (object) null;
MyProject.Forms.FrmSetFallback.ComboBox4.Items.Clear();
MyProject.Forms.FrmSetFallback.ComboBox6.DataSource = (object) null;
MyProject.Forms.FrmSetFallback.ComboBox6.Items.Clear();
if (GetDevices.AudioDevices.Count > 0)
{
int num = checked (GetDevices.AudioDevices.Count - 1);
int index = 0;
while (index <= num)
{
if (GetDevices.AudioDevices[index].Properties[checked (GetDevices.AudioDevices[index].Properties.Count - 3)].Value.ToString().ToLower().Contains("rift"))
{
MySettingsProperty.Settings.RiftAudioGuid = GetDevices.AudioDevices[index].ID.ToString();
MySettingsProperty.Settings.Save();
Log.WriteToLog("Rift Audio ID: " + GetDevices.AudioDevices[index].ID.ToString().Replace("{", "[").Replace("}", "]"));
}
MyProject.Forms.FrmSetFallback.ComboAudioFallbackSource.Add(GetDevices.AudioDevices[index].ID.ToString(), GetDevices.AudioDevices[index].Properties[checked (GetDevices.AudioDevices[index].Properties.Count - 3)].Value.ToString());
checked { ++index; }
}
if (GetDevices.AudioDevices.Count > 1)
{
MyProject.Forms.FrmSetFallback.ComboAudioFallbackSource.Add("1", "Use current default");
MyProject.Forms.FrmSetFallback.ComboAudioFallback.DataSource = (object) new BindingSource((object) MyProject.Forms.FrmSetFallback.ComboAudioFallbackSource, (string) null);
MyProject.Forms.FrmSetFallback.ComboAudioFallback.DisplayMember = "Value";
MyProject.Forms.FrmSetFallback.ComboAudioFallback.ValueMember = "Key";
MyProject.Forms.FrmSetFallback.ComboCommFallback.DataSource = (object) new BindingSource((object) MyProject.Forms.FrmSetFallback.ComboAudioFallbackSource, (string) null);
MyProject.Forms.FrmSetFallback.ComboCommFallback.DisplayMember = "Value";
MyProject.Forms.FrmSetFallback.ComboCommFallback.ValueMember = "Key";
MyProject.Forms.FrmSetFallback.ComboBox4.DataSource = (object) new BindingSource((object) MyProject.Forms.FrmSetFallback.ComboAudioFallbackSource, (string) null);
MyProject.Forms.FrmSetFallback.ComboBox4.DisplayMember = "Value";
MyProject.Forms.FrmSetFallback.ComboBox4.ValueMember = "Key";
MyProject.Forms.FrmSetFallback.ComboBox6.DataSource = (object) new BindingSource((object) MyProject.Forms.FrmSetFallback.ComboAudioFallbackSource, (string) null);
MyProject.Forms.FrmSetFallback.ComboBox6.DisplayMember = "Value";
MyProject.Forms.FrmSetFallback.ComboBox6.ValueMember = "Key";
}
else
{
MySettingsProperty.Settings.DefaultAudio = "";
MySettingsProperty.Settings.SystemDefaultAudioGuid = "";
MySettingsProperty.Settings.SystemDefaultCommAudioGuid = "";
MySettingsProperty.Settings.Save();
}
Log.WriteToLog("Found " + Conversions.ToString(checked (GetDevices.AudioDevices.Count - 1)) + " non-Rift output devices");
}
else
{
Log.WriteToLog("No enabled audio devices found");
FrmMain.fmain.AddToListboxAndScroll("No enabled audio devices found");
MyProject.Forms.FrmMain.hasWarning = true;
GetConfig.useVoiceCommands = false;
MyProject.Forms.FrmMain.ComboVoice.SelectedIndex = 0;
MyProject.Forms.FrmMain.ComboVoice.Enabled = false;
MyProject.Forms.FrmMain.BtnVoice.Enabled = false;
MySettingsProperty.Settings.DefaultAudio = "";
MySettingsProperty.Settings.SystemDefaultAudioGuid = "";
MySettingsProperty.Settings.Save();
}
}
catch (Exception ex)
{
ProjectData.SetProjectError(ex);
Log.WriteToLog("GetAllAudioDevices: " + ex.Message);
ProjectData.ClearProjectError();
}
}
public static void GetAllMicDevices()
{
try
{
Log.WriteToLog("Getting list of available microphone devices");
GetDevices.MicDevices = GetDevices.devenum.EnumerateAudioEndPoints(EDataFlow.eCapture, DEVICE_STATE.DEVICE_STATE_ACTIVE);
GetDevices.MicdevCount = GetDevices.MicDevices.Count;
MyProject.Forms.FrmSetFallback.ComboMicFallback.DataSource = (object) null;
MyProject.Forms.FrmSetFallback.ComboMicFallbackSource.Clear();
MyProject.Forms.FrmSetFallback.ComboMicFallback.Items.Clear();
MyProject.Forms.FrmSetFallback.ComboCommMicFallback.DataSource = (object) null;
MyProject.Forms.FrmSetFallback.ComboCommMicFallback.Items.Clear();
MyProject.Forms.FrmSetFallback.ComboBox3.DataSource = (object) null;
MyProject.Forms.FrmSetFallback.ComboBox3.Items.Clear();
MyProject.Forms.FrmSetFallback.ComboBox5.DataSource = (object) null;
MyProject.Forms.FrmSetFallback.ComboBox5.Items.Clear();
if (GetDevices.MicDevices.Count > 0)
{
int num = checked (GetDevices.MicDevices.Count - 1);
int index = 0;
while (index <= num)
{
if (GetDevices.MicDevices[index].Properties[checked (GetDevices.MicDevices[index].Properties.Count - 3)].Value.ToString().ToLower().Contains("rift"))
{
MySettingsProperty.Settings.RiftMicGuid = GetDevices.MicDevices[index].ID.ToString();
MySettingsProperty.Settings.Save();
Log.WriteToLog("Rift Microphone ID: " + GetDevices.MicDevices[index].ID.ToString().Replace("{", "[").Replace("}", "]"));
}
MyProject.Forms.FrmSetFallback.ComboMicFallbackSource.Add(GetDevices.MicDevices[index].ID.ToString(), GetDevices.MicDevices[index].Properties[checked (GetDevices.MicDevices[index].Properties.Count - 3)].Value.ToString());
checked { ++index; }
}
Log.WriteToLog("Found " + Conversions.ToString(checked (GetDevices.MicDevices.Count - 1)) + " non-Rift input devices");
}
else
{
Log.WriteToLog("No enabled microphone devices found");
FrmMain.fmain.AddToListboxAndScroll("No enabled microphone devices found");
MyProject.Forms.FrmMain.hasWarning = true;
GetConfig.useVoiceCommands = false;
MyProject.Forms.FrmMain.ComboVoice.SelectedIndex = 0;
MyProject.Forms.FrmMain.ComboVoice.Enabled = false;
MyProject.Forms.FrmMain.BtnVoice.Enabled = false;
MySettingsProperty.Settings.DefaultMic = "";
MySettingsProperty.Settings.SystemDefaultMicGuid = "";
MySettingsProperty.Settings.SystemDefaultCommGuid = "";
MySettingsProperty.Settings.Save();
}
if (GetDevices.MicDevices.Count > 1)
{
MyProject.Forms.FrmSetFallback.ComboMicFallbackSource.Add("1", "Use current default");
MyProject.Forms.FrmSetFallback.ComboMicFallback.DataSource = (object) new BindingSource((object) MyProject.Forms.FrmSetFallback.ComboMicFallbackSource, (string) null);
MyProject.Forms.FrmSetFallback.ComboMicFallback.DisplayMember = "Value";
MyProject.Forms.FrmSetFallback.ComboMicFallback.ValueMember = "Key";
MyProject.Forms.FrmSetFallback.ComboCommMicFallback.DataSource = (object) new BindingSource((object) MyProject.Forms.FrmSetFallback.ComboMicFallbackSource, (string) null);
MyProject.Forms.FrmSetFallback.ComboCommMicFallback.DisplayMember = "Value";
MyProject.Forms.FrmSetFallback.ComboCommMicFallback.ValueMember = "Key";
MyProject.Forms.FrmSetFallback.ComboBox3.DataSource = (object) new BindingSource((object) MyProject.Forms.FrmSetFallback.ComboMicFallbackSource, (string) null);
MyProject.Forms.FrmSetFallback.ComboBox3.DisplayMember = "Value";
MyProject.Forms.FrmSetFallback.ComboBox3.ValueMember = "Key";
MyProject.Forms.FrmSetFallback.ComboBox5.DataSource = (object) new BindingSource((object) MyProject.Forms.FrmSetFallback.ComboMicFallbackSource, (string) null);
MyProject.Forms.FrmSetFallback.ComboBox5.DisplayMember = "Value";
MyProject.Forms.FrmSetFallback.ComboBox5.ValueMember = "Key";
}
else
{
MySettingsProperty.Settings.DefaultMic = "";
MySettingsProperty.Settings.SystemDefaultMicGuid = "";
MySettingsProperty.Settings.SystemDefaultCommGuid = "";
MySettingsProperty.Settings.Save();
}
}
catch (Exception ex)
{
ProjectData.SetProjectError(ex);
Exception exception = ex;
if (Operators.CompareString(exception.HResult.ToString(), "-2147023728", false) == 0)
{
Log.WriteToLog("No microphone devices found!");
FrmMain.fmain.AddToListboxAndScroll("No microphone devices found!");
MyProject.Forms.FrmMain.hasWarning = true;
MySettingsProperty.Settings.DefaultMic = "";
MySettingsProperty.Settings.SystemDefaultMicGuid = "";
MySettingsProperty.Settings.Save();
}
else
Log.WriteToLog("GetAllMicDevices: " + exception.Message + " (" + exception.HResult.ToString() + ")");
ProjectData.ClearProjectError();
}
}
public static object GetDefaultMicDevice()
{
object defaultMicDevice;
try
{
defaultMicDevice = (object) GetDevices.devenum.GetDefaultAudioEndpoint(EDataFlow.eCapture, ERole.eMultimedia).ID.ToString();
}
catch (Exception ex)
{
ProjectData.SetProjectError(ex);
Log.WriteToLog("GetDefaultMicDevice: " + ex.Message);
defaultMicDevice = (object) "";
ProjectData.ClearProjectError();
}
return defaultMicDevice;
}
public static object GetDefaultMicDeviceName()
{
object defaultMicDeviceName;
try
{
MMDevice defaultAudioEndpoint = GetDevices.devenum.GetDefaultAudioEndpoint(EDataFlow.eCapture, ERole.eMultimedia);
defaultMicDeviceName = (object) defaultAudioEndpoint.Properties[checked (defaultAudioEndpoint.Properties.Count - 3)].Value.ToString();
}
catch (Exception ex)
{
ProjectData.SetProjectError(ex);
Log.WriteToLog("GetDefaultMicDeviceName: " + ex.Message);
defaultMicDeviceName = (object) "";
ProjectData.ClearProjectError();
}
return defaultMicDeviceName;
}
public static object GetDefaultAudioDevice()
{
object defaultAudioDevice;
try
{
defaultAudioDevice = (object) GetDevices.devenum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia).ID.ToString();
}
catch (Exception ex)
{
ProjectData.SetProjectError(ex);
Log.WriteToLog("GetDefaultAudioDevice: " + ex.Message);
defaultAudioDevice = (object) "";
ProjectData.ClearProjectError();
}
return defaultAudioDevice;
}
public static object GetDefaultAudioDeviceName()
{
object defaultAudioDeviceName;
try
{
MMDevice defaultAudioEndpoint = GetDevices.devenum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia);
defaultAudioDeviceName = (object) defaultAudioEndpoint.Properties[checked (defaultAudioEndpoint.Properties.Count - 3)].Value.ToString();
}
catch (Exception ex)
{
ProjectData.SetProjectError(ex);
Log.WriteToLog("GetDefaultAudioDeviceName: " + ex.Message);
defaultAudioDeviceName = (object) "";
ProjectData.ClearProjectError();
}
return defaultAudioDeviceName;
}
public static object GetDefaultAudioCommDevice()
{
object defaultAudioCommDevice;
try
{
defaultAudioCommDevice = (object) GetDevices.devenum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eCommunications).ID.ToString();
}
catch (Exception ex)
{
ProjectData.SetProjectError(ex);
Log.WriteToLog("GetDefaultAudioCommDevice: " + ex.Message);
defaultAudioCommDevice = (object) "";
ProjectData.ClearProjectError();
}
return defaultAudioCommDevice;
}
public static object GetDefaultAudioCommDeviceName()
{
object audioCommDeviceName;
try
{
MMDevice defaultAudioEndpoint = GetDevices.devenum.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eCommunications);
audioCommDeviceName = (object) defaultAudioEndpoint.Properties[checked (defaultAudioEndpoint.Properties.Count - 3)].Value.ToString();
}
catch (Exception ex)
{
ProjectData.SetProjectError(ex);
Log.WriteToLog("GetDefaultAudioCommDeviceName: " + ex.Message);
audioCommDeviceName = (object) "";
ProjectData.ClearProjectError();
}
return audioCommDeviceName;
}
public static object GetDefaultMicCommDevice()
{
object defaultMicCommDevice;
try
{
defaultMicCommDevice = (object) GetDevices.devenum.GetDefaultAudioEndpoint(EDataFlow.eCapture, ERole.eCommunications).ID.ToString();
}
catch (Exception ex)
{
ProjectData.SetProjectError(ex);
Log.WriteToLog("GetDefaultMiCommDevice: " + ex.Message);
defaultMicCommDevice = (object) "";
ProjectData.ClearProjectError();
}
return defaultMicCommDevice;
}
public static object GetDefaultMicCommDeviceName()
{
object micCommDeviceName;
try
{
MMDevice defaultAudioEndpoint = GetDevices.devenum.GetDefaultAudioEndpoint(EDataFlow.eCapture, ERole.eCommunications);
micCommDeviceName = (object) defaultAudioEndpoint.Properties[checked (defaultAudioEndpoint.Properties.Count - 3)].Value.ToString();
}
catch (Exception ex)
{
ProjectData.SetProjectError(ex);
Log.WriteToLog("GetDefaultMiCommDeviceName: " + ex.Message);
micCommDeviceName = (object) "";
ProjectData.ClearProjectError();
}
return micCommDeviceName;
}
}
}