mirror of
https://gitlab.com/Syroot/Worms.git
synced 2025-01-15 00:08:02 +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
|
namespace Syroot.Worms.OnlineWorms.Launcher
|
||||||
{
|
{
|
||||||
@ -13,11 +14,12 @@ namespace Syroot.Worms.OnlineWorms.Launcher
|
|||||||
public string Password { get; set; }
|
public string Password { get; set; }
|
||||||
public uint PasswordKey { 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 ExecutableArgs { get; set; }
|
||||||
public string MappingName { get; set; } = "KG1234567890";
|
public string MappingName { get; set; } = "KG1234567890";
|
||||||
public bool StartSuspended { get; set; }
|
public bool StartSuspended { get; set; }
|
||||||
|
|
||||||
|
internal IList<string> ExecutePathList => ExecutablePaths.Split(';');
|
||||||
internal IPEndPoint ServerEndPoint => new IPEndPoint(IPAddress.Parse(ServerIP), ServerPort);
|
internal IPEndPoint ServerEndPoint => new IPEndPoint(IPAddress.Parse(ServerIP), ServerPort);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
// Debugging settings (optional)
|
// Debugging settings (optional)
|
||||||
"PasswordKey": 1000, // base value to encrypt and decrypt password in launch file mapping
|
"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
|
"ExecutableArgs": "", // additional arguments appended to command line
|
||||||
"MappingName": "KG1234567890", // launch file mapping identifier used and passed as first argument to game
|
"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)
|
"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;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
|
||||||
@ -15,35 +17,30 @@ namespace Syroot.Worms.OnlineWorms.Launcher
|
|||||||
{
|
{
|
||||||
// Create and read the configuration.
|
// Create and read the configuration.
|
||||||
Config config = new ConfigurationBuilder()
|
Config config = new ConfigurationBuilder()
|
||||||
.AddJsonFile("OWLauncherConfig.json", true)
|
.AddJsonFile("LauncherConfig.json", true)
|
||||||
.Build()
|
.Build()
|
||||||
.Get<Config>();
|
.Get<Config>();
|
||||||
|
|
||||||
// Create the launch configuration.
|
// Check which of the game executables is available.
|
||||||
LaunchConfig launchConfig = new LaunchConfig
|
string executablePath = config.ExecutePathList.FirstOrDefault(x => File.Exists(x));
|
||||||
{
|
if (executablePath == null)
|
||||||
ServerEndPoint = config.ServerEndPoint,
|
throw new InvalidOperationException("Game executable was not found.");
|
||||||
UserName = config.UserName
|
// Kill any possibly existing process.
|
||||||
};
|
KillProcesses(Path.GetFileNameWithoutExtension(executablePath));
|
||||||
launchConfig.SetPassword(config.Password, config.PasswordKey);
|
|
||||||
|
|
||||||
// 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))
|
using (launchConfig.CreateMappedFile(config.MappingName))
|
||||||
{
|
{
|
||||||
// Create the process.
|
// Create and run the process.
|
||||||
string commandLine = String.Join(" ", config.MappingName, config.ExecutableArgs).TrimEnd();
|
NativeProcess process = CreateProcess(executablePath,
|
||||||
string directory = Path.GetDirectoryName(config.ExecutablePath);
|
String.Join(" ", config.MappingName, config.ExecutableArgs).TrimEnd(),
|
||||||
if (String.IsNullOrEmpty(directory))
|
config.StartSuspended);
|
||||||
directory = null;
|
|
||||||
NativeProcessFlags flags = NativeProcessFlags.InheritHandles;
|
|
||||||
if (config.StartSuspended)
|
|
||||||
flags |= NativeProcessFlags.StartSuspended;
|
|
||||||
NativeProcess process = new NativeProcess(config.ExecutablePath, commandLine, directory, flags);
|
|
||||||
if (config.StartSuspended)
|
if (config.StartSuspended)
|
||||||
{
|
{
|
||||||
if (MessageBox.Show("Game process is paused. Click OK to resume or Cancel to kill it.",
|
if (ShowMessage(MessageBoxIcon.Information,
|
||||||
Application.ProductName, MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
|
"Game process has been created and is paused. Click OK to resume or Cancel to kill it.",
|
||||||
== DialogResult.OK)
|
MessageBoxButtons.OKCancel) == DialogResult.OK)
|
||||||
{
|
{
|
||||||
process.Resume();
|
process.Resume();
|
||||||
}
|
}
|
||||||
@ -52,14 +49,49 @@ namespace Syroot.Worms.OnlineWorms.Launcher
|
|||||||
process.Terminate();
|
process.Terminate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
process.WaitForExit();
|
process.WaitForExit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
ShowMessage(MessageBoxIcon.Error, ex.Message, MessageBoxButtons.OK);
|
||||||
Console.WriteLine(ex);
|
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": {
|
"profiles": {
|
||||||
"Syroot.OnlineWorms.Launcher": {
|
"Syroot.OnlineWorms.Launcher": {
|
||||||
"commandName": "Project",
|
"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>
|
<PropertyGroup>
|
||||||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
|
||||||
<ApplicationIcon>Resources\Icon.ico</ApplicationIcon>
|
<ApplicationIcon>Resources\Icon.ico</ApplicationIcon>
|
||||||
<AssemblyName>OWLauncher</AssemblyName>
|
<AssemblyName>Launcher</AssemblyName>
|
||||||
<AssemblyTitle>Online Worms Launcher</AssemblyTitle>
|
<AssemblyTitle>Mgame Worms Launcher</AssemblyTitle>
|
||||||
<Authors>Syroot</Authors>
|
<Authors>Syroot</Authors>
|
||||||
<Copyright>(c) Syroot, licensed under MIT</Copyright>
|
<Copyright>(c) Syroot, licensed under MIT</Copyright>
|
||||||
<DebugType Condition="'$(Configuration)'=='Release'">None</DebugType>
|
<DebugType Condition="'$(Configuration)'=='Release'">None</DebugType>
|
||||||
<Description>Game launcher for Online Worms</Description>
|
<Description>Game launcher for Mgame Worms games</Description>
|
||||||
<OutputType>WinExe</OutputType>
|
<OutputType>WinExe</OutputType>
|
||||||
<ProductName>Online Worms Launcher</ProductName>
|
<ProductName>Online Worms Launcher</ProductName>
|
||||||
<TargetFrameworks>net461</TargetFrameworks>
|
<TargetFrameworks>net461</TargetFrameworks>
|
||||||
<Version>0.1.0-alpha1</Version>
|
<Version>0.5.0</Version>
|
||||||
<ApplicationManifest>app.manifest</ApplicationManifest>
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -20,12 +20,8 @@
|
|||||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
|
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" />
|
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.2.0" />
|
||||||
<ProjectReference Include="..\Syroot.Worms\Syroot.Worms.csproj" />
|
<ProjectReference Include="..\Syroot.Worms\Syroot.Worms.csproj" />
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
|
||||||
<Reference Include="System.Windows.Forms" />
|
<Reference Include="System.Windows.Forms" />
|
||||||
</ItemGroup>
|
<None Update="LauncherConfig.json">
|
||||||
<ItemGroup>
|
|
||||||
<None Update="OWLauncherConfig.json">
|
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user