-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cs
510 lines (502 loc) · 14.8 KB
/
Main.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
using System;
using System.Xml;
using System.IO;
using System.Threading;
using System.Text;
using System.Collections;
using System.Security.Cryptography;
using System.Web;
using System.Net;
namespace ffManager
{
class MainClass
{
public static string ffversion = "";
public static string fastfile = "";
public static string profile = "";
public static string console = "";
private static string DS = ffManager.MainClass.getOS() == "win32" ? @"\" : "/";
public static string cwd = "";
public static void Main (string[] args)
{
string cwd_exe = System.Reflection.Assembly.GetExecutingAssembly().Location.ToString();
FileInfo exeinfo = new FileInfo(cwd_exe);
MainClass.cwd = exeinfo.Directory.FullName;
if(!File.Exists(MainClass.cwd + MainClass.DS + "offzip.exe") || !File.Exists(MainClass.cwd + MainClass.DS + "packzip.exe"))
{
Console.WriteLine("Opps, seems you are missing required files!");
Console.WriteLine("Please Re-Download ffManager from SimplyHacks.com...");
Console.WriteLine("Press Enter to Continue");
Console.Read();
return;
}
if(File.Exists("." + MainClass.DS + "ffManager-old.exe"))
{
Thread.Sleep(700);
File.Delete("." + MainClass.DS + "ffManager-old.exe");
}
Console.WriteLine("ffManager Tool\n");
Console.WriteLine("Version: " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version + "\n");
Console.WriteLine("------------------------------\n");
Console.WriteLine("Created by Derrick Hammer, A.K.A. PCFreak30\n");
Console.WriteLine("Released under GPLv3 License, http://www.gnu.org/licenses/gpl.html\n\n");
Console.WriteLine("Visit PCFreak30.com for News and Updates\n\n");
Console.WriteLine("Visit SimplyHacks.com for Releases and a fun, leech-free community..\n");
Console.WriteLine("------------------------------\n");
Thread.Sleep(3000);
Console.Clear();
if(args.Length == 1)
{
args[0] = args[0].Trim().Replace("'","").Replace(@"""","");
isValidFastFile(args[0], false);
if(isValidProfile(args[0]))
MainClass.profile = args[0];
}
if(args.Length == 2)
{
args[0] = args[0].Trim().Replace("'","").Replace(@"""","");
args[1] = args[1].Trim().Replace("'","").Replace(@"""","");
isValidFastFile(args[0], false);
isValidFastFile(args[1], false);
if(isValidProfile(args[0]))
MainClass.profile = args[0];
if(isValidProfile(args[1]))
MainClass.profile = args[1];
}
if(MainClass.checkForUpdate())
{/*
Console.WriteLine("Update Complete! Please re-run ffManager to use the new version");
Console.WriteLine("Thank You");
Console.WriteLine("Press ENTER to continue");
Console.Read();
*/
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName=MainClass.cwd + MainClass.DS + "ffManager.exe";
p.Start();
return;
}
else
{
MainClass.showOptions();
}
}
private static void showOptions()
{
Console.Clear();
Console.WriteLine("\t\t\tPlease select an action AND press ENTER:");
Console.WriteLine("");
if(MainClass.fastfile.Length > 0)
Console.WriteLine("1: Set the FastFile to use\n\t\tCurrent:" + MainClass.fastfile + "\n\t\tVersion: " + MainClass.ffversion);
else
Console.WriteLine("1: Set the FastFile to use");
if(MainClass.profile.Length > 0)
Console.WriteLine("2: Set the FastFile FFXML profile to use\n\t\tCurrent:" + MainClass.profile);
else
Console.WriteLine("2: Set the FastFile FFXML profile to use");
if(MainClass.console.Length > 0)
Console.WriteLine("3: Set the Console\n\t\tCurrent: " + MainClass.console);
else
Console.WriteLine("3: Set the Console");
Console.WriteLine("4: De-Compress the FastFile");
Console.WriteLine("5: Compress the FastFile");
Console.WriteLine("6: Quit");
Console.WriteLine("");
Console.Write("Choice:");
string choice = Console.ReadLine().Trim();
switch(choice)
{
case "1":
MainClass.promptFastFile();
break;
case "2":
MainClass.promptProfile();
break;
case "3":
MainClass.promptConsole();
break;
case "4":
MainClass.doDecompress();
break;
case "5":
MainClass.doCompress();
break;
case "6":
return;
break;
default:
MainClass.showOptions();
break;
}
}
private static void promptFastFile()
{
Console.Clear();
Console.WriteLine("Drag and drop a FastFile into this window AND press ENTER: ");
string file = Console.ReadLine().Trim().Replace("'","").Replace(@"""","");
if(file == "")
MainClass.showOptions();
if(MainClass.isValidFastFile(file, true))
{
switch(MainClass.ffversion)
{
case "cod4":
Console.WriteLine("Call of Duty 4 FastFile Detected");
break;
case "cod5":
Console.WriteLine("Call of Duty World at War FastFile Detected");
break;
case "mw2":
Console.WriteLine("Modern Warfare 2 FastFile Detected");
break;
}
Thread.Sleep(1500);
MainClass.showOptions();
}
else
MainClass.promptFastFile();
}
private static bool isValidFastFile(string file, bool showError)
{
if(!File.Exists(file))
return false;
BinaryReader binread = new BinaryReader( File.OpenRead(file));
string header =new string(binread.ReadChars(8)).Trim().ToLower();
binread.BaseStream.Seek(10,SeekOrigin.Begin);
byte[] verb = binread.ReadBytes(2);
binread.Close();
string verba = "";
for(int i=0; i < verb.Length; i++)
{
verba = verba + int.Parse(verb[i].ToString()).ToString();
}
int version = int.Parse(verba);
if(header != "iwff0100" && header != "iwffu100")
{
if(showError)
{
Console.WriteLine("This is NOT a valid FastFile");
Thread.Sleep(2000);
}
return false;
}
else if(header == "iWffs100")
{
if(showError)
{
Console.WriteLine("ffManager does NOT support signed fastfiles");
Thread.Sleep(2000);
}
return false;
}
switch(version)
{
case 1:
MainClass.ffversion = "cod4";
MainClass.fastfile= file;
return true;
break;
case 113:
MainClass.ffversion = "mw2";
MainClass.fastfile= file;
return true;
break;
case 1131:
MainClass.ffversion = "cod5";
MainClass.fastfile= file;
return true;
break;
default:
Console.WriteLine("ffManager does not suport FastFiles of that version...");
Thread.Sleep(2000);
return false;
break;
}
}
private static void promptProfile()
{
Console.Clear();
Console.WriteLine("Drag and drop a FastFile FFXML Profile into this window AND press ENTER: ");
string file = Console.ReadLine().Trim().Replace("'","").Replace(@"""","");
if(file == "")
MainClass.showOptions();
if(MainClass.isValidProfile(file))
{
MainClass.profile = file;
Console.WriteLine("Profile "+ file +" set");
Thread.Sleep(1500);
MainClass.showOptions();
}
else
MainClass.promptProfile();
}
private static bool isValidProfile(string file)
{
if(!File.Exists(file))
return false;
XmlDocument xml = new XmlDocument();
try
{
xml.Load(file);
return true;
}
catch (XmlException xmlex)
{
return false;
}
}
private static void promptConsole()
{
Console.Clear();
Console.WriteLine("Please choose the console format for the FastFile: ");
Console.WriteLine("Valid Options are:\n\t--> PS3\n\t-->XBOX\n(Not case sensitive)\n\nChoice:");
string console = Console.ReadLine().Trim();
if(console == "")
MainClass.showOptions();
if(console == "ps3" || console == "xbox")
{
MainClass.console = console;
MainClass.showOptions();
}
else
MainClass.promptConsole();
}
private static void doDecompress()
{
if(MainClass.fastfile.Length == 0)
{
Console.WriteLine("ERROR: FastFile not set. Going to FastFile selection...");
Thread.Sleep(2000);
MainClass.promptFastFile();
}
else if(MainClass.profile.Length == 0)
{
Console.WriteLine("ERROR: FastFile FFXML Profile not set. Going to profile selection...");
Thread.Sleep(2000);
MainClass.promptProfile();
}
else if(MainClass.console.Length == 0)
{
Console.WriteLine("ERROR: Console not set. Going to console selection...");
Thread.Sleep(2000);
MainClass.promptConsole();
}
else
{
FileInfo ffinfo = new FileInfo(MainClass.fastfile);
string dir = ffinfo.DirectoryName + MainClass.DS + ffinfo.Name.Replace(ffinfo.Extension,"_work");
if(MainClass.ffversion == "cod4")
{
COD4_Decompress cod = new COD4_Decompress(MainClass.fastfile,MainClass.console);
cod.decompress(dir, MainClass.profile);
ArrayList missing = cod.getMissingFiles();
if(missing.Count > 0)
{
foreach(ArrayList element in missing)
{
Console.WriteLine("Missing Data " + element[0] + " for file "+ element[1]);
}
}
}
else if(MainClass.ffversion == "cod5")
{
COD5_Decompress cod = new COD5_Decompress(MainClass.fastfile,MainClass.console);
cod.decompress(dir, MainClass.profile);
ArrayList missing = cod.getMissingFiles();
if(missing.Count > 0)
{
foreach(ArrayList element in missing)
{
Console.WriteLine("Missing Data " + element[0] + " for file "+ element[1]);
}
}
}
else if(MainClass.ffversion == "mw2")
{
MW2_Decompress cod = new MW2_Decompress(MainClass.fastfile,MainClass.console);
cod.decompress(dir, MainClass.profile);
ArrayList missing = cod.getMissingFiles();
if(missing.Count > 0)
{
foreach(ArrayList element in missing)
{
Console.WriteLine("Missing Data " + element[0] + " for file "+ element[1]);
}
}
}
Console.WriteLine("Press ENTER to continue back to program options..");
Console.ReadLine();
MainClass.showOptions();
}
}
private static void doCompress()
{
FileInfo ffinfo = new FileInfo(MainClass.fastfile);
string dir = ffinfo.DirectoryName + MainClass.DS + ffinfo.Name.Replace(ffinfo.Extension,"_work");
if(!Directory.Exists(dir) || !Directory.Exists(dir + DS + "raw") || !Directory.Exists(dir + DS + "scripts"))
{
Console.WriteLine("ERROR: You have not De-Compressed the currently set FastFile!");
Thread.Sleep(2000);
MainClass.promptFastFile();
}
else
{
if(MainClass.ffversion == "cod4")
{
COD4_Compress cod = new COD4_Compress(MainClass.fastfile,MainClass.console);
cod.compress(dir, MainClass.profile);
ArrayList missing = cod.getMissingFiles();
ArrayList overflow = cod.getOverflow();
if(missing.Count > 0)
{
foreach(ArrayList element in missing)
{
Console.WriteLine("Missing Data " + element[0] + " for file "+ element[1]);
}
}
if(overflow.Count > 0)
{
foreach(ArrayList element in overflow )
{
Console.WriteLine("Overflow in " + element[0] + "! Max size is: "+ element[1] + " -- Overflow is: " + element[2]);
}
}
}
else if(MainClass.ffversion == "cod5")
{
COD5_Compress cod = new COD5_Compress(MainClass.fastfile,MainClass.console);
cod.compress(dir, MainClass.profile);
ArrayList missing = cod.getMissingFiles();
ArrayList overflow = cod.getOverflow();
if(missing.Count > 0)
{
foreach(ArrayList element in missing)
{
Console.WriteLine("Missing Data " + element[0] + " for file "+ element[1]);
}
}
if(overflow.Count > 0)
{
foreach(ArrayList element in overflow )
{
Console.WriteLine("Overflow in " + element[0] + "! Max size is: "+ element[1] + " -- Overflow is: " + element[2]);
}
}
}
else if(MainClass.ffversion == "mw2")
{
MW2_Compress cod = new MW2_Compress(MainClass.fastfile,MainClass.console);
cod.compress(dir, MainClass.profile);
ArrayList missing = cod.getMissingFiles();
ArrayList overflow = cod.getOverflow();
if(missing.Count > 0)
{
foreach(ArrayList element in missing)
{
Console.WriteLine("Missing Data " + element[0] + " for file "+ element[1]);
}
}
if(overflow.Count > 0)
{
foreach(ArrayList element in overflow )
{
Console.WriteLine("Overflow in " + element[0] + "! Max size is: "+ element[1] + " -- Overflow is: " + element[2]);
}
}
}
Console.WriteLine("Press ENTER to continue back to program options..");
Console.ReadLine();
MainClass.showOptions();
}
}
public static string getOS()
{
OperatingSystem os = Environment.OSVersion;
PlatformID pid = os.Platform;
string result = "";
switch (pid)
{
case PlatformID.Win32NT:
case PlatformID.Win32S:
case PlatformID.Win32Windows:
case PlatformID.WinCE:
result= "win32";
break;
case PlatformID.Unix:
result= "unix";
break;
}
return result;
}
public static string GetMD5HashFromFile(string fileName)
{
FileStream file = new FileStream(fileName, FileMode.Open);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] retVal = md5.ComputeHash(file);
file.Close();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < retVal.Length; i++)
{
sb.Append(retVal[i].ToString("x2"));
}
return sb.ToString();
}
private static bool checkForUpdate()
{
string version = "";
try
{
XmlTextReader reader = new XmlTextReader("http://www.simplyhacks.com/ffManager-version.xml");
reader.Read();
reader.MoveToContent();
while (!reader.EOF && reader.Name != "version")
{
reader.Read();
}
version = reader.ReadString();
}
catch(Exception execp)
{
return false;
}
if(version == System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString())
return false;
if(MainClass.promptUpdate(version))
{
try
{
MainClass.doUpdate();
}
catch(Exception execp)
{
return false;
}
return true;
}
return false;
}
private static bool promptUpdate(string version)
{
Console.Clear();
Console.WriteLine("**UPDATE NOTICE**");
Console.WriteLine("The latest version of ffManager is " + version + "..You have version "+ System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + "\n Would you like to update? YES or NO: ");
string answer = Console.ReadLine().Trim().ToLower();
if(answer == "yes")
return true;
else if(answer == "no")
return false;
else
return MainClass.promptUpdate(version);
}
private static void doUpdate()
{
Console.Clear();
string updateFile = "." + MainClass.DS + "ffManager.exe";
string origFile = "." + MainClass.DS + "ffManager-old.exe";
if(File.Exists(origFile))
File.Delete(origFile);
File.Move(updateFile, origFile);
WebClient req = new WebClient();
req.DownloadFile("http://www.simplyhacks.com/ffManager.exe",updateFile);
}
}
}