-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGames.cs
805 lines (721 loc) · 31.3 KB
/
Games.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
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
namespace BISLib
{
/// <summary>
/// Provides methods and properties which can be assigned to
/// provide a launch setup for a specific game.
/// </summary>
public class Game
{
#region Static Game Instances
private static Game _arma2;
/// <summary>
/// ArmA 2
/// </summary>
public static Game ArmA2
{
get
{
if (_arma2 == null)
{
_arma2 = new Game("ArmA2");
_arma2.InstallDirectory = launch =>
{
switch(launch)
{
case LaunchTypes.Steam:
case LaunchTypes.Beta:
case LaunchTypes.Release:
case LaunchTypes.Latest:
return Game.ArmA2Directory;
default: return null;
}
};
_arma2.ExecutableFile = launch =>
{
switch(launch)
{
case LaunchTypes.Steam:
return Path.Combine(SteamDirectory, "Steam.exe");
case LaunchTypes.Release:
if (_arma2.InstallDirectory(launch) == null)
return null;
return Path.Combine(_arma2.InstallDirectory(launch), "arma2.exe");
case LaunchTypes.Beta:
if (_arma2.InstallDirectory(launch) == null)
return null;
return Path.Combine(_arma2.InstallDirectory(launch), "beta", "arma2.exe");
default: return null;
}
};
_arma2.IsGamePresent = launch =>
{
string exePath = _arma2.ExecutableFile(launch);
if (exePath != null && File.Exists(exePath))
return true;
return false;
};
_arma2.EquivalentLaunch = launch =>
{
if (launch != LaunchTypes.Latest)
return launch;
Version releaseVersion = GetAssemblyVersion(_arma2.ExecutableFile(LaunchTypes.Release));
Version betaVersion = GetAssemblyVersion(_arma2.ExecutableFile(LaunchTypes.Beta));
if (releaseVersion < betaVersion)
return LaunchTypes.Beta;
return LaunchTypes.Release;
};
_arma2.BaseArguments = launch =>
{
if (launch == LaunchTypes.Steam)
return "-applaunch 33910 ";
return "";
};
_arma2.BaseMods = launch =>
{
if (launch == LaunchTypes.Beta)
return "beta";
return "";
};
_arma2.GameFolder = folder =>
{
switch(folder)
{
case "AddOns":
case "BattlEye":
case "BEsetup":
case "beta":
case "Campaigns":
case "DirectX":
case "Dta":
case "Keys":
case "Missions":
case "MPMissions":
case "userconfig":
return true;
default: return false;
}
};
}
return _arma2;
}
}
private static Game _operationArrowhead;
/// <summary>
/// ArmA 2 Operation Arrowhead
/// </summary>
public static Game OperationArrowhead
{
get
{
if (_operationArrowhead == null)
{
_operationArrowhead = new Game("Operation Arrowhead");
_operationArrowhead.InstallDirectory = launch =>
{
switch (launch)
{
case LaunchTypes.Steam:
case LaunchTypes.Beta:
case LaunchTypes.Release:
case LaunchTypes.Latest:
return Game.OperationArrowheadDirectory;
default: return null;
}
};
_operationArrowhead.ExecutableFile = launch =>
{
switch (launch)
{
case LaunchTypes.Steam:
return Path.Combine(SteamDirectory, "Steam.exe");
case LaunchTypes.Release:
if (_operationArrowhead.InstallDirectory(launch) == null)
return null;
return Path.Combine(_operationArrowhead.InstallDirectory(launch), "arma2oa.exe");
case LaunchTypes.Beta:
if (_operationArrowhead.InstallDirectory(launch) == null)
return null;
return Path.Combine(_operationArrowhead.InstallDirectory(launch), "Expansion", "beta", "arma2oa.exe");
default: return null;
}
};
_operationArrowhead.IsGamePresent = launch =>
{
string exePath = _operationArrowhead.ExecutableFile(launch);
if (exePath != null && File.Exists(exePath))
return true;
return false;
};
_operationArrowhead.EquivalentLaunch = launch =>
{
if (launch != LaunchTypes.Latest)
return launch;
Version releaseVersion = GetAssemblyVersion(_operationArrowhead.ExecutableFile(LaunchTypes.Release));
Version betaVersion = GetAssemblyVersion(_operationArrowhead.ExecutableFile(LaunchTypes.Beta));
if (releaseVersion < betaVersion)
return LaunchTypes.Beta;
return LaunchTypes.Release;
};
_operationArrowhead.BaseArguments = launch =>
{
if (launch == LaunchTypes.Steam)
return "-applaunch 33930 ";
return "";
};
_operationArrowhead.BaseMods = launch =>
{
if (launch == LaunchTypes.Beta)
return "Expansion/beta";
return "";
};
_operationArrowhead.GameFolder = folder =>
{
switch (folder)
{
case "AddOns":
case "BattlEye":
case "BEsetup":
case "Common":
case "Campaigns":
case "DirectX":
case "Dta":
case "Keys":
case "Missions":
case "MPMissions":
case "userconfig":
case "BAF":
case "PMC":
return true;
default: return false;
}
};
}
return _operationArrowhead;
}
}
private static Game _combinedOperations;
/// <summary>
/// ArmA 2 Combined Operations
/// </summary>
public static Game CombinedOperations
{
get
{
if (_combinedOperations == null)
{
_combinedOperations = new Game("Combined Operations");
_combinedOperations.InstallDirectory = launch =>
{
switch (launch)
{
case LaunchTypes.Steam:
case LaunchTypes.Beta:
case LaunchTypes.Release:
case LaunchTypes.Latest:
return Game.OperationArrowheadDirectory;
default: return null;
}
};
_combinedOperations.ExecutableFile = launch =>
{
switch (launch)
{
case LaunchTypes.Steam:
return Path.Combine(SteamDirectory, "Steam.exe");
case LaunchTypes.Release:
if (_combinedOperations.InstallDirectory(launch) == null)
return null;
return Path.Combine(_combinedOperations.InstallDirectory(launch), "arma2oa.exe");
case LaunchTypes.Beta:
if (_combinedOperations.InstallDirectory(launch) == null)
return null;
return Path.Combine(_combinedOperations.InstallDirectory(launch), "Expansion", "beta", "arma2oa.exe");
default: return null;
}
};
_combinedOperations.IsGamePresent = launch =>
{
if (!ArmA2.IsGamePresent(launch) || !OperationArrowhead.IsGamePresent(launch))
return false;
return true;
};
_combinedOperations.EquivalentLaunch = launch =>
{
if (launch != LaunchTypes.Latest)
return launch;
Version releaseVersion = GetAssemblyVersion(_combinedOperations.ExecutableFile(LaunchTypes.Release));
Version betaVersion = GetAssemblyVersion(_combinedOperations.ExecutableFile(LaunchTypes.Beta));
if (releaseVersion < betaVersion)
return LaunchTypes.Beta;
return LaunchTypes.Release;
};
_combinedOperations.BaseArguments = launch =>
{
if (launch == LaunchTypes.Steam)
return "-applaunch 33930 ";
return "";
};
_combinedOperations.BaseMods = launch =>
{
string baseMods = "";
if (launch == LaunchTypes.Beta)
baseMods += "Expansion/beta;";
baseMods += "Expansion;ca";
return baseMods;
};
_combinedOperations.GameFolder = folder =>
{
switch (folder)
{
case "AddOns":
case "BattlEye":
case "BEsetup":
case "Common":
case "Campaigns":
case "DirectX":
case "Dta":
case "Keys":
case "Missions":
case "MPMissions":
case "userconfig":
case "BAF":
case "PMC":
return true;
default: return false;
}
};
}
return _combinedOperations;
}
}
private static Game _tkoh;
/// <summary>
/// Take On Helicopters
/// </summary>
public static Game TakeOnHelicopters
{
get
{
if (_tkoh == null)
{
_tkoh = new Game("Take On Helicopters");
_tkoh.InstallDirectory = launch =>
{
switch (launch)
{
case LaunchTypes.Steam:
case LaunchTypes.Beta:
case LaunchTypes.Release:
case LaunchTypes.Latest:
return Game.TakeOnHelicoptersDirectory;
default: return null;
}
};
_tkoh.ExecutableFile = launch =>
{
switch (launch)
{
case LaunchTypes.Steam:
return Path.Combine(SteamDirectory, "Steam.exe");
case LaunchTypes.Release:
if (_tkoh.InstallDirectory(launch) == null)
return null;
return Path.Combine(_tkoh.InstallDirectory(launch), "takeonh.exe");
default: return null;
}
};
_tkoh.IsGamePresent = launch =>
{
string exePath = _tkoh.ExecutableFile(launch);
if (exePath != null && File.Exists(exePath))
return true;
return false;
};
_tkoh.EquivalentLaunch = launch =>
{
if (launch != LaunchTypes.Latest)
return launch;
Version releaseVersion = GetAssemblyVersion(_tkoh.ExecutableFile(LaunchTypes.Release));
Version betaVersion = GetAssemblyVersion(_tkoh.ExecutableFile(LaunchTypes.Beta));
if (releaseVersion < betaVersion)
return LaunchTypes.Beta;
return LaunchTypes.Release;
};
_tkoh.BaseArguments = launch =>
{
if (launch == LaunchTypes.Steam)
return "-applaunch 65730 ";
return "";
};
_tkoh.BaseMods = launch =>
{
if (launch == LaunchTypes.Beta)
return "beta";
return "";
};
_tkoh.GameFolder = folder =>
{
switch (folder)
{
case "AddOns":
case "DirectX":
case "DLCsetup":
case "dll":
case "Dta":
case "Hinds":
case "jre":
case "Keys":
case "missions":
case "mpmissions":
case "Rearmed":
return true;
default: return false;
}
};
}
return _tkoh;
}
}
private static Game _tkoh_rearmed;
/// <summary>
/// Take On Helicopters: Rearmed
/// </summary>
public static Game TakeOnHelicoptersRearmed
{
get
{
if (_tkoh_rearmed == null)
{
_tkoh_rearmed = new Game("Take On Helicopters: Rearmed");
_tkoh_rearmed.InstallDirectory = launch =>
{
switch (launch)
{
case LaunchTypes.Steam:
case LaunchTypes.Beta:
case LaunchTypes.Release:
case LaunchTypes.Latest:
return Game.TakeOnHelicoptersDirectory;
default: return null;
}
};
_tkoh_rearmed.ExecutableFile = launch =>
{
switch (launch)
{
case LaunchTypes.Steam:
return Path.Combine(SteamDirectory, "Steam.exe");
case LaunchTypes.Release:
if (_tkoh_rearmed.InstallDirectory(launch) == null)
return null;
return Path.Combine(_tkoh_rearmed.InstallDirectory(launch), "takeonh.exe");
default: return null;
}
};
_tkoh_rearmed.IsGamePresent = launch =>
{
if (!CombinedOperations.IsGamePresent(launch) || !TakeOnHelicopters.IsGamePresent(launch))
return false;
return true;
};
_tkoh_rearmed.EquivalentLaunch = launch =>
{
if (launch != LaunchTypes.Latest)
return launch;
Version releaseVersion = GetAssemblyVersion(_tkoh_rearmed.ExecutableFile(LaunchTypes.Release));
Version betaVersion = GetAssemblyVersion(_tkoh_rearmed.ExecutableFile(LaunchTypes.Beta));
if (releaseVersion < betaVersion)
return LaunchTypes.Beta;
return LaunchTypes.Release;
};
_tkoh_rearmed.BaseArguments = launch =>
{
if (launch == LaunchTypes.Steam)
return "-applaunch 65730 ";
return "";
};
_tkoh_rearmed.BaseMods = launch =>
{
return ArmA2Directory + ";" +
OperationArrowheadDirectory + ";" +
Path.Combine(OperationArrowheadDirectory, "Expansion") + ";" +
TakeOnHelicoptersDirectory + ";" +
"Rearmed";
};
_tkoh_rearmed.GameFolder = folder =>
{
switch (folder)
{
case "AddOns":
case "DirectX":
case "DLCsetup":
case "dll":
case "Dta":
case "Hinds":
case "jre":
case "Keys":
case "missions":
case "mpmissions":
case "Rearmed":
case "BattlEye":
case "BEsetup":
case "Common":
case "Campaigns":
case "Missions":
case "MPMissions":
case "userconfig":
case "BAF":
case "PMC":
return true;
default: return false;
}
};
}
return _tkoh_rearmed;
}
}
#endregion
/// <summary>
/// Creates a new instance of the <see cref="Game"/> class
/// for internal use
/// </summary>
/// <param name="name">
/// The name of the game to create an instance of
/// </param>
private Game(string name)
{
Name = name;
}
/// <summary>
/// Creates a new instance of the <see cref="Game"/> class
/// which allows BISLib to launch a particular game
/// </summary>
/// <param name="name">The name of the game</param>
/// <param name="isGamePresent">
/// A function which will determine whether or not the game is installed
/// </param>
/// <param name="installDirectory">
/// A function which will retreive the install directory for the game
/// </param>
/// <param name="executableFile">
/// A function which will retreive the path to the game's executable file
/// </param>
/// <param name="equivalentLaunch">
/// A function which will convert a specified launch type into an equivalent launch type
/// for this game.
/// </param>
/// <param name="baseArguments">
/// The base arguments which are applied to the game's launch parameters
/// </param>
/// <param name="baseMods">
/// The base mods which are applied to the game's launch parameters
/// </param>
/// <param name="isGameFolder">
/// A function which determines whether or not a folder is one of the game's core folders
/// </param>
public Game(string name,
Func<LaunchTypes, bool> isGamePresent,
Func<LaunchTypes, string> installDirectory,
Func<LaunchTypes, string> executableFile,
Func<LaunchTypes, LaunchTypes> equivalentLaunch,
Func<LaunchTypes, string> baseArguments,
Func<LaunchTypes, string> baseMods,
Func<string, bool> isGameFolder
)
{
Name = name;
IsGamePresent = isGamePresent;
InstallDirectory = installDirectory;
ExecutableFile = executableFile;
EquivalentLaunch = equivalentLaunch;
BaseArguments = baseArguments;
BaseMods = baseMods;
GameFolder = isGameFolder;
}
/// <summary>
/// Human readable name for the game that can be used
/// for displaying the game in a list
/// </summary>
public string Name
{ get; private set; }
/// <summary>
/// Determines whether or not all of the required functions are
/// present in this game instance for the game to be launched.
/// </summary>
/// <remarks>
/// In other words, determines whether or not this is a valid
/// game definition or whether it has been poorly implemented
/// as a custom game (Assuming all included definitions are solid)
/// </remarks>
public bool RequiredFunctionsPresent
{
get
{
return
IsGamePresent != null &&
InstallDirectory != null &&
ExecutableFile != null &&
EquivalentLaunch != null &&
BaseArguments != null &&
BaseMods != null &&
GameFolder != null;
}
}
/// <summary>
/// Checks whether the <see cref="Game"/> is present in its default
/// directory for the given launch condition
/// </summary>
public Func<LaunchTypes, bool> IsGamePresent
{ get; set; }
/// <summary>
/// Gets the install directory for the current <see cref="Game"/>
/// and should return <c>null</c> if no directory could be found
/// </summary>
public Func<LaunchTypes, string> InstallDirectory
{ get; set; }
/// <summary>
/// Gets the full path to the executable file used by
/// the <see cref="Game"/> for the given <see cref="LaunchTypes"/>
/// </summary>
public Func<LaunchTypes, string> ExecutableFile
{ get; set; }
/// <summary>
/// Converts a specified launch type into one that can be launched
/// by the game launcher.
/// </summary>
/// <remarks>
/// Generally, this is used to change a <see cref="LaunchTypes.Latest"/>
/// value into either a <see cref="LaunchTypes.Release"/> or
/// <see cref="LaunchTypes.Beta"/> launch type which can then
/// be processed by the launch library.
/// </remarks>
public Func<LaunchTypes, LaunchTypes> EquivalentLaunch
{ get; set; }
/// <summary>
/// Gets the base arguments to be passed to the <see cref="ExecutableFile"/>
/// before any mods are added.
/// </summary>
public Func<LaunchTypes, string> BaseArguments
{ get; set; }
/// <summary>
/// Gets any base mods associated with this game which
/// should be added before any selected mods
/// </summary>
public Func<LaunchTypes, string> BaseMods
{ get; set; }
/// <summary>
/// Determines whether or not a folder is a game core
/// folder or not to prevent core folders from being
/// selected as 'mods'.
/// </summary>
public Func<string, bool> GameFolder
{ get; set; }
#region Utility Functions
/// <summary>
/// Gets the file version for a given assembly
/// </summary>
/// <param name="file">The file who's version should be determined</param>
/// <returns></returns>
private static Version GetAssemblyVersion(string file)
{
FileVersionInfo fi = FileVersionInfo.GetVersionInfo(file);
return new Version(fi.ProductVersion);
}
#endregion
#region Paths
private static string __steamDirectory = null;
private static string SteamDirectory
{
get
{
if (__steamDirectory == null)
{
try
{
if (IntPtr.Size == 4 && RegistryManager.IsPresent("HKLM\\SOFTWARE\\Valve\\Steam"))
{
__steamDirectory = RegistryManager.GetValue("HKLM\\SOFTWARE\\Valve\\Steam\\InstallPath").ToString();
}
else if (IntPtr.Size == 8 && RegistryManager.IsPresent("HKLM\\SOFTWARE\\Wow6432Node\\Valve\\Steam"))
{
__steamDirectory = RegistryManager.GetValue("HKLM\\SOFTWARE\\Wow6432Node\\Valve\\Steam\\InstallPath").ToString();
}
}
catch
{ }
}
return __steamDirectory;
}
}
private static string __arma2Directory = null;
private static string ArmA2Directory
{
get
{
if (__arma2Directory == null)
{
if (File.Exists(Path.Combine(Environment.CurrentDirectory, "arma2.exe")))
__arma2Directory = Environment.CurrentDirectory;
if (IntPtr.Size == 4 && RegistryManager.IsPresent("HKLM\\SOFTWARE\\Bohemia Interactive Studio\\ArmA 2"))
{
__arma2Directory = RegistryManager.GetValue("HKLM\\SOFTWARE\\Bohemia Interactive Studio\\ArmA 2\\Main").ToString();
}
else if (IntPtr.Size == 8 && RegistryManager.IsPresent("HKLM\\SOFTWARE\\Wow6432Node\\Bohemia Interactive Studio\\ArmA 2"))
{
__arma2Directory = RegistryManager.GetValue("HKLM\\SOFTWARE\\Wow6432Node\\Bohemia Interactive Studio\\ArmA 2\\Main").ToString();
}
}
return __arma2Directory;
}
}
private static string __oaDirectory = null;
private static string OperationArrowheadDirectory
{
get
{
if (__oaDirectory == null)
{
if (File.Exists(Path.Combine(Environment.CurrentDirectory, "arma2oa.exe")))
__oaDirectory = Environment.CurrentDirectory;
if (IntPtr.Size == 4 && RegistryManager.IsPresent("HKLM\\SOFTWARE\\Bohemia Interactive Studio\\ArmA 2 OA"))
{
__oaDirectory = RegistryManager.GetValue("HKLM\\SOFTWARE\\Bohemia Interactive Studio\\ArmA 2 OA\\Main").ToString();
}
else if (IntPtr.Size == 8 && RegistryManager.IsPresent("HKLM\\SOFTWARE\\Wow6432Node\\Bohemia Interactive Studio\\ArmA 2 OA"))
{
__oaDirectory = RegistryManager.GetValue("HKLM\\SOFTWARE\\Wow6432Node\\Bohemia Interactive Studio\\ArmA 2 OA\\Main").ToString();
}
}
return __oaDirectory;
}
}
private static string __tkohDirectory = null;
private static string TakeOnHelicoptersDirectory
{
get
{
if (__tkohDirectory == null)
{
if (File.Exists(Path.Combine(Environment.CurrentDirectory, "arma2.exe")))
__tkohDirectory = Environment.CurrentDirectory;
if (IntPtr.Size == 4 && RegistryManager.IsPresent("HKLM\\SOFTWARE\\Bohemia Interactive Studio\\Take On Helicopters"))
{
__tkohDirectory = RegistryManager.GetValue("HKLM\\SOFTWARE\\Bohemia Interactive Studio\\Take On Helicopters\\Main").ToString();
}
else if (IntPtr.Size == 8 && RegistryManager.IsPresent("HKLM\\SOFTWARE\\Wow6432Node\\Bohemia Interactive Studio\\Take On Helicopters"))
{
__tkohDirectory = RegistryManager.GetValue("HKLM\\SOFTWARE\\Wow6432Node\\Bohemia Interactive Studio\\Take On Helicopters\\Main").ToString();
}
}
return __tkohDirectory;
}
}
#endregion
}
}