-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
404 lines (374 loc) · 18.3 KB
/
Program.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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
namespace OculusKillSwitch;
using System;
using System.IO;
using System.Security.Cryptography;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Net;
using IniParser;
using IniParser.Model;
using Ookii.Dialogs.Wpf;
using IWshRuntimeLibrary;
using Mayerch1.GithubUpdateCheck;
using ThankYouReza;
static class Program
{
// #### Get Current Version ####
public static string getVersion()
{
var version = Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion;
version = version.Split("+").First();
return version;
}
// #### Credit to @ndepoel ####
static DirectoryInfo GetOculusBaseDirectory()
{
string OculusBaseVarName = @"OculusBase";
string OculusBasePath = Environment.GetEnvironmentVariable(OculusBaseVarName);
if (OculusBasePath == null)
return null;
return Directory.Exists(OculusBasePath) ? new DirectoryInfo(OculusBasePath) : null;
}
static string GetMD5Hash(string filePath)
{
using (var fileStream = new FileStream(filePath,
FileMode.Open,
FileAccess.Read,
FileShare.ReadWrite))
{
byte[] hash = System.IO.File.ReadAllBytes(filePath);
byte[] hashValue = MD5.HashData(hash);
return Convert.ToHexString(hashValue);
}
}
static void MakeShortcut()
{
var parser = new FileIniDataParser();
IniData configdata = parser.ReadFile("OculusKillSwitch.ini");
var desktopFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var shell = new WshShell();
var shortCutLinkFilePath = desktopFolderPath + "\\Oculus Kill Switch.lnk";
string[] fileArray = Directory.GetFiles(desktopFolderPath);
List<string> fileHashList = new();
try
{
if (configdata["OculusKillSwitch"]["DontShowShortcutDialog"] != "true")
{
using (TaskDialog dialog = new TaskDialog())
{
TaskDialogButton butYes = new TaskDialogButton(ButtonType.Yes);
TaskDialogButton butNo = new TaskDialogButton(ButtonType.No);
dialog.WindowTitle = "Oculus Kill Switch";
dialog.Content = "Do you want me to make a desktop shortcut?";
dialog.MainIcon = TaskDialogIcon.Custom;
dialog.CustomMainIcon = Icon.FromHandle(NM.GetModernIcon("SIID_HELP"));
dialog.VerificationText = "Don't Show Again";
dialog.Buttons.Add(butYes);
dialog.Buttons.Add(butNo);
dialog.CenterParent = false;
TaskDialogButton result = dialog.ShowDialog();
if (dialog.IsVerificationChecked && result == butNo)
{
configdata["OculusKillSwitch"]["DontShowShortcutDialog"] = "true";
parser.WriteFile("OculusKillSwitch.ini", configdata);
}
if (result == butYes)
{
configdata["OculusKillSwitch"]["DontShowShortcutDialog"] = "true";
var windowsApplicationShortcut = (IWshShortcut)shell.CreateShortcut(shortCutLinkFilePath);
windowsApplicationShortcut.Description = "Toggle Oculus Killer and play your Oculus games.";
windowsApplicationShortcut.WorkingDirectory = Application.StartupPath;
windowsApplicationShortcut.TargetPath = Application.ExecutablePath;
windowsApplicationShortcut.Save();
parser.WriteFile("OculusKillSwitch.ini", configdata);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
Application.Exit();
}
}
//Got lazy
static void MakeShortcutStartMenu()
{
var parser = new FileIniDataParser();
IniData configdata = parser.ReadFile("OculusKillSwitch.ini");
var startFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu), "Programs");
var shell = new WshShell();
var shortCutLinkFilePath = startFolderPath + "\\Oculus Kill Switch.lnk";
string[] fileArray = Directory.GetFiles(startFolderPath);
List<string> fileHashList = new();
try
{
if (configdata["OculusKillSwitch"]["DontShowStartShortcutDialog"] != "true")
{
using (TaskDialog dialog = new TaskDialog())
{
TaskDialogButton butYes = new TaskDialogButton(ButtonType.Yes);
TaskDialogButton butNo = new TaskDialogButton(ButtonType.No);
dialog.WindowTitle = "Oculus Kill Switch";
dialog.Content = "Do you want me to make a start menu shortcut?\n(You'll need to remove the shortcut manually.)";
dialog.MainIcon = TaskDialogIcon.Custom;
dialog.CustomMainIcon = Icon.FromHandle(NM.GetModernIcon("SIID_HELP"));
dialog.VerificationText = "Don't Show Again";
dialog.Buttons.Add(butYes);
dialog.Buttons.Add(butNo);
dialog.CenterParent = false;
TaskDialogButton result = dialog.ShowDialog();
if (dialog.IsVerificationChecked && result == butNo)
{
configdata["OculusKillSwitch"]["DontShowStartShortcutDialog"] = "true";
parser.WriteFile("OculusKillSwitch.ini", configdata);
}
if (result == butYes)
{
configdata["OculusKillSwitch"]["DontShowStartShortcutDialog"] = "true";
var windowsApplicationShortcut = (IWshShortcut)shell.CreateShortcut(shortCutLinkFilePath);
windowsApplicationShortcut.Description = "Toggle Oculus Killer and play your Oculus games.";
windowsApplicationShortcut.WorkingDirectory = Application.StartupPath;
windowsApplicationShortcut.TargetPath = Application.ExecutablePath;
windowsApplicationShortcut.Save();
parser.WriteFile("OculusKillSwitch.ini", configdata);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
Application.Exit();
}
}
static void CheckConfig()
{
if (System.IO.Directory.Exists("..\\..\\..\\oculus-dash") == false)
{
try
{
Process.Start("explorer.exe", GetOculusBaseDirectory().FullName + "Support\\oculus-dash\\dash\\bin");
DialogResult nuhuhbox = MessageBox.Show("I'm not in the right directory, I go here.\nAfter I close, would you please move me?", "Oculus Kill Switch", MessageBoxButtons.OK, MessageBoxIcon.Warning);
if (nuhuhbox == DialogResult.OK)
{
Console.WriteLine("WRONG LOCATION/DASH NOT PRESENT");
Application.Exit();
}
}
catch (Exception x)
{
Process.Start("explorer.exe", @"https://www.oculus.com/download_app/?id=1582076955407037");
DialogResult Dialog1 = MessageBox.Show("Looks like you've never installed the Oculus Software, please install Oculus Software before using this program, ya goof.", "Oculus Kill Switch", MessageBoxButtons.OK);
if (Dialog1 == DialogResult.OK)
{
Console.WriteLine(x);
Console.WriteLine("NOT INSTALLED AT ALL???");
Application.Exit();
}
}
}
else
{
if (System.IO.File.Exists("OculusKillSwitch.ini") != true)
{
System.IO.File.Create("OculusKillSwitch.ini").Close();
}
var parser = new FileIniDataParser();
IniData configdata = parser.ReadFile("OculusKillSwitch.ini");
if (new FileInfo("OculusKillSwitch.ini").Length == 0)
{
configdata["OculusKillSwitch"]["IgnoreOculusClientOpen"] = "false";
configdata["OculusKillSwitch"]["DontShowShortcutDialog"] = "false";
configdata["OculusKillSwitch"]["IgnoreUpdate"] = "false";
parser.WriteFile("OculusKillSwitch.ini", configdata);
}
}
}
static void CheckForUpdate()
{
var parser = new FileIniDataParser();
IniData configdata = parser.ReadFile("OculusKillSwitch.ini");
var startupFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var shell = new WshShell();
var shortCutLinkFilePath = startupFolderPath + "\\Oculus Kill Switch.lnk";
string[] fileArray = Directory.GetFiles(startupFolderPath);
GithubUpdateCheck update = new GithubUpdateCheck("kckarnige", "OculusKillSwitch");
bool isUpdate = update.IsUpdateAvailable(getVersion(), VersionChange.Revision);
if (isUpdate && configdata["OculusKillSwitch"]["IgnoreUpdate"] != "true")
{
using (TaskDialog dialog = new TaskDialog())
{
TaskDialogButton butYes = new TaskDialogButton(ButtonType.Yes);
TaskDialogButton butNo = new TaskDialogButton(ButtonType.No);
dialog.WindowTitle = "Oculus Kill Switch";
dialog.Content = "Looks like there's a new update, wanna check it out?";
dialog.MainIcon = TaskDialogIcon.Information;
dialog.VerificationText = "Don't Show Again";
dialog.Buttons.Add(butYes);
dialog.Buttons.Add(butNo);
dialog.CenterParent = false;
TaskDialogButton result = dialog.ShowDialog();
if (dialog.IsVerificationChecked && result == butNo)
{
configdata["OculusKillSwitch"]["IgnoreUpdate"] = "true";
parser.WriteFile("OculusKillSwitch.ini", configdata);
}
if (result == butYes)
{
Process.Start("explorer.exe", @"https://github.com/kckarnige/OculusKillSwitch");
Application.Exit();
}
}
}
}
static void Main()
{
CheckConfig();
Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
CheckForUpdate();
Process[] DashCheck = Process.GetProcessesByName("OculusDash");
Process[] SteamVRCheck = Process.GetProcessesByName("vrmonitor");
Process[] OculusAppCheck = Process.GetProcessesByName("OculusClient");
var parser = new FileIniDataParser();
IniData configdata = parser.ReadFile("OculusKillSwitch.ini");
if (DashCheck.Length > 0 != true && SteamVRCheck.Length > 0 != true)
{
string activeFileHash;
string backupFileHash;
bool whoops = false;
try
{
activeFileHash = GetMD5Hash("OculusDash.exe");
configdata["OculusKillSwitch"]["OculusDashExecHash"] = activeFileHash;
parser.WriteFile("OculusKillSwitch.ini", configdata);
MakeShortcutStartMenu();
MakeShortcut();
try
{
System.IO.File.Exists("OculusDash.exe.bak");
backupFileHash = GetMD5Hash("OculusDash.exe.bak");
}
catch (Exception)
{
if (activeFileHash == "9DB7CC8B646A01C60859B318F85E65D0")
{
MessageBox.Show("Oculus Dash backup couldn't be found. If it's in a different directory, move it here. If you don't have it, you may need to reinstall the Oculus app to get it back.", "Oculus Kill Switch", MessageBoxButtons.OK, MessageBoxIcon.Error);
whoops = true;
Console.WriteLine("NO BACKUP");
}
else if (activeFileHash == configdata["OculusKillSwitch"]["OculusDashExecHash"])
{
DialogResult Dialog1 = MessageBox.Show("Oculus Killer isn't installed, or the backup file has been renamed. Would you like for me to download it for you?", "Oculus Kill Switch", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (Dialog1 == DialogResult.Yes)
{
using (WebClient client = new WebClient())
{
client.DownloadFile("https://github.com/irlbunny/OculusKiller/releases/latest/download/OculusDash.exe", "OculusDash.exe.bak");
}
}
else
{
MessageBox.Show("Oculus Killer needs to be installed for me to do my job.", "Oculus Kill Switch", MessageBoxButtons.OK, MessageBoxIcon.Error);
whoops = true;
Console.WriteLine("NO KILLER");
Application.Exit();
}
}
else
{
DialogResult Dialog1 = MessageBox.Show("Looks like the Oculus Client updated since this was last ran, give me a sec to update the stored hash value for the Oculus Client.", "Oculus Kill Switch", MessageBoxButtons.OK);
if (Dialog1 == DialogResult.OK)
{
configdata["OculusKillSwitch"]["OculusDashExecHash"] = GetMD5Hash("OculusDash.exe");
parser.WriteFile("OculusKillSwitch.ini", configdata);
}
else
{
whoops = true;
Console.WriteLine("SHOULDA PRESSED OK");
Application.Exit();
}
}
}
}
catch (Exception ex)
{
activeFileHash = "null";
Console.WriteLine(ex);
whoops = true;
Console.WriteLine("WRONG LOCATION/DASH NOT PRESENT");
}
if (OculusAppCheck.Length > 0 == true && configdata["OculusKillSwitch"]["IgnoreOculusClientOpen"] != "true" && whoops == false)
{
using (TaskDialog dialog = new TaskDialog())
{
TaskDialogButton butOK = new TaskDialogButton(ButtonType.Ok);
TaskDialogButton butCancel = new TaskDialogButton(ButtonType.Cancel);
dialog.VerificationText = "Don't Show Again";
dialog.WindowTitle = "Oculus Kill Switch";
dialog.Content = "For safety reasons, I'm here to warn you of switching while in VR because I can't detect anything but the Oculus Client being open.\n\nIf you just took off your headset to switch, please make sure to save your game before either closing or restarting (Recommended) the Oculus app.\nIf all you did was open the Oculus app, you may continue, otherwise, click 'Cancel' to close this prompt and come back after you saved your progress.";
dialog.MainIcon = TaskDialogIcon.Warning;
dialog.Buttons.Add(butOK);
dialog.Buttons.Add(butCancel);
dialog.CenterParent = false;
TaskDialogButton result = dialog.ShowDialog();
if (dialog.IsVerificationChecked)
{
configdata["OculusKillSwitch"]["IgnoreOculusClientOpen"] = "true";
parser.WriteFile("OculusKillSwitch.ini", configdata);
}
if (result == butCancel)
{
whoops = true;
Console.WriteLine("WARNING ACKNOWLEDGED");
Application.Exit();
}
}
}
string killerEnabled;
if (activeFileHash == "9DB7CC8B646A01C60859B318F85E65D0")
{
killerEnabled = "enabled.";
}
else
{
killerEnabled = "disabled.";
};
DialogResult Dialog0;
if (whoops == false)
{
Dialog0 = MessageBox.Show("Toggle Oculus Killer?\n" + "It's currently " + killerEnabled, "Oculus Kill Switch", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
}
else
{
Dialog0 = DialogResult.None;
}
// It'll be fiiiiiine
if (Dialog0 == DialogResult.OK)
{
if (activeFileHash != "9DB7CC8B646A01C60859B318F85E65D0")
{
// Stock -> Default
System.IO.File.Move("OculusDash.exe.bak", "tempkill.exe");
System.IO.File.Move("OculusDash.exe", "OculusDash.exe.bak");
System.IO.File.Move("tempkill.exe", "OculusDash.exe");
MessageBox.Show("Successfully enabled Oculus Killer!", "Oculus Kill Switch", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
// Killer -> Stock
System.IO.File.Move("OculusDash.exe.bak", "tempbak.exe");
System.IO.File.Move("OculusDash.exe", "OculusDash.exe.bak");
System.IO.File.Move("tempbak.exe", "OculusDash.exe");
MessageBox.Show("Successfully disabled Oculus Killer!", "Oculus Kill Switch", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
else
{
MessageBox.Show("Please exit VR before switching your dash.\nIf this issue persists, try restarting the Oculus app.\nSettings > Beta > Restart Oculus", "Oculus Kill Switch", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}