This repository was archived by the owner on May 9, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
1509 lines (1331 loc) · 52.9 KB
/
Copy pathProgram.cs
File metadata and controls
1509 lines (1331 loc) · 52.9 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
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
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System.Diagnostics;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using Microsoft.Win32;
namespace Sm0k3r;
enum SteamToolsStatus { UpToDate, UpToDateCloudFixed, Outdated, NotInstalled, Unknown }
class Program
{
const string FallbackVersion = "1773426488";
const int FileServerPort = 1666;
const string FallbackManifestUrl = "https://raw.githubusercontent.com/SteamDatabase/SteamTracking/master/ClientManifest/steam_client_win64";
const string ManifestFileName = "steam_client_win64";
static RemoteConfig? _remoteConfig;
static readonly HttpClient _http = new() { Timeout = TimeSpan.FromMinutes(5) };
static string TargetVersion => _remoteConfig?.Version ?? FallbackVersion;
static string TargetManifestUrl => Updater.ManifestAssetUrl ?? FallbackManifestUrl;
// SteamTools
const string SteamToolsDllUrl = "http://update.aaasn.com/update";
const string SteamToolsDwmapiUrl = "http://update.aaasn.com/dwmapi";
const string SteamToolsRegPath = @"Software\Valve\Steamtools";
static async Task<int> Main(string[] args)
{
ClearScreen();
Console.WriteLine($"=== sm0k3r v{Updater.CurrentVersion} ===");
Console.WriteLine();
await Updater.CheckAndApply();
_remoteConfig = await Updater.FetchRemoteConfig();
if (_remoteConfig != null)
Console.WriteLine($"Remote config loaded (target version: {TargetVersion})");
else
Console.WriteLine($"Using built-in config (target version: {TargetVersion})");
string? steamPath = GetSteamPath();
if (steamPath == null)
{
Console.Error.WriteLine("ERROR: Could not find Steam installation path in registry.");
Console.Error.WriteLine("Looked in: HKCU\\Software\\Valve\\Steam -> SteamPath");
return 1;
}
steamPath = steamPath.Replace('/', '\\');
Console.WriteLine($"Steam install path: {steamPath}");
if (!Directory.Exists(steamPath))
{
Console.Error.WriteLine($"ERROR: Steam directory does not exist: {steamPath}");
return 1;
}
string? currentVersion = GetSteamVersion(steamPath);
long curVer = 0, tgtVer = 0;
bool tooNew = currentVersion != null
&& long.TryParse(currentVersion, out curVer)
&& long.TryParse(TargetVersion, out tgtVer)
&& curVer > tgtVer;
if (currentVersion != null)
{
Console.WriteLine($"Current Steam client version: {currentVersion}");
if (currentVersion == TargetVersion)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Steam is up to date.");
Console.ResetColor();
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
if (tooNew)
{
Console.WriteLine($"** Your Steam client is newer than the latest supported version ({TargetVersion}). **");
Console.WriteLine("** Select 'Run everything' or 'Downgrade Steam' to roll back. **");
}
else
{
Console.WriteLine($"** Your Steam client is out of date ({TargetVersion} is latest compatible) **");
Console.WriteLine("** Select 'Run everything' to update **");
}
Console.ResetColor();
}
}
else
Console.WriteLine("Current Steam client version: unknown");
bool steamCurrent = currentVersion == TargetVersion;
var stStatus = CheckSteamToolsStatus(steamPath);
switch (stStatus)
{
case SteamToolsStatus.UpToDate:
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("SteamTools is up to date");
Console.ResetColor();
break;
case SteamToolsStatus.UpToDateCloudFixed:
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("SteamTools is up to date (CloudFix patch detected)");
Console.ResetColor();
break;
case SteamToolsStatus.Outdated:
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("** SteamTools is outdated. **");
Console.ResetColor();
break;
case SteamToolsStatus.NotInstalled:
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("** SteamTools is not installed. **");
Console.ResetColor();
break;
default:
Console.WriteLine("SteamTools status: unknown (no remote hashes to compare).");
break;
}
bool stCurrent = stStatus == SteamToolsStatus.UpToDate || stStatus == SteamToolsStatus.UpToDateCloudFixed;
if (stStatus != SteamToolsStatus.NotInstalled && stStatus != SteamToolsStatus.Unknown)
{
if (tooNew)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("SteamTools is not compatible with this version of Steam!");
}
else
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("SteamTools is compatible with this version of Steam!");
}
Console.ResetColor();
}
string cfgPath = Path.Combine(steamPath, "steam.cfg");
bool updatesBlocked = false;
try
{
if (File.Exists(cfgPath))
{
string cfg = File.ReadAllText(cfgPath);
updatesBlocked = cfg.Contains("BootStrapperInhibitAll=enable", StringComparison.OrdinalIgnoreCase)
&& cfg.Contains("BootStrapperForceSelfUpdate=disable", StringComparison.OrdinalIgnoreCase);
}
}
catch { }
if (updatesBlocked)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Steam updates are blocked");
}
else
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("** Steam updates are NOT blocked. **");
}
Console.ResetColor();
if (!tooNew && !steamCurrent && stStatus != SteamToolsStatus.NotInstalled && stStatus != SteamToolsStatus.Unknown)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("SteamTools is compatible with your Steam version, but your version is out of date. Recommend updating.");
Console.ResetColor();
}
Console.WriteLine();
while (true)
{
// Refresh state
currentVersion = GetSteamVersion(steamPath);
tooNew = currentVersion != null
&& long.TryParse(currentVersion, out curVer)
&& long.TryParse(TargetVersion, out tgtVer)
&& curVer > tgtVer;
steamCurrent = currentVersion == TargetVersion;
stStatus = CheckSteamToolsStatus(steamPath);
stCurrent = stStatus == SteamToolsStatus.UpToDate || stStatus == SteamToolsStatus.UpToDateCloudFixed;
string option1Label;
if (steamCurrent && stCurrent)
option1Label = "Verify installation";
else if (steamCurrent)
option1Label = "Run everything (install SteamTools)";
else if (stCurrent)
option1Label = tooNew
? "Run everything (downgrade Steam)"
: "Run everything (update Steam)";
else
option1Label = tooNew
? "Run everything (downgrade + install SteamTools)"
: "Run everything (update + install SteamTools)";
string option2Label;
if (steamCurrent)
option2Label = "Reinstall Steam at current version";
else if (tooNew)
option2Label = $"Downgrade Steam to {TargetVersion}";
else
option2Label = $"Update Steam to {TargetVersion}";
updatesBlocked = false;
try
{
if (File.Exists(cfgPath))
{
string cfg = File.ReadAllText(cfgPath);
updatesBlocked = cfg.Contains("BootStrapperInhibitAll=enable", StringComparison.OrdinalIgnoreCase)
&& cfg.Contains("BootStrapperForceSelfUpdate=disable", StringComparison.OrdinalIgnoreCase);
}
}
catch { }
string option5Label = updatesBlocked ? "Unblock Steam updates" : "Block Steam updates";
Console.WriteLine("Select an option:");
Console.WriteLine($" 1) {option1Label}");
Console.WriteLine($" 2) {option2Label}");
Console.WriteLine(" 3) Install SteamTools");
Console.WriteLine(" 4) Pick a specific Steam version (advanced)");
Console.WriteLine($" 5) {option5Label}");
Console.WriteLine(" 0) Exit");
Console.WriteLine();
Console.Write("> ");
string? choice = Console.ReadLine()?.Trim();
Console.WriteLine();
switch (choice)
{
case "1":
ClearScreen();
await RunEverything(steamPath);
WaitForKey();
ClearScreen();
break;
case "2":
ClearScreen();
await ApplyTargetVersion(steamPath);
WaitForKey();
ClearScreen();
break;
case "3":
ClearScreen();
await InstallSteamTools(steamPath);
WaitForKey();
ClearScreen();
break;
case "4":
ClearScreen();
await PickAndApplyVersion(steamPath);
WaitForKey();
ClearScreen();
break;
case "5":
ClearScreen();
ToggleSteamUpdates(steamPath, updatesBlocked);
WaitForKey();
ClearScreen();
break;
case "0":
return 0;
default:
Console.WriteLine("Invalid option. Please enter 0-5.");
Console.WriteLine();
break;
}
}
}
static async Task RunEverything(string steamPath)
{
string? currentVersion = GetSteamVersion(steamPath);
bool needsVersionChange = currentVersion != TargetVersion;
var stStatus = CheckSteamToolsStatus(steamPath);
bool needsSteamTools = stStatus != SteamToolsStatus.UpToDate && stStatus != SteamToolsStatus.UpToDateCloudFixed;
if (!needsVersionChange && !needsSteamTools)
{
Console.WriteLine("=== Verify Installation ===");
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"Steam client version: {currentVersion} (target: {TargetVersion})");
Console.WriteLine("SteamTools DLLs match expected hashes.");
Console.ResetColor();
Console.WriteLine();
Console.WriteLine("Everything is up to date. Nothing to do.");
Console.WriteLine();
return;
}
Console.WriteLine("=== Run Everything ===");
Console.WriteLine();
Console.WriteLine("This will:");
if (needsVersionChange)
{
bool isDown = currentVersion != null
&& long.TryParse(currentVersion, out var c)
&& long.TryParse(TargetVersion, out var t)
&& c > t;
string verb = isDown ? "downgrade" : "update";
Console.WriteLine(" - Quit Steam");
Console.WriteLine($" - Delete the package/ directory and download the target Steam version");
Console.WriteLine($" - Launch Steam in update mode to apply the {verb}");
Console.WriteLine(" - Write steam.cfg to block future updates");
Console.WriteLine(" - Clean appcache/ (preserving achievement data)");
}
if (needsSteamTools)
{
Console.WriteLine(" - Install SteamTools DLLs without installing the unnecessary app itself");
Console.WriteLine(" - Launch Steam");
}
Console.WriteLine();
Console.WriteLine("You will NOT lose any installed games or game saves. Everything will be preserved, don't worry.");
Console.WriteLine();
Console.Write("Proceed? [Y/n] ");
string? input = Console.ReadLine();
if (input != null && input.Trim().Equals("n", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("Aborted.");
Console.WriteLine();
return;
}
Console.WriteLine();
if (needsVersionChange)
{
bool versionOk = await ApplyTargetVersion(steamPath, skipPrompt: true);
if (!versionOk)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Version apply failed — skipping SteamTools install to avoid incompatible state.");
Console.ResetColor();
Console.WriteLine();
return;
}
}
if (needsSteamTools)
await InstallSteamTools(steamPath, skipPrompt: true);
}
static async Task<bool> ApplyTargetVersion(string steamPath, bool skipPrompt = false,
string? overrideVersion = null, string? overrideSourcesUrl = null, string? overrideManifestUrl = null,
bool skipSteamToolsInstall = false)
{
string version = overrideVersion ?? TargetVersion;
string? currentVersion = GetSteamVersion(steamPath);
bool isDowngrade = currentVersion != null
&& long.TryParse(currentVersion, out var cur)
&& long.TryParse(version, out var tgt)
&& cur > tgt;
string action = currentVersion == version ? "reinstall"
: isDowngrade ? "downgrade"
: "update";
if (currentVersion != null)
{
if (action == "reinstall")
Console.WriteLine($"Will reinstall Steam at version {version}.");
else
Console.WriteLine($"Will {action} from {currentVersion} to {version}.");
}
else
Console.WriteLine($"Will apply target version {version}.");
if (!skipPrompt)
{
Console.WriteLine();
Console.WriteLine("This will:");
Console.WriteLine(" - Quit Steam");
Console.WriteLine($" - Delete the package/ directory and download the target Steam version");
Console.WriteLine($" - Launch Steam in update mode to apply the {(action == "reinstall" ? "reinstallation" : action)}");
Console.WriteLine(" - Write steam.cfg to block future updates");
Console.WriteLine(" - Clean appcache/ (preserving achievement data)");
Console.WriteLine();
Console.WriteLine("You will NOT lose any installed games or game saves. Everything will be preserved, don't worry.");
Console.WriteLine();
Console.Write("Proceed? [Y/n] ");
string? input = Console.ReadLine();
if (input != null && input.Trim().Equals("n", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("Aborted.");
Console.WriteLine();
return false;
}
Console.WriteLine();
}
KillSteam();
// Write steam.cfg early so even a partial failure leaves update prevention in place
WriteSteamCfg(steamPath);
NukeAppcache(steamPath);
string packageDir = Path.Combine(steamPath, "package");
Console.WriteLine($"Clearing package directory: {packageDir}");
if (Directory.Exists(packageDir))
Directory.Delete(packageDir, true);
Directory.CreateDirectory(packageDir);
Console.WriteLine("Downloading client manifest...");
bool manifestOk = await DownloadManifest(packageDir, overrideManifestUrl);
if (!manifestOk)
{
Console.Error.WriteLine("ERROR: Failed to download client manifest.");
Console.WriteLine();
return false;
}
List<string> urls = await FetchSources(overrideSourcesUrl);
if (urls.Count == 0)
{
Console.Error.WriteLine("ERROR: No package URLs found from remote or embedded sources.");
Console.WriteLine();
return false;
}
Console.WriteLine($"Downloading {urls.Count} package files...");
Console.WriteLine();
bool downloadOk = await DownloadAllPackages(urls, packageDir);
if (!downloadOk)
{
Console.Error.WriteLine("ERROR: Some downloads failed.");
Console.WriteLine();
return false;
}
Console.WriteLine();
Console.WriteLine("All packages downloaded successfully.");
Console.WriteLine();
Console.WriteLine($"Starting local file server on port {FileServerPort}...");
using var cts = new CancellationTokenSource();
var serverTask = RunFileServer(packageDir, FileServerPort, cts.Token);
await Task.Delay(500);
// Bail if the file server failed to start
if (serverTask.IsFaulted || serverTask.IsCompleted)
{
Console.Error.WriteLine("ERROR: File server failed to start.");
Console.WriteLine();
return false;
}
string steamExe = Path.Combine(steamPath, "steam.exe");
if (!File.Exists(steamExe))
{
Console.Error.WriteLine($"ERROR: steam.exe not found at {steamExe}");
cts.Cancel();
Console.WriteLine();
return false;
}
string steamArgs = $"-textmode -forcesteamupdate -forcepackagedownload -overridepackageurl http://127.0.0.1:{FileServerPort}/ -exitsteam";
Console.WriteLine($"Launching: {steamExe} {steamArgs}");
Console.WriteLine();
Console.WriteLine("Steam will download the pinned packages from the local server and then exit.");
Console.WriteLine("Waiting for Steam to finish...");
Console.WriteLine();
try
{
var psi = new ProcessStartInfo
{
FileName = steamExe,
Arguments = steamArgs,
UseShellExecute = false,
};
using var proc = Process.Start(psi);
if (proc != null)
{
// 10-minute timeout — update mode should finish well within this
using var steamTimeout = new CancellationTokenSource(TimeSpan.FromMinutes(10));
try
{
await proc.WaitForExitAsync(steamTimeout.Token);
Console.WriteLine($"Steam exited with code {proc.ExitCode}.");
}
catch (OperationCanceledException)
{
Console.Error.WriteLine("WARNING: Steam did not exit within 10 minutes. Killing...");
try { proc.Kill(true); } catch { }
}
}
}
catch (Exception ex)
{
Console.Error.WriteLine($"ERROR: Failed to launch Steam: {ex.Message}");
}
Console.WriteLine("Stopping local file server...");
cts.Cancel();
try { await serverTask; } catch (OperationCanceledException) { }
// Re-write steam.cfg in case Steam overwrote it
WriteSteamCfg(steamPath);
NukeAppcache(steamPath);
string? newVersion = GetSteamVersion(steamPath);
bool versionOk = false;
if (newVersion != null)
{
Console.WriteLine($"Steam client version after {action}: {newVersion}");
if (newVersion == version)
{
string pastTense = action == "downgrade" ? "downgraded"
: action == "reinstall" ? "reinstalled"
: "updated";
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"Success! Steam is now {pastTense} and update blocking is in place!");
Console.ResetColor();
versionOk = true;
}
else
Console.WriteLine($"WARNING: Version is {newVersion}, expected {version}. The {action} may not have fully applied.");
}
else
{
Console.WriteLine($"Could not verify version after {action}. Check manually.");
}
if (versionOk && !skipSteamToolsInstall)
{
Console.WriteLine();
await InstallSteamTools(steamPath, skipPrompt: true);
}
// Make sure Steam is running at the end of the flow
// InstallSteamTools launches Steam when it does work, but skips when already current
LaunchSteamIfNotRunning(steamPath);
Console.WriteLine();
return versionOk;
}
static async Task InstallSteamTools(string steamPath, bool skipPrompt = false)
{
Console.WriteLine("=== Install SteamTools ===");
Console.WriteLine();
var stStatus = CheckSteamToolsStatus(steamPath);
if (stStatus == SteamToolsStatus.UpToDate || stStatus == SteamToolsStatus.UpToDateCloudFixed)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("SteamTools is already up to date.");
Console.ResetColor();
Console.WriteLine();
return;
}
if (!skipPrompt)
{
Console.Write("Install SteamTools? [Y/n] ");
string? input = Console.ReadLine();
if (input != null && input.Trim().Equals("n", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("Aborted.");
Console.WriteLine();
return;
}
Console.WriteLine();
}
KillSteam();
// Clean up old conflicting DLLs
string[] oldDlls = ["user32.dll", "version.dll"];
foreach (var dll in oldDlls)
{
string path = Path.Combine(steamPath, dll);
if (File.Exists(path))
{
try
{
File.Delete(path);
Console.WriteLine($"Removed old DLL: {dll}");
}
catch (Exception ex)
{
Console.Error.WriteLine($"WARNING: Could not remove {dll}: {ex.Message}");
}
}
}
string betaPath = Path.Combine(steamPath, "package", "beta");
if (File.Exists(betaPath))
{
try { File.Delete(betaPath); } catch { }
}
string xinputPath = Path.Combine(steamPath, "xinput1_4.dll");
string dwmapiPath = Path.Combine(steamPath, "dwmapi.dll");
// Add Defender exclusions (best-effort, requires admin)
AddDefenderExclusion(xinputPath);
AddDefenderExclusion(dwmapiPath);
Console.WriteLine("Downloading SteamTools DLLs...");
bool dlOk = true;
dlOk &= await DownloadFile(_http, SteamToolsDllUrl, xinputPath, "xinput1_4.dll");
dlOk &= await DownloadFile(_http, SteamToolsDwmapiUrl, dwmapiPath, "dwmapi.dll");
if (!dlOk)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Error.WriteLine("SteamTools servers appear to be down.");
Console.Error.WriteLine("Run STFixer to make SteamTools work offline:");
Console.Error.WriteLine(" https://github.com/Selectively11/CloudFix/releases");
Console.ResetColor();
Console.WriteLine();
return;
}
// Verify downloaded DLLs against known hashes when available
var cfg = _remoteConfig;
if (cfg?.SteamToolsXinputSha256 != null && cfg?.SteamToolsDwmapiSha256 != null)
{
string xinputHash = ComputeSha256(xinputPath);
string dwmapiHash = ComputeSha256(dwmapiPath);
if (xinputHash != cfg.SteamToolsXinputSha256 || dwmapiHash != cfg.SteamToolsDwmapiSha256)
{
Console.Error.WriteLine("ERROR: Downloaded SteamTools DLLs do not match expected hashes!");
Console.Error.WriteLine($" xinput1_4.dll: got {xinputHash}, expected {cfg.SteamToolsXinputSha256}");
Console.Error.WriteLine($" dwmapi.dll: got {dwmapiHash}, expected {cfg.SteamToolsDwmapiSha256}");
try { File.Delete(xinputPath); } catch { }
try { File.Delete(dwmapiPath); } catch { }
Console.WriteLine();
return;
}
Console.WriteLine("DLL hashes verified.");
}
try
{
using var key = Registry.CurrentUser.CreateSubKey(SteamToolsRegPath);
if (key != null)
{
// Clean up old properties
try { key.DeleteValue("ActivateUnlockMode", false); } catch { }
try { key.DeleteValue("AlwaysStayUnlocked", false); } catch { }
try { key.DeleteValue("notUnlockDepot", false); } catch { }
key.SetValue("iscdkey", "true", Microsoft.Win32.RegistryValueKind.String);
Console.WriteLine("Set SteamTools registry keys.");
}
}
catch (Exception ex)
{
Console.Error.WriteLine($"WARNING: Could not set registry keys: {ex.Message}");
}
// Re-apply steam.cfg to preserve update prevention
WriteSteamCfg(steamPath);
string steamExe = Path.Combine(steamPath, "steam.exe");
if (File.Exists(steamExe))
{
Console.WriteLine("Launching Steam...");
try
{
Process.Start(new ProcessStartInfo
{
FileName = steamExe,
UseShellExecute = true,
});
}
catch (Exception ex)
{
Console.Error.WriteLine($"WARNING: Could not launch Steam: {ex.Message}");
}
}
Console.WriteLine();
Console.WriteLine("SteamTools installed successfully. Please log in to Steam to activate.");
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("TIP: If SteamTools servers are down, run CloudFix to enable offline mode:");
Console.WriteLine(" https://github.com/Selectively11/CloudFix/releases");
Console.ResetColor();
Console.WriteLine();
}
static async Task PickAndApplyVersion(string steamPath)
{
Console.WriteLine("=== Pick a Specific Steam Version ===");
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("WARNING: This is an advanced option. Only use this if you know what you");
Console.WriteLine("are doing. Not all versions are compatible with SteamTools. SteamTools");
Console.WriteLine("will NOT be automatically installed after this operation.");
Console.ResetColor();
Console.WriteLine();
Console.WriteLine("Fetching available versions...");
var versions = await Updater.FetchVersionsList();
if (versions.Count == 0)
{
Console.Error.WriteLine("ERROR: Could not fetch version list from remote config.");
Console.WriteLine();
return;
}
string? currentVersion = GetSteamVersion(steamPath);
Console.WriteLine();
Console.WriteLine("Available versions:");
Console.WriteLine();
for (int i = 0; i < versions.Count; i++)
{
string label = versions[i].Label ?? "";
string recommended = versions[i].Version == TargetVersion ? " (recommended)" : "";
string current = versions[i].Version == currentVersion ? " [installed]" : "";
Console.WriteLine($" {i + 1}) {versions[i].Version} - {label}{recommended}{current}");
}
Console.WriteLine();
Console.WriteLine(" 0) Back to main menu");
Console.WriteLine();
Console.Write("> ");
string? choice = Console.ReadLine()?.Trim();
if (choice == "0" || string.IsNullOrEmpty(choice))
{
Console.WriteLine();
return;
}
if (!int.TryParse(choice, out int idx) || idx < 1 || idx > versions.Count)
{
Console.WriteLine("Invalid selection.");
Console.WriteLine();
return;
}
var selected = versions[idx - 1];
Console.WriteLine();
if (selected.SourcesUrl == null || selected.ManifestUrl == null)
{
Console.Error.WriteLine("ERROR: Missing download URLs for this version. The config release may be incomplete.");
Console.WriteLine();
return;
}
await ApplyTargetVersion(steamPath,
overrideVersion: selected.Version,
overrideSourcesUrl: selected.SourcesUrl,
overrideManifestUrl: selected.ManifestUrl,
skipSteamToolsInstall: true);
}
static async Task<bool> DownloadFile(HttpClient httpClient, string url, string filePath, string displayName)
{
try
{
if (File.Exists(filePath))
File.Delete(filePath);
using var response = await httpClient.GetAsync(url);
response.EnsureSuccessStatusCode();
byte[] content = await response.Content.ReadAsByteArrayAsync();
await File.WriteAllBytesAsync(filePath, content);
Console.WriteLine($" Downloaded {displayName} ({content.Length / 1024.0:F1} KB)");
return true;
}
catch (Exception ex)
{
Console.Error.WriteLine($" FAILED {displayName}: {ex.Message}");
return false;
}
}
static void AddDefenderExclusion(string path)
{
try
{
var psi = new ProcessStartInfo
{
FileName = "powershell",
Arguments = $"-Command \"Add-MpPreference -ExclusionPath '{path}' -ErrorAction SilentlyContinue\"",
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
};
using var proc = Process.Start(psi);
proc?.WaitForExit(5000);
}
catch { }
}
static string? GetSteamPath()
{
try
{
using var key = Registry.CurrentUser.OpenSubKey(@"Software\Valve\Steam");
if (key != null)
{
var val = key.GetValue("SteamPath");
if (val is string s && !string.IsNullOrWhiteSpace(s))
return s;
}
}
catch { }
// Fallback: check common paths
string[] fallbacks = [
@"C:\Program Files (x86)\Steam",
@"C:\Program Files\Steam",
@"C:\Steam",
];
foreach (var path in fallbacks)
{
if (Directory.Exists(path) && File.Exists(Path.Combine(path, "steam.exe")))
return path;
}
return null;
}
static string? GetSteamVersion(string steamPath)
{
string manifestPath = Path.Combine(steamPath, "package", "steam_client_win64.manifest");
if (File.Exists(manifestPath))
{
string? ver = ExtractVersionFromManifest(manifestPath);
if (ver != null) return ver;
}
string infPath = Path.Combine(steamPath, "steam.inf");
if (File.Exists(infPath))
{
try
{
foreach (var line in File.ReadAllLines(infPath))
{
if (line.StartsWith("ClientVersion=", StringComparison.OrdinalIgnoreCase))
{
return line.Substring("ClientVersion=".Length).Trim();
}
}
}
catch { }
}
return null;
}
internal static string? ExtractVersionFromManifest(string manifestPath)
{
try
{
string content = File.ReadAllText(manifestPath);
// VDF-like format: "version" "1234567890"
var match = Regex.Match(content, @"""version""\s+""(\d+)""");
if (match.Success)
return match.Groups[1].Value;
}
catch { }
return null;
}
static void KillSteam()
{
string[] processNames = ["steam", "steamwebhelper", "steamservice"];
bool killed = false;
foreach (var name in processNames)
{
foreach (var proc in Process.GetProcessesByName(name))
{
try
{
Console.WriteLine($"Killing process: {proc.ProcessName} (PID {proc.Id})");
proc.Kill(true);
killed = true;
}
catch (Exception ex)
{
Console.Error.WriteLine($"WARNING: Could not kill {proc.ProcessName}: {ex.Message}");
}
finally
{
proc.Dispose();
}
}
}
if (killed)
{
Console.WriteLine("Waiting for Steam processes to exit...");
Thread.Sleep(3000);
}
}
static void LaunchSteamIfNotRunning(string steamPath)
{
var existing = Process.GetProcessesByName("steam");
bool running = existing.Length > 0;
foreach (var p in existing) p.Dispose();
if (running) return;
string steamExe = Path.Combine(steamPath, "steam.exe");
if (!File.Exists(steamExe)) return;
Console.WriteLine("Launching Steam...");
try
{
Process.Start(new ProcessStartInfo
{
FileName = steamExe,
UseShellExecute = true,
});
}
catch (Exception ex)
{
Console.Error.WriteLine($"WARNING: Could not launch Steam: {ex.Message}");
}
}
internal static List<string> ReadEmbeddedSources()
{
var urls = new List<string>();
var assembly = Assembly.GetExecutingAssembly();
string? resourceName = null;
foreach (var name in assembly.GetManifestResourceNames())
{
if (name.EndsWith("sources.txt", StringComparison.OrdinalIgnoreCase))
{
resourceName = name;
break;
}
}
if (resourceName == null)
{
Console.Error.WriteLine("ERROR: Embedded resource 'sources.txt' not found.");
Console.Error.WriteLine("Available resources: " + string.Join(", ", assembly.GetManifestResourceNames()));
return urls;
}
using var stream = assembly.GetManifestResourceStream(resourceName);
if (stream == null) return urls;
using var reader = new StreamReader(stream);
string? line;
while ((line = reader.ReadLine()) != null)
{
line = line.Trim();
if (line.Length > 0 && !line.StartsWith('#'))
{
urls.Add(line);
}
}
return urls;
}
static async Task<List<string>> FetchSources(string? overrideSourcesUrl = null)
{
string? sourcesUrl = overrideSourcesUrl ?? Updater.SourcesAssetUrl;
if (!string.IsNullOrEmpty(sourcesUrl))
{
try
{
string raw = await _http.GetStringAsync(sourcesUrl);
var urls = ParseSourceLines(raw);
if (urls.Count > 0)
{
Console.WriteLine($"Loaded {urls.Count} package URLs from remote sources.");
return urls;
}
}
catch
{
Console.WriteLine("Could not fetch remote sources, falling back to embedded.");
}
}
if (overrideSourcesUrl != null)
return [];