-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameDetection.cs
98 lines (84 loc) · 2.5 KB
/
GameDetection.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
using System.Diagnostics;
namespace FFPR_Fix;
public enum GameVersion
{
Unknown = 0,
FF1 = 1 << 0,
FF2 = 1 << 1,
FF3 = 1 << 2,
FF4 = 1 << 3,
FF5 = 1 << 4,
FF6 = 1 << 5,
Any = int.MaxValue
}
public class GameDetection
{
private static GameVersion _version = GameVersion.Unknown;
public static GameVersion Version
{
get
{
if (_version == GameVersion.Unknown)
{
_version = GetGameVersion();
}
return _version;
}
private set => _version = value;
}
private static GameVersion GetGameVersion()
{
switch (GetProductName())
{
case "FINAL FANTASY":
return GameVersion.FF1;
case "FINAL FANTASY II":
return GameVersion.FF2;
case "FINAL FANTASY III":
return GameVersion.FF3;
case "FINAL FANTASY IV":
return GameVersion.FF4;
case "FINAL FANTASY V":
return GameVersion.FF5;
case "FINAL FANTASY VI":
return GameVersion.FF6;
}
switch (GetModuleFileName())
{
case "FINAL FANTASY":
return GameVersion.FF1;
case "FINAL FANTASY II":
return GameVersion.FF2;
case "FINAL FANTASY III":
return GameVersion.FF3;
case "FINAL FANTASY IV":
return GameVersion.FF4;
case "FINAL FANTASY V":
return GameVersion.FF5;
case "FINAL FANTASY VI":
return GameVersion.FF6;
}
return GameVersion.Unknown;
}
private static string GetProductName()
{
var fileInfo = FileVersionInfo.GetVersionInfo(BepInEx.Paths.ExecutablePath);
var productName = TrimAfterNullCharacter(fileInfo.ProductName);
Plugin.Log.LogDebug($"Product name: {productName}");
return productName;
}
private static string GetModuleFileName()
{
Plugin.Log.LogDebug($"Module name: {BepInEx.Paths.ProcessName}");
return BepInEx.Paths.ProcessName;
}
private static string TrimAfterNullCharacter(string input)
{
int nullCharIndex = input.IndexOf('\0');
if (nullCharIndex == -1)
{
return input;
}
return input.Substring(0, nullCharIndex);
}
}