mirror of
https://gitlab.com/Syroot/Worms.git
synced 2025-01-13 15:27:59 +03:00
Update launcher for WWPA, supporting multiple executable paths.
This commit is contained in:
parent
dac33e441a
commit
4aa9aef362
28
src/Syroot.Worms.OnlineWorms.Launcher/AssemblyInfo.cs
Normal file
28
src/Syroot.Worms.OnlineWorms.Launcher/AssemblyInfo.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace Syroot.Worms.OnlineWorms.Launcher
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents entry assembly information.
|
||||
/// </summary>
|
||||
internal static class AssemblyInfo
|
||||
{
|
||||
// ---- FIELDS -------------------------------------------------------------------------------------------------
|
||||
|
||||
private static readonly Assembly _entryAssembly;
|
||||
|
||||
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------
|
||||
|
||||
static AssemblyInfo()
|
||||
{
|
||||
_entryAssembly = Assembly.GetEntryAssembly();
|
||||
}
|
||||
|
||||
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Gets the value of the <see cref="AssemblyTitleAttribute"/>.
|
||||
/// </summary>
|
||||
internal static string Title => _entryAssembly.GetCustomAttribute<AssemblyTitleAttribute>().Title;
|
||||
}
|
||||
}
|
@ -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<string> ExecutePathList => ExecutablePaths.Split(';');
|
||||
internal IPEndPoint ServerEndPoint => new IPEndPoint(IPAddress.Parse(ServerIP), ServerPort);
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
@ -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<Config>();
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
"profiles": {
|
||||
"Syroot.OnlineWorms.Launcher": {
|
||||
"commandName": "Project",
|
||||
"workingDirectory": "C:\\Games\\Online Worms"
|
||||
"workingDirectory": "C:\\Games\\WWP Aqua"
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 2.2 KiB After Width: | Height: | Size: 4.2 KiB |
@ -2,16 +2,16 @@
|
||||
<PropertyGroup>
|
||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||
<ApplicationIcon>Resources\Icon.ico</ApplicationIcon>
|
||||
<AssemblyName>OWLauncher</AssemblyName>
|
||||
<AssemblyTitle>Online Worms Launcher</AssemblyTitle>
|
||||
<AssemblyName>Launcher</AssemblyName>
|
||||
<AssemblyTitle>Mgame Worms Launcher</AssemblyTitle>
|
||||
<Authors>Syroot</Authors>
|
||||
<Copyright>(c) Syroot, licensed under MIT</Copyright>
|
||||
<DebugType Condition="'$(Configuration)'=='Release'">None</DebugType>
|
||||
<Description>Game launcher for Online Worms</Description>
|
||||
<Description>Game launcher for Mgame Worms games</Description>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<ProductName>Online Worms Launcher</ProductName>
|
||||
<TargetFrameworks>net461</TargetFrameworks>
|
||||
<Version>0.1.0-alpha1</Version>
|
||||
<Version>0.5.0</Version>
|
||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
@ -20,13 +20,9 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" />
|
||||
<ProjectReference Include="..\Syroot.Worms\Syroot.Worms.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Update="OWLauncherConfig.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<None Update="LauncherConfig.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
Loading…
x
Reference in New Issue
Block a user