-
Notifications
You must be signed in to change notification settings - Fork 8
/
MainWindow.xaml.cs
679 lines (611 loc) · 30.5 KB
/
MainWindow.xaml.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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
using ClubmanSharp.TrackData;
using Microsoft.Win32;
using Nefarius.ViGEm.Client.Targets.DualShock4;
using NuGet.Versioning;
using System;
using System.Diagnostics;
using System.Net.Http;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Navigation;
using System.IO;
using System.Linq;
using System.Net;
using System.Windows.Interop;
using System.Threading.Tasks;
using System.IO.Compression;
using System.Threading;
namespace ClubmanSharp
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
private bool isStarted = false;
private string ip = "192.168.1.30";
private readonly Bot bot;
private readonly Settings settings = Settings.Default;
private DateTime nextUpdate = DateTime.UtcNow;
private string specialDebugTxt = "";
private bool autoRetry = false;
private uint autoRetryCount = 0;
public SemanticVersion currentVersion = new(1, 2, 0);
public MainWindow()
{
DebugLog.Log($"Starting MainWindow initialization");
InitializeComponent();
CheckDebugLog.IsChecked = settings.debugLog > 0;
DebugLog.Log("Loaded MainWindow");
TxtHeader.Text = $"ClubmanSharp by ddm [v{currentVersion}]";
DebugLog.Log($"Version is {currentVersion}");
ip = settings.ip;
TxtIP.Text = ip;
DebugLog.Log($"Loaded IP from settings as {settings.ip}");
bot = new Bot();
DebugLog.Log($"Initialized Bot");
CustomDelayShort.Text = $"{settings.customShortDelay}";
DebugLog.Log($"Loaded customShortDelay from settings as {settings.customShortDelay}");
CustomDelayLong.Text = $"{settings.customLongDelay}";
DebugLog.Log($"Loaded customLongDelay from settings as {settings.customLongDelay}");
SliderThrottle.Value = Convert.ToDouble(settings.maxThrottle);
DebugLog.Log($"Loaded maxThrottle from settings as {settings.maxThrottle}");
switch (settings.delaySetting)
{
case 0:
RadioDelayPS4.IsChecked = true;
break;
case 1:
RadioDelayPS5.IsChecked = true;
break;
case 2:
RadioDelayCustom.IsChecked = true;
break;
}
DebugLog.Log($"Loaded delaySetting from settings as {settings.delaySetting}");
switch (settings.confirmButton)
{
case 0:
RadioConfirmCross.IsChecked = true;
autoRetry = false;
break;
case 1:
RadioConfirmCircle.IsChecked = true;
autoRetry = true;
break;
}
DebugLog.Log($"Loaded confirmButton from settings as {settings.confirmButton}");
switch (settings.autoRetry)
{
case 0:
RadioAutoRetryOff.IsChecked = true;
break;
case 1:
RadioAutoRetryOn.IsChecked = true;
break;
}
DebugLog.Log($"Loaded autoRetry from settings as {settings.autoRetry}");
// WRX data wasn't actually required after all
RadioCarGTO.IsChecked = true;
DebugLog.Log($"Set car to GTO (unused)");
CompositionTarget.Rendering += VisualLoop;
DebugLog.Log($"Added VisualLoop");
TxtDetails.Text = "WARNING: The latest version of PS Remote Play does not currently work with virtual controllers!\n" +
"If you do not already use a patched version of PS Remote Play, *CLOSE REMOTE PLAY* and then click the button below " +
"to get a version which will work with the bot.\n";
TxtShortHelp.Text = "Turn on a password requirement for PlayStation purchases before using any script.\n" +
"It is recommended to use HidHide to prevent the bot interacting with your desktop.\n\n" +
"You must start Remote Play with no controller connected to your PC.\n\n" +
"Enter your PS4/PS5's local IP address and hit Start while on the Tokyo Clubman+ pre-race menu.";
TxtLicensing.Text = "Developed with tunes and tips provided by Photon-Phoenix\n" +
"Using the GT7 SimInterface found & documented by Nenkai\n" +
"Special thanks to the PSNProfiles GT7 and GT Modding Community discord servers\n\n" +
"This project is licensed under the European Union Public License 1.2 (EUPL-1.2).\n" +
"This is a copyleft free/open-source software license. (This is not legal advice.)\n" +
"Full terms can be found at:\n https://github.com/ddm999/ClubmanSharp/blob/main/LICENSE\n\n" +
"This project uses https://github.com/Nenkai/PDTools, licensed under the MIT license.\n" +
"Full terms can be found at:\n https://github.com/Nenkai/PDTools/blob/master/LICENSE\n\n" +
"This project uses https://github.com/ViGEm/ViGEm.NET, licensed under the MIT license.\n" +
"Full terms can be found at:\n https://github.com/ViGEm/ViGEm.NET/blob/master/LICENSE\n\n" +
"All developers of this project are not affiliated with Polyphony Digital or Sony Interactive Entertainment.";
UpdateCheck();
if (DebugLog.isActive)
{
MessageBox.Show("You have the debug.log setting enabled!\n" +
"This option WILL make a huge log file if you leave it on all the time & don't delete the log every now and again.\n" +
"Turn it off unless you really need someone to verify what's happening with the bot!",
"ClubmanSharp Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
DebugLog.Log("Warning user of debug log setting");
}
DebugLog.Log($"Finished MainWindow initialization");
}
public void TooMuchStuckDetectionCheck()
{
DebugLog.Log($"Starting TooMuchStuckDetectionCheck");
if (bot is null)
return;
if (bot.completedRaces >= 2 && (bot.stuckDetectionRuns >= (bot.completedRaces*0.05)))
{
string msg = "That last run had a lot of stuck detection attempts, which usually means your delays are too short.\n\n";
if (RadioDelayCustom.IsChecked is true)
msg += "Try switching back to the defaults, or increasing your custom delays.";
else if (RadioDelayPS5.IsChecked is true)
msg += "Try using the PS4 delays.";
else
msg += "Try using large custom delays, or increasing your network stability if possible.";
MessageBox.Show(msg, "ClubmanSharp Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
DebugLog.Log($"Warning: {msg}");
}
DebugLog.Log($"Finished TooMuchStuckDetectionCheck");
}
public async void UpdateCheck()
{
DebugLog.Log($"Started UpdateCheck");
try
{
using var client = new HttpClient();
string serverResult = await client.GetStringAsync("http://gt-mod.site/ClubmanSharpVersion.txt");
SemanticVersionConverter converter = new();
SemanticVersion serverVersion = (SemanticVersion)converter.ConvertFromString(serverResult);
if (serverVersion > currentVersion)
{
TxtSrcLink.Visibility = Visibility.Hidden;
TxtUpdateLink.Visibility = Visibility.Visible;
MessageBox.Show("A new version of ClubmanSharp is available to download.\n" +
"You may have issues using this out-of-date version.\n" +
"Download the latest version at https://github.com/ddm999/ClubmanSharp/releases\n" +
"(A link is available at the bottom of the Startup menu.)", "ClubmanSharp Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
DebugLog.Log($"Warning: serverVersion > currentVersion");
}
}
catch (Exception ex)
{
MessageBox.Show($"Failed to check for updates.\nException details below:\n\n{ex.Message}", "ClubmanSharp Error", MessageBoxButton.OK, MessageBoxImage.Error);
DebugLog.Log($"Error: UpdateCheck failed.\n{ex.Message}");
}
DebugLog.Log($"Finished UpdateCheck");
}
public void VisualLoop(object? sender, EventArgs? e)
{
if (bot.error is true)
{
DebugLog.Log($"Error: bot.error\n{bot.errorMsg}");
bool retriableError = bot.errorMsg.Contains("packet") || bot.errorMsg.Contains("Unexpected error");
if (!(autoRetry && retriableError))
{
MessageBox.Show(bot.errorMsg, "ClubmanSharp Error (in bot)", MessageBoxButton.OK, MessageBoxImage.Error);
}
bot.error = false;
bot.Stop();
isStarted = false;
TooMuchStuckDetectionCheck();
BtnStartStop.Content = "Start";
TxtIP.IsEnabled = true;
BtnStartStop.IsEnabled = true;
if (autoRetry && retriableError)
{
DebugLog.Log($"AutoRetry: Error is retriable");
Thread.Sleep(3000);
autoRetryCount++;
StartStop_Click(null, null);
DebugLog.Log($"AutoRetry: Clicked the Start button");
}
}
// don't update text constantly because it actually uses an unnecessary chunk of GPU lol
if (nextUpdate > DateTime.UtcNow)
{
return;
}
nextUpdate = DateTime.UtcNow + new TimeSpan(1000000);
TxtState.Text = "Current State: ";
if (bot.currentMenuState == Bot.MenuState.Unknown)
TxtState.Text += "Unknown";
else if (bot.currentMenuState == Bot.MenuState.Race)
TxtState.Text += "Race";
else if (bot.currentMenuState == Bot.MenuState.RacePaused)
TxtState.Text += "Race Paused";
else if (bot.currentMenuState == Bot.MenuState.RaceStart)
TxtState.Text += "Race Start";
else if (bot.currentMenuState == Bot.MenuState.PreRace)
TxtState.Text += "Pre Race";
else if (bot.currentMenuState == Bot.MenuState.RaceResult)
TxtState.Text += "Race Result";
else if (bot.currentMenuState == Bot.MenuState.Replay)
TxtState.Text += "Replay";
else if (bot.currentMenuState == Bot.MenuState.PostRace)
TxtState.Text += "Post Race";
else if (bot.currentMenuState == Bot.MenuState.Stuck_PreOrPostRace)
TxtState.Text += "Stk Unknown";
else if (bot.currentMenuState == Bot.MenuState.Stuck_Replay)
TxtState.Text += "Stk Replay";
else if (bot.currentMenuState == Bot.MenuState.Stuck_PostRace)
TxtState.Text += "Stk Post Race";
else if (bot.currentMenuState == Bot.MenuState.Stuck_PreRace)
TxtState.Text += "Stk Pre Race";
TxtLap.Text = $"Fastest Lap: {bot.fastestLap.Minutes:d1}:{bot.fastestLap.Seconds:d2}.{bot.fastestLap.Milliseconds:d3}";
TxtRaces.Text = $"Completed Races: {bot.completedRaces}";
TxtCredits.Text = $"Estimated Credits: {bot.completedRaces * 105000 * 0.98:n0}";
if (tabControl.SelectedItem == debugTabItem)
{
TxtDebug.Text = "Bot information:\n";
TxtDebug.Text += $"error: {bot.error} ";
TxtDebug.Text += $"connected: {bot.connected} ";
TxtDebug.Text += $"autoRetries: {autoRetryCount} ";
TxtDebug.Text += $"stuckDetectRuns: {bot.stuckDetectionRuns}\n";
TxtDebug.Text += $"Controller: {bot.buttonString}\n";
if (bot.currentPacket != null)
{
TxtDebug.Text += "\nPacket information:\n";
TxtDebug.Text += $"DateReceived: {bot.currentPacket.DateReceived}\n";
TxtDebug.Text += $"CarCode: {bot.currentPacket.CarCode}\n";
TxtDebug.Text += $"NumCarsAtPreRace: {bot.currentPacket.NumCarsAtPreRace}\n";
TxtDebug.Text += $"CurrentGear: {bot.currentPacket.CurrentGear} ";
TxtDebug.Text += $"EngineRPM: {bot.currentPacket.EngineRPM} ";
TxtDebug.Text += $"MetersPerSecond: {bot.currentPacket.MetersPerSecond}\n";
TxtDebug.Text += $"LapCount: {bot.currentPacket.LapCount} ";
TxtDebug.Text += $"LapsInRace: {bot.currentPacket.LapsInRace}\n";
TxtDebug.Text += $"BestLapTime: {bot.currentPacket.BestLapTime} ";
TxtDebug.Text += $"LastLapTime: {bot.currentPacket.LastLapTime}\n";
TxtDebug.Text += $"RelativeOrientationToNorth: {bot.currentPacket.RelativeOrientationToNorth}\n";
TxtDebug.Text += $"Position: {bot.currentPacket.Position}\n";
TxtDebug.Text += $"Rotation: {bot.currentPacket.Rotation}\n";
TxtDebug.Text += $"Velocity: {bot.currentPacket.Velocity}\n";
}
if (bot.currentTrackData != null)
{
TxtDebug.Text += "\nTrack information:\n";
TxtDebug.Text += $"useInitialSegments: {bot.currentTrackData.useInitialSegments} ";
TxtDebug.Text += $"segmentNum: {bot.currentTrackData.segmentNum} ";
TxtDebug.Text += $"pitboxCounter: {bot.currentTrackData.pitboxCounter}\n";
}
TxtDebug.Text += specialDebugTxt;
}
}
private void StartStop_Click(object sender, RoutedEventArgs e)
{
DebugLog.Log($"Started StartStop_Click");
TxtIP.IsEnabled = false;
BtnStartStop.IsEnabled = false;
ip = TxtIP.Text;
isStarted = !isStarted;
if (isStarted)
{
BtnStartStop.Content = "Starting...";
bot.Start(ip);
if (bot.error is true)
{
bot.Stop();
MessageBox.Show(bot.errorMsg, "ClubmanSharp Error (starting bot)", MessageBoxButton.OK, MessageBoxImage.Error);
DebugLog.Log($"Error: bot.error\n{bot.errorMsg}");
bot.error = false;
BtnStartStop.Content = "Start";
TxtIP.IsEnabled = true;
BtnStartStop.IsEnabled = true;
return;
}
BtnStartStop.Content = "Stop";
BtnStartStop.IsEnabled = true;
}
else
{
bot.Stop();
TooMuchStuckDetectionCheck();
BtnStartStop.Content = "Start";
TxtIP.IsEnabled = true;
BtnStartStop.IsEnabled = true;
}
DebugLog.Log($"Finished StartStop_Click");
}
private void Hyperlink_Click(object sender, RequestNavigateEventArgs e)
{
DebugLog.Log($"Started Hyperlink_Click");
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri) { UseShellExecute = true });
e.Handled = true;
DebugLog.Log($"Finished Hyperlink_Click");
}
private void RadioDelayPS4_Checked(object sender, RoutedEventArgs e)
{
DebugLog.Log($"Started RadioDelayPS4_Checked");
if (bot is null)
return;
CustomDelayShort.Text = "250";
CustomDelayLong.Text = "3000";
bot.ShortDelay = 250;
bot.LongDelay = 3000;
CustomDelayShort.IsEnabled = false;
CustomDelayLong.IsEnabled = false;
RadioDelayPS5.IsChecked = false;
RadioDelayCustom.IsChecked = false;
settings.delaySetting = 0;
settings.Save();
DebugLog.Log($"Finished RadioDelayPS4_Checked");
}
private void RadioDelayPS5_Checked(object sender, RoutedEventArgs e)
{
DebugLog.Log($"Started RadioDelayPS5_Checked");
CustomDelayShort.Text = "250";
CustomDelayLong.Text = "1000";
bot.ShortDelay = 250;
bot.LongDelay = 1000;
CustomDelayShort.IsEnabled = false;
CustomDelayLong.IsEnabled = false;
RadioDelayPS4.IsChecked = false;
RadioDelayCustom.IsChecked = false;
settings.delaySetting = 1;
settings.Save();
DebugLog.Log($"Finished RadioDelayPS5_Checked");
}
private void RadioDelayCustom_Checked(object sender, RoutedEventArgs e)
{
DebugLog.Log($"Started RadioDelayCustom_Checked");
bot.ShortDelay = int.Parse(CustomDelayShort.Text);
bot.LongDelay = int.Parse(CustomDelayLong.Text);
CustomDelayShort.IsEnabled = true;
CustomDelayLong.IsEnabled = true;
RadioDelayPS4.IsChecked = false;
RadioDelayPS5.IsChecked = false;
settings.delaySetting = 2;
settings.Save();
DebugLog.Log($"Finished RadioDelayCustom_Checked");
}
private void TxtIP_TextChanged(object sender, TextChangedEventArgs e)
{
DebugLog.Log($"Started TxtIP_TextChanged");
DebugLog.Log($"TxtIP is {TxtIP.Text}");
if (TxtIP.Text == "x")
return;
ip = TxtIP.Text;
settings.ip = ip;
settings.Save();
DebugLog.Log($"Finished TxtIP_TextChanged");
}
private void CustomDelayShort_TextChanged(object sender, TextChangedEventArgs e)
{
DebugLog.Log($"Started CustomDelayShort_TextChanged");
DebugLog.Log($"CustomDelayShort is {CustomDelayShort.Text}");
if (bot is null)
return;
bool success = int.TryParse(CustomDelayShort.Text, out int number);
if (success)
{
bot.ShortDelay = number;
settings.customShortDelay = number;
settings.Save();
}
else
{
DebugLog.Log($"Error: CustomDelayShort invalid");
MessageBox.Show($"Invalid delay of {CustomDelayShort.Text}", "ClubmanSharp Error", MessageBoxButton.OK, MessageBoxImage.Error);
CustomDelayShort.Text = $"{bot.ShortDelay}";
}
DebugLog.Log($"Finished CustomDelayShort_TextChanged");
}
private void CustomDelayLong_TextChanged(object sender, TextChangedEventArgs e)
{
DebugLog.Log($"Started CustomDelayLong_TextChanged");
DebugLog.Log($"CustomDelayLong is {CustomDelayLong.Text}");
if (bot is null)
return;
bool success = int.TryParse(CustomDelayLong.Text, out int number);
if (success)
{
bot.LongDelay = number;
settings.customLongDelay = number;
settings.Save();
}
else
{
DebugLog.Log($"Error: CustomDelayShort invalid");
MessageBox.Show($"Invalid delay of {CustomDelayLong.Text}", "ClubmanSharp Error", MessageBoxButton.OK, MessageBoxImage.Error);
CustomDelayLong.Text = $"{bot.LongDelay}";
}
DebugLog.Log($"Finished CustomDelayLong_TextChanged");
}
private void RadioCarGTO_Checked(object sender, RoutedEventArgs e)
{
DebugLog.Log($"Started RadioCarGTO_Checked");
if (bot is null)
return;
bot.currentTrackData = new GTOTrackData();
RadioCarWRX.IsChecked = false;
settings.carSetting = 0;
settings.Save();
DebugLog.Log($"Finished RadioCarGTO_Checked");
}
private void RadioCarWRX_Checked(object sender, RoutedEventArgs e)
{
DebugLog.Log($"Started RadioCarWRX_Checked");
/*if (bot is null)
return;
bot.currentTrackData = new WRXTrackData();
RadioCarGTO.IsChecked = false;
settings.carSetting = 1;
settings.Save();*/
DebugLog.Log($"Finished RadioCarWRX_Checked");
}
private void SliderThrottle_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
DebugLog.Log($"Started SliderThrottle_ValueChanged");
DebugLog.Log($"SliderThrottle is {SliderThrottle.Value}");
byte byteVal = Convert.ToByte(SliderThrottle.Value);
SliderThrottle.ToolTip = $"{byteVal}/255";
TxtThrottleValue.Text = $"{byteVal}";
if (bot is null)
return;
bot.LateRaceMaxThrottle = byteVal;
settings.maxThrottle = byteVal;
settings.Save();
DebugLog.Log($"Finished SliderThrottle_ValueChanged");
}
private void RadioConfirmCross_Checked(object sender, RoutedEventArgs e)
{
DebugLog.Log($"Started RadioConfirmCross_Checked");
if (bot is null)
return;
bot.confirmButton = DualShock4Button.Cross;
bot.cancelButton = DualShock4Button.Circle;
RadioConfirmCircle.IsChecked = false;
settings.confirmButton = 0;
settings.Save();
DebugLog.Log($"Finished RadioConfirmCross_Checked");
}
private void RadioConfirmCircle_Checked(object sender, RoutedEventArgs e)
{
DebugLog.Log($"Started RadioConfirmCircle_Checked");
if (bot is null)
return;
bot.confirmButton = DualShock4Button.Circle;
bot.cancelButton = DualShock4Button.Cross;
RadioConfirmCross.IsChecked = false;
settings.confirmButton = 1;
settings.Save();
DebugLog.Log($"Finished RadioConfirmCircle_Checked");
}
private void RadioAutoRetryOff_Checked(object sender, RoutedEventArgs e)
{
DebugLog.Log($"Started RadioAutoRetryOff_Checked");
RadioAutoRetryOn.IsChecked = false;
autoRetry = false;
settings.autoRetry = 0;
settings.Save();
DebugLog.Log($"Finished RadioAutoRetryOff_Checked");
}
private void RadioAutoRetryOn_Checked(object sender, RoutedEventArgs e)
{
DebugLog.Log($"Started RadioAutoRetryOn_Checked");
RadioAutoRetryOff.IsChecked = false;
autoRetry = true;
settings.autoRetry = 1;
settings.Save();
DebugLog.Log($"Finished RadioAutoRetryOn_Checked");
}
private void CheckDebugLog_Checked(object sender, RoutedEventArgs e)
{
DebugLog.Log($"Started CheckDebugLog_Checked");
DebugLog.SetActive(true);
settings.debugLog = 1;
settings.Save();
DebugLog.Log($"Finished CheckDebugLog_Checked");
}
private void CheckDebugLog_Unchecked(object sender, RoutedEventArgs e)
{
DebugLog.Log($"Started CheckDebugLog_Unchecked");
DebugLog.SetActive(false);
settings.debugLog = 0;
settings.Save();
DebugLog.Log($"Finished CheckDebugLog_Unchecked");
}
/*
* The following function is from https://github.com/xeropresence/remoteplay-version-patcher
*/
private static string? FindRemotePlay()
{
DebugLog.Log($"Started FindRemotePlay (nofin)");
DebugLog.Log($"Environment.Is64BitOperatingSystem {Environment.Is64BitOperatingSystem}");
var baseKey = Environment.Is64BitOperatingSystem ?
@"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\" :
@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\";
using (var keys = Registry.LocalMachine.OpenSubKey(baseKey))
{
var remotePlayKey = keys?.GetSubKeyNames()
.Select(name => keys.OpenSubKey(name))
.FirstOrDefault(key => key.GetValue("DisplayName", "").ToString().Contains("PS Remote Play") &&
key.GetValue("Publisher", "").ToString().Contains("Sony"));
DebugLog.Log($"remotePlayKey {remotePlayKey}");
var path = remotePlayKey?.GetValue("InstallLocation", null)?.ToString() ?? string.Empty;
DebugLog.Log($"path {path}");
return Directory.Exists(path) ? path : null;
}
}
public async Task DownloadPatchedRemotePlay(string path)
{
DebugLog.Log($"Started DownloadPatchedRemotePlay");
using var client = new HttpClient();
using var stream = await client.GetStreamAsync("http://gt-mod.site/PS_Remote_Play_v550_patch.zip");
using var fileStream = new FileStream(path, FileMode.Create);
stream.CopyTo(fileStream);
fileStream.Close();
DebugLog.Log($"Finished DownloadPatchedRemotePlay");
}
private async void BtnPatchedRemotePlay_Click(object sender, RoutedEventArgs e)
{
DebugLog.Log($"Started BtnPatchedRemotePlay_Click");
string? outpath = FindRemotePlay();
DebugLog.Log($"Directory.GetCurrentDirectory {Directory.GetCurrentDirectory()}");
string dlpath = Path.Combine(Directory.GetCurrentDirectory(), "PS_Remote_Play_v550_patch.zip");
string extractpath = Path.Combine(Directory.GetCurrentDirectory(), "PS_Remote_Play_v550_patch");
// delete if exists, fine if this fails
DebugLog.Log($"Deleting existing download files");
try { File.Delete(dlpath); } catch (Exception) { DebugLog.Log($"Failed to delete download path (OK!)"); }
try { Directory.Delete(extractpath, true); } catch (Exception) { DebugLog.Log($"Failed to delete extract path (OK!)"); }
await DownloadPatchedRemotePlay(dlpath);
DebugLog.Log($"Extracting downloaded zip");
ZipFile.ExtractToDirectory(dlpath, extractpath);
if (
outpath != null &&
File.Exists(Path.Combine(extractpath, "RemotePlay.exe")) &&
File.Exists(Path.Combine(outpath, "RemotePlay.exe")) &&
File.Exists(Path.Combine(extractpath, "RpCtrlWrapper.dll")) &&
File.Exists(Path.Combine(outpath, "RpCtrlWrapper.dll"))
)
{
DebugLog.Log($"Info: Patch install");
MessageBox.Show("ClubmanSharp will now install the patch for Remote Play.\n"+
"You may need to accept a 'Windows Command Processor' UAC prompt that will appear after this box.",
"ClubmanSharp Information", MessageBoxButton.OK, MessageBoxImage.Information);
DebugLog.Log($"Initializing RemotePlay.exe install process");
Process process = new();
ProcessStartInfo startInfo = new()
{
WindowStyle = ProcessWindowStyle.Hidden,
FileName = "cmd.exe",
Arguments = $"/C move \"{Path.Combine(extractpath, "RemotePlay.exe")}\" \"{outpath}\"",
Verb = "runas",
UseShellExecute = true
};
process.StartInfo = startInfo;
DebugLog.Log($"Starting RemotePlay.exe install process");
process.Start();
DebugLog.Log($"Initializing RpCtrlWrapper.dll install process");
Process process2 = new();
ProcessStartInfo startInfo2 = new()
{
WindowStyle = ProcessWindowStyle.Hidden,
FileName = "cmd.exe",
Arguments = $"/C move \"{Path.Combine(extractpath, "RpCtrlWrapper.dll")}\" \"{outpath}\"",
Verb = "runas",
UseShellExecute = true
};
process2.StartInfo = startInfo2;
DebugLog.Log($"Starting RpCtrlWrapper.dll install process");
process2.Start();
DebugLog.Log($"Deleting download & extract files");
try
{
File.Delete(dlpath);
Directory.Delete(extractpath);
}
// ignore delete fails, it probably failed for a reason and might help the user if the files are left
catch (Exception)
{
DebugLog.Log($"Failed to delete download & extract files (OK!)");
}
MessageBox.Show("This should have successfully patched Remote Play.\n"+
"Launch Remote Play as normal and see if it works.\n\n"+
"If it doesn't, try this process again, making sure that Remote Play is fully closed.\n"+
"If you can't get it working, you can request help in the GitHub issues.",
"ClubmanSharp Information", MessageBoxButton.OK, MessageBoxImage.Information);
DebugLog.Log($"Info: Patch probably succeeded");
}
else
{
MessageBox.Show("Failed to find current Remote Play installation:\n"+
"you can manually patch using the downloaded files left next to ClubmanSharp.",
"ClubmanSharp Information", MessageBoxButton.OK, MessageBoxImage.Information);
DebugLog.Log($"Info: Locating Remote Play install failed");
}
DebugLog.Log($"Finished BtnPatchedRemotePlay_Click");
}
}
}