-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgramCMD.cs
More file actions
357 lines (315 loc) · 13.8 KB
/
Copy pathProgramCMD.cs
File metadata and controls
357 lines (315 loc) · 13.8 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
using System;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using System.Diagnostics;
using System.IO.Compression;
using System.Text.Json;
class Program
{
private const string GITHUB_API = "https://api.github.com/repos/FluxyRepacks/AutoCrack/releases/latest";
private const string GITHUB_REPO = "https://github.com/FluxyRepacks/AutoCrack";
private const string GITHUB_RAW = "https://raw.githubusercontent.com/FluxyRepacks/AutoCrack/main/steam";
private const string CURRENT_VERSION = "1.0.0";
private static readonly HttpClient httpClient = new HttpClient();
static async Task Main()
{
httpClient.DefaultRequestHeaders.Add("User-Agent", "AutoCrack-Console");
Console.Title = $"Fluxy Repacks - AutoCrack v{CURRENT_VERSION}";
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("╔════════════════════════════════════════╗");
Console.WriteLine($"║ Fluxy Repacks - AutoCrack v{CURRENT_VERSION} ║");
Console.WriteLine("║ Steam API DLL Replacer ║");
Console.WriteLine($"║ GitHub: {GITHUB_REPO.PadRight(24)}║");
Console.WriteLine("╚════════════════════════════════════════╝");
Console.ResetColor();
Console.WriteLine();
// Check for updates
await CheckForUpdates();
// Get the directory containing the executable
string appDir = AppDomain.CurrentDomain.BaseDirectory;
string steamDir = Path.Combine(appDir, "steam");
// Check if steam folder exists, if not download it
if (!Directory.Exists(steamDir) || !HasSteamDlls(steamDir))
{
await DownloadSteamFolder(appDir, steamDir);
}
// Check for DLL files in steam folder
string steamApi32 = Path.Combine(steamDir, "steam_api.dll");
string steamApi64 = Path.Combine(steamDir, "steam_api64.dll");
bool has32bit = File.Exists(steamApi32);
bool has64bit = File.Exists(steamApi64);
if (!has32bit && !has64bit)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("[ERROR] No DLL files found even after download attempt!");
Console.ResetColor();
Console.WriteLine($"Please check: {GITHUB_REPO}");
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
return;
}
Console.WriteLine($"[INFO] Found in steam folder:");
if (has32bit) Console.WriteLine(" ✓ steam_api.dll");
if (has64bit) Console.WriteLine(" ✓ steam_api64.dll");
Console.WriteLine();
// Get target directory from user
Console.Write("Enter the target directory path: ");
string targetDir = Console.ReadLine()?.Trim('"');
if (string.IsNullOrEmpty(targetDir) || !Directory.Exists(targetDir))
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("[ERROR] Invalid directory path!");
Console.ResetColor();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
return;
}
Console.WriteLine();
Console.WriteLine("[INFO] Scanning directory and subdirectories...");
Console.WriteLine();
int replaced32 = 0;
int replaced64 = 0;
int errors = 0;
try
{
// Search for all matching DLL files
if (has32bit)
{
string[] files32 = Directory.GetFiles(targetDir, "steam_api.dll", SearchOption.AllDirectories);
foreach (string file in files32)
{
try
{
File.Copy(steamApi32, file, true);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"[REPLACED] {file}");
Console.ResetColor();
replaced32++;
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"[FAILED] {file} - {ex.Message}");
Console.ResetColor();
errors++;
}
}
}
if (has64bit)
{
string[] files64 = Directory.GetFiles(targetDir, "steam_api64.dll", SearchOption.AllDirectories);
foreach (string file in files64)
{
try
{
File.Copy(steamApi64, file, true);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"[REPLACED] {file}");
Console.ResetColor();
replaced64++;
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"[FAILED] {file} - {ex.Message}");
Console.ResetColor();
errors++;
}
}
}
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"[ERROR] {ex.Message}");
Console.ResetColor();
}
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("╔════════════════════════════════════════╗");
Console.WriteLine("║ SUMMARY ║");
Console.WriteLine("╚════════════════════════════════════════╝");
Console.ResetColor();
Console.WriteLine($"steam_api.dll replaced: {replaced32}");
Console.WriteLine($"steam_api64.dll replaced: {replaced64}");
Console.WriteLine($"Total files replaced: {replaced32 + replaced64}");
if (errors > 0)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"Errors encountered: {errors}");
Console.ResetColor();
}
Console.WriteLine();
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
private static bool HasSteamDlls(string steamDir)
{
if (!Directory.Exists(steamDir)) return false;
string steamApi32 = Path.Combine(steamDir, "steam_api.dll");
string steamApi64 = Path.Combine(steamDir, "steam_api64.dll");
return File.Exists(steamApi32) || File.Exists(steamApi64);
}
private static async Task DownloadSteamFolder(string appDir, string steamDir)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("[INFO] Steam folder not found. Downloading from GitHub repository...");
Console.ResetColor();
try
{
if (!Directory.Exists(steamDir))
Directory.CreateDirectory(steamDir);
// Download steam_api.dll
Console.WriteLine("[INFO] Downloading steam_api.dll...");
try
{
var dll32Data = await httpClient.GetByteArrayAsync($"{GITHUB_RAW}/steam_api.dll");
File.WriteAllBytes(Path.Combine(steamDir, "steam_api.dll"), dll32Data);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("[SUCCESS] steam_api.dll downloaded!");
Console.ResetColor();
}
catch
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("[WARNING] steam_api.dll not found in repository");
Console.ResetColor();
}
// Download steam_api64.dll
Console.WriteLine("[INFO] Downloading steam_api64.dll...");
try
{
var dll64Data = await httpClient.GetByteArrayAsync($"{GITHUB_RAW}/steam_api64.dll");
File.WriteAllBytes(Path.Combine(steamDir, "steam_api64.dll"), dll64Data);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("[SUCCESS] steam_api64.dll downloaded!");
Console.ResetColor();
}
catch
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("[WARNING] steam_api64.dll not found in repository");
Console.ResetColor();
}
Console.WriteLine();
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"[ERROR] Failed to download Steam DLLs: {ex.Message}");
Console.ResetColor();
Console.WriteLine($"Please download manually from: {GITHUB_REPO}/tree/main/steam");
Console.WriteLine();
}
}
private static async Task CheckForUpdates()
{
try
{
Console.WriteLine("[INFO] Checking for updates...");
var response = await httpClient.GetStringAsync(GITHUB_API);
var jsonDoc = JsonDocument.Parse(response);
string latestVersion = jsonDoc.RootElement.GetProperty("tag_name").GetString().TrimStart('v');
if (IsNewerVersion(latestVersion, CURRENT_VERSION))
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"[UPDATE] New version available: v{latestVersion} (Current: v{CURRENT_VERSION})");
Console.ResetColor();
Console.Write("Do you want to update now? (Y/N): ");
string answer = Console.ReadLine()?.Trim().ToUpper();
if (answer == "Y" || answer == "YES")
{
await DownloadAndInstallUpdate(jsonDoc);
}
else
{
Console.WriteLine("[INFO] Update skipped. Continuing...");
Console.WriteLine();
}
}
else
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("[INFO] You are using the latest version!");
Console.ResetColor();
Console.WriteLine();
}
}
catch
{
// Silently skip if no releases exist
Console.WriteLine("[INFO] No updates available.");
Console.WriteLine();
}
}
private static async Task DownloadAndInstallUpdate(JsonDocument releaseData)
{
try
{
Console.WriteLine("[INFO] Downloading update...");
var assets = releaseData.RootElement.GetProperty("assets");
string downloadUrl = null;
foreach (var asset in assets.EnumerateArray())
{
string name = asset.GetProperty("name").GetString();
if (name.EndsWith(".exe") && !name.Contains("GUI"))
{
downloadUrl = asset.GetProperty("browser_download_url").GetString();
break;
}
}
if (downloadUrl == null)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("[ERROR] Update file not found!");
Console.ResetColor();
return;
}
string appDir = AppDomain.CurrentDomain.BaseDirectory;
string currentExe = Process.GetCurrentProcess().MainModule.FileName;
string newExePath = Path.Combine(appDir, "AutoCrack_new.exe");
string batchPath = Path.Combine(appDir, "update.bat");
var exeData = await httpClient.GetByteArrayAsync(downloadUrl);
File.WriteAllBytes(newExePath, exeData);
// Create update batch script
string batchContent = $@"@echo off
timeout /t 2 /nobreak >nul
del ""{currentExe}""
move /y ""{newExePath}"" ""{currentExe}""
start """" ""{currentExe}""
del ""%~f0""";
File.WriteAllText(batchPath, batchContent);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("[SUCCESS] Update downloaded! Restarting...");
Console.ResetColor();
Process.Start(new ProcessStartInfo
{
FileName = batchPath,
CreateNoWindow = true,
UseShellExecute = false
});
Environment.Exit(0);
}
catch (Exception ex)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine($"[ERROR] Update failed: {ex.Message}");
Console.ResetColor();
}
}
private static bool IsNewerVersion(string latest, string current)
{
var latestParts = latest.Split('.');
var currentParts = current.Split('.');
for (int i = 0; i < Math.Min(latestParts.Length, currentParts.Length); i++)
{
if (int.TryParse(latestParts[i], out int l) && int.TryParse(currentParts[i], out int c))
{
if (l > c) return true;
if (l < c) return false;
}
}
return false;
}
}