This repository has been archived by the owner on Aug 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Program.cs
158 lines (141 loc) · 5.92 KB
/
Program.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
using BmLauncherAsylumNET6.infrastructure;
using BmLauncherAsylumNET6.ui;
using NLog;
using NLog.Config;
using NLog.Targets;
using System.Diagnostics;
using System.Globalization;
namespace BmLauncherAsylumNET6
{
/// <summary>
/// Replacement Application for the original Batman: Arkham Asylum BmLauncher
/// Offers more configuration options, enables compatibility with High-Res Texture Packs
/// and automatically takes care of the ReadOnly properties of each file, removing
/// any requirement to manually edit .ini files. Guarantees a much more comfortable user experience.
/// @author frofoo (https://steamcommunity.com/id/frofoo)
/// </summary>
internal static class Program
{
// logger for easy debugging
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public static Factory MyFactory;
public static BmLauncherForm Client;
public static NvidiaWorker NvWorker;
private static readonly string CurrentTime = DateTime.Now.ToString("dd-MM-yy__hh-mm-ss");
// Mutex with this applications GUID as name
private static readonly Mutex Mutex = new(true, "{cbb275f6-724f-4e82-a403-e333dcf6c0bf}");
[STAThread]
private static void Main(string[] args)
{
if (Mutex.WaitOne(TimeSpan.Zero, true))
{
SetupLogger();
logger.Info("Main - Starting logs at {0}, on {1}.",
DateTime.Now.ToString("HH:mm:ss"), DateTime.Now.ToString("D", new CultureInfo("en-GB")));
if (args.Contains("-nolauncher"))
{
Mutex.ReleaseMutex();
LauncherBypass();
}
else
{
RunWindow();
Mutex.ReleaseMutex();
}
}
else
{
NativeMethods.PostMessage((IntPtr)NativeMethods.HwndBroadcast, NativeMethods.WmShowme, IntPtr.Zero,
IntPtr.Zero);
}
}
private static void SetupLogger()
{
LoggingConfiguration config = new();
ConsoleTarget logconsole = new("logconsole");
if (!Directory.Exists("logs"))
{
Directory.CreateDirectory("logs");
}
FileTarget logfile = new("logfile")
{
FileName = Directory.GetCurrentDirectory() + "\\logs\\bmlauncher_report__" + CurrentTime + ".log"
};
DirectoryInfo logDirectory = new(Directory.GetCurrentDirectory() + "\\logs");
DateTime oldestAllowedArchive = DateTime.Now - new TimeSpan(3, 0, 0, 0);
foreach (FileInfo file in logDirectory.GetFiles())
{
if (file.CreationTime < oldestAllowedArchive)
{
file.Delete();
}
}
config.AddRule(LogLevel.Debug, LogLevel.Warn, logconsole);
config.AddRule(LogLevel.Debug, LogLevel.Warn, logfile);
LogManager.Configuration = config;
}
private static void DetectTexmod()
{
DirectoryInfo d = new(Directory.GetCurrentDirectory());
FileInfo[] Files = d.GetFiles("*.exe");
foreach (FileInfo f in Files)
{
if (f.Name == "texmod_autoload.exe")
{
Factory.TexmodDetected = true;
}
}
}
public static void LauncherBypass() // Edited from BmLauncherForm.launchButton_Click
{
logger.Info("Launcher bypassed: No configuration changes made.");
using (Process launchBmGame = new())
{
try
{
Factory.InputFileInfo.IsReadOnly = true;
if (Factory.TexmodDetected)
{
launchBmGame.StartInfo.FileName = "texmod_autoload.exe";
launchBmGame.StartInfo.CreateNoWindow = true;
launchBmGame.Start();
logger.Info("Launching Texmod. Logging has concluded at {0}, on {1}.",
DateTime.Now.ToString("HH:mm:ss"), DateTime.Now.ToString("D", new CultureInfo("en-GB")));
LogManager.Flush();
Application.Exit();
}
else
{
launchBmGame.StartInfo.FileName = "ShippingPC-BmGame.exe";
launchBmGame.StartInfo.CreateNoWindow = true;
launchBmGame.Start();
logger.Info("Launching game application. Logging has concluded at {0}, on {1}.",
DateTime.Now.ToString("HH:mm:ss"), DateTime.Now.ToString("D", new CultureInfo("en-GB")));
LogManager.Flush();
Application.Exit();
}
}
catch (Exception)
{
MessageBox.Show(
"Couldn't find ShippingPC_BmGame.exe or texmod_autoload.exe.\r\nPlease place the Launcher files in the correct folder.\r\n" +
"\r\nThe correct install folder is: \\Batman Arkham Asylum GOTY\\Binaries.",
@"Could not start game!",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
public static void RunWindow()
{
new SysResolutions().getResolutions();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Client = new BmLauncherForm();
DetectTexmod();
MyFactory = new Factory(Client);
MyFactory.readFiles();
Application.Run(Client);
}
}
}