From 4aa9aef3621294e391f1b323153f339601a61554 Mon Sep 17 00:00:00 2001 From: Ray Koopa Date: Sat, 12 Jan 2019 17:38:39 +0100 Subject: [PATCH] Update launcher for WWPA, supporting multiple executable paths. --- .../AssemblyInfo.cs | 28 +++++++ .../Config.cs | 6 +- ...auncherConfig.json => LauncherConfig.json} | 2 +- .../Program.cs | 76 +++++++++++++----- .../Properties/launchSettings.json | 2 +- .../Resources/Icon.ico | Bin 2238 -> 4286 bytes .../Syroot.Worms.OnlineWorms.Launcher.csproj | 20 ++--- 7 files changed, 96 insertions(+), 38 deletions(-) create mode 100644 src/Syroot.Worms.OnlineWorms.Launcher/AssemblyInfo.cs rename src/Syroot.Worms.OnlineWorms.Launcher/{OWLauncherConfig.json => LauncherConfig.json} (85%) diff --git a/src/Syroot.Worms.OnlineWorms.Launcher/AssemblyInfo.cs b/src/Syroot.Worms.OnlineWorms.Launcher/AssemblyInfo.cs new file mode 100644 index 0000000..309d94a --- /dev/null +++ b/src/Syroot.Worms.OnlineWorms.Launcher/AssemblyInfo.cs @@ -0,0 +1,28 @@ +using System.Reflection; + +namespace Syroot.Worms.OnlineWorms.Launcher +{ + /// + /// Represents entry assembly information. + /// + internal static class AssemblyInfo + { + // ---- FIELDS ------------------------------------------------------------------------------------------------- + + private static readonly Assembly _entryAssembly; + + // ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------ + + static AssemblyInfo() + { + _entryAssembly = Assembly.GetEntryAssembly(); + } + + // ---- PROPERTIES --------------------------------------------------------------------------------------------- + + /// + /// Gets the value of the . + /// + internal static string Title => _entryAssembly.GetCustomAttribute().Title; + } +} diff --git a/src/Syroot.Worms.OnlineWorms.Launcher/Config.cs b/src/Syroot.Worms.OnlineWorms.Launcher/Config.cs index 96abd0e..b740c91 100644 --- a/src/Syroot.Worms.OnlineWorms.Launcher/Config.cs +++ b/src/Syroot.Worms.OnlineWorms.Launcher/Config.cs @@ -1,4 +1,5 @@ -using System.Net; +using System.Collections.Generic; +using System.Net; namespace Syroot.Worms.OnlineWorms.Launcher { @@ -13,11 +14,12 @@ namespace Syroot.Worms.OnlineWorms.Launcher public string Password { get; set; } public uint PasswordKey { get; set; } - public string ExecutablePath { get; set; } = "DWait.exe"; + public string ExecutablePaths { get; set; } = "DWait.exe;Main.exe"; public string ExecutableArgs { get; set; } public string MappingName { get; set; } = "KG1234567890"; public bool StartSuspended { get; set; } + internal IList ExecutePathList => ExecutablePaths.Split(';'); internal IPEndPoint ServerEndPoint => new IPEndPoint(IPAddress.Parse(ServerIP), ServerPort); } } diff --git a/src/Syroot.Worms.OnlineWorms.Launcher/OWLauncherConfig.json b/src/Syroot.Worms.OnlineWorms.Launcher/LauncherConfig.json similarity index 85% rename from src/Syroot.Worms.OnlineWorms.Launcher/OWLauncherConfig.json rename to src/Syroot.Worms.OnlineWorms.Launcher/LauncherConfig.json index e14fe58..e5f0978 100644 --- a/src/Syroot.Worms.OnlineWorms.Launcher/OWLauncherConfig.json +++ b/src/Syroot.Worms.OnlineWorms.Launcher/LauncherConfig.json @@ -9,7 +9,7 @@ // Debugging settings (optional) "PasswordKey": 1000, // base value to encrypt and decrypt password in launch file mapping - "ExecutablePath": "DWait.exe", // relative or absolute path to game executable + "ExecutablePaths": "DWait.exe;Main.exe", // relative or absolute paths to game executables to consider "ExecutableArgs": "", // additional arguments appended to command line "MappingName": "KG1234567890", // launch file mapping identifier used and passed as first argument to game "StartSuspended": false // true to create, but wait for confirmation to run the game process (to attach debuggers) diff --git a/src/Syroot.Worms.OnlineWorms.Launcher/Program.cs b/src/Syroot.Worms.OnlineWorms.Launcher/Program.cs index 0049f14..db0709b 100644 --- a/src/Syroot.Worms.OnlineWorms.Launcher/Program.cs +++ b/src/Syroot.Worms.OnlineWorms.Launcher/Program.cs @@ -1,5 +1,7 @@ using System; +using System.Diagnostics; using System.IO; +using System.Linq; using System.Windows.Forms; using Microsoft.Extensions.Configuration; @@ -15,35 +17,30 @@ namespace Syroot.Worms.OnlineWorms.Launcher { // Create and read the configuration. Config config = new ConfigurationBuilder() - .AddJsonFile("OWLauncherConfig.json", true) + .AddJsonFile("LauncherConfig.json", true) .Build() .Get(); - // Create the launch configuration. - LaunchConfig launchConfig = new LaunchConfig - { - ServerEndPoint = config.ServerEndPoint, - UserName = config.UserName - }; - launchConfig.SetPassword(config.Password, config.PasswordKey); + // Check which of the game executables is available. + string executablePath = config.ExecutePathList.FirstOrDefault(x => File.Exists(x)); + if (executablePath == null) + throw new InvalidOperationException("Game executable was not found."); + // Kill any possibly existing process. + KillProcesses(Path.GetFileNameWithoutExtension(executablePath)); - // Map the launch configuration to pass it to the process. + // Create the launch configuration and map it. + LaunchConfig launchConfig = CreateLaunchConfig(config); using (launchConfig.CreateMappedFile(config.MappingName)) { - // Create the process. - string commandLine = String.Join(" ", config.MappingName, config.ExecutableArgs).TrimEnd(); - string directory = Path.GetDirectoryName(config.ExecutablePath); - if (String.IsNullOrEmpty(directory)) - directory = null; - NativeProcessFlags flags = NativeProcessFlags.InheritHandles; - if (config.StartSuspended) - flags |= NativeProcessFlags.StartSuspended; - NativeProcess process = new NativeProcess(config.ExecutablePath, commandLine, directory, flags); + // Create and run the process. + NativeProcess process = CreateProcess(executablePath, + String.Join(" ", config.MappingName, config.ExecutableArgs).TrimEnd(), + config.StartSuspended); if (config.StartSuspended) { - if (MessageBox.Show("Game process is paused. Click OK to resume or Cancel to kill it.", - Application.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Information) - == DialogResult.OK) + if (ShowMessage(MessageBoxIcon.Information, + "Game process has been created and is paused. Click OK to resume or Cancel to kill it.", + MessageBoxButtons.OKCancel) == DialogResult.OK) { process.Resume(); } @@ -52,14 +49,49 @@ namespace Syroot.Worms.OnlineWorms.Launcher process.Terminate(); } } - process.WaitForExit(); } } catch (Exception ex) { + ShowMessage(MessageBoxIcon.Error, ex.Message, MessageBoxButtons.OK); Console.WriteLine(ex); } } + + private static void KillProcesses(string processName) + { + foreach (Process process in Process.GetProcessesByName(processName)) + process.Kill(); + } + + private static LaunchConfig CreateLaunchConfig(Config config) + { + LaunchConfig launchConfig = new LaunchConfig + { + ServerEndPoint = config.ServerEndPoint, + UserName = config.UserName + }; + launchConfig.SetPassword(config.Password, config.PasswordKey); + return launchConfig; + } + + private static NativeProcess CreateProcess(string executablePath, string commandLine, bool startSuspended) + { + string directory = Path.GetDirectoryName(executablePath); + if (String.IsNullOrEmpty(directory)) + directory = null; + + NativeProcessFlags flags = NativeProcessFlags.InheritHandles; + if (startSuspended) + flags |= NativeProcessFlags.StartSuspended; + + return new NativeProcess(executablePath, commandLine, directory, flags); + } + + private static DialogResult ShowMessage(MessageBoxIcon icon, string text, MessageBoxButtons buttons) + { + return MessageBox.Show(text, AssemblyInfo.Title, buttons, icon); + } } } diff --git a/src/Syroot.Worms.OnlineWorms.Launcher/Properties/launchSettings.json b/src/Syroot.Worms.OnlineWorms.Launcher/Properties/launchSettings.json index 681c7d3..c3f017a 100644 --- a/src/Syroot.Worms.OnlineWorms.Launcher/Properties/launchSettings.json +++ b/src/Syroot.Worms.OnlineWorms.Launcher/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "Syroot.OnlineWorms.Launcher": { "commandName": "Project", - "workingDirectory": "C:\\Games\\Online Worms" + "workingDirectory": "C:\\Games\\WWP Aqua" } } } \ No newline at end of file diff --git a/src/Syroot.Worms.OnlineWorms.Launcher/Resources/Icon.ico b/src/Syroot.Worms.OnlineWorms.Launcher/Resources/Icon.ico index 3d9d7c0fa2ae04031f22830c64cb73ded818b45e..67e55e9e27b0263b61ab7c7b7d2f1389767b9700 100644 GIT binary patch literal 4286 zcmc(jd3;UR7ROJuW)h)-im6&Pm5*F=`_d5lQJQD!M?7MBxJXrr8lpTyC5nVJhPp_Q zkb#(940&d1c-5#-5@JZanyIO;9_r@%);f77xrz9vthT{^QHGHFE1}%#;@YhFrVGt{|i2gI8WqG zOdISoS8?qbWd9pZ{Q^JUgQKEkvB|Q-;#)S@ZE4u;B57@6i}E$@#qllnm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L zmXd?O)0Ckt?a(FAO@pD(p}9F(nkhpdmXVD`66o;ydrwKol#YF;cc=INzxRE=``(j; zSmJ6n1@{&4%Zd z$zjQ1v1NfHha-n0ha-o>mI{s>h8%_*22;8mjvR&@hLT*GyDcGk78he%UQ->Y$gP-V zOHFPClOm}ifr3eqTVX1KC~_-u+wHKq(aEpKugGt@ZB)g+Jql0m zW*ezNNxl-c5{{C5c54j>H7MaI4F@k~x0^*JEF~-@5G4ui5rCy+VacQtp@fAGojB}C z2}^0}VOh*+FuQ;TgN8xFpkdH3Xc+8qf}w;#!=Pa(VIT~h`7mf0Gz=OBLetS<&@gBi zGyt0XCBZZcHIs5;D;q>nRJ`{`Q|WnIqm5Q#U2flpC-_tA@BDFB4vK-C?zED@hY72` zV)?aNuoE@zNvq1OWYN;QjCbW*nc~mKQAJJ*r94k2{kW|g@jf$;~}OU+NJRfBW$F z^QbZR-SFYu1gHhrn@i1RbNy1VI)CUnauPKviQ^=vyhU2`Sxx9>r*k;#UQB#a$!U3&(R%cHi@(h0_RvqMdGGuO7u=K?8vFs!OW>@{L1Xad29W^k?B&W zC_2*HgVO(y5M65Q4Jo*Pu1dTQ)swb1(fczPVprcN-U0*zrC-*u{K+DTovT|`W9 z0XT6S$Db6#zE^ksfiw(>=X(9&uwb@3Q4-E-zb`$`=jvdP$}kBN&uj0o+G+3Y^?41a z>Us4#^^-|5Y9+z`s^@vUe!bmp_fwY{uB?YHZ%s5NSgcM`vMZ-2kn+x{@YPOAmu@vU)VXJex$w|no~vazyd y9^G2d7|qA_CzymE?Bzwn=KMzyi%sh#+48}`!8adgWm%ZG!RJ~S)c8C2U)#S8nz7^n diff --git a/src/Syroot.Worms.OnlineWorms.Launcher/Syroot.Worms.OnlineWorms.Launcher.csproj b/src/Syroot.Worms.OnlineWorms.Launcher/Syroot.Worms.OnlineWorms.Launcher.csproj index a2c8642..2075c66 100644 --- a/src/Syroot.Worms.OnlineWorms.Launcher/Syroot.Worms.OnlineWorms.Launcher.csproj +++ b/src/Syroot.Worms.OnlineWorms.Launcher/Syroot.Worms.OnlineWorms.Launcher.csproj @@ -2,16 +2,16 @@ false Resources\Icon.ico - OWLauncher - Online Worms Launcher + Launcher + Mgame Worms Launcher Syroot (c) Syroot, licensed under MIT None - Game launcher for Online Worms + Game launcher for Mgame Worms games WinExe Online Worms Launcher net461 - 0.1.0-alpha1 + 0.5.0 app.manifest @@ -20,13 +20,9 @@ - - - - - - - PreserveNewest - + + + PreserveNewest +