Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ Arguments (case-insensitive):
- `-describe-target`: validate and describe the game without requiring a payload, copying files or creating a shortcut. Prints one JSON object with `GameDirectory` (absolute path), `ModDirectory` and `LauncherPath`. Assumes a complete payload containing both launchers; ordinary installation still falls back to the blob launcher when the normal payload launcher is absent.
- `-include-debug-symbols`: also copy root `.pdb` files when installing, retaining their names even when `MetaHook.exe` is renamed to `svencoop.exe`. Normal installations continue to omit root symbols.
- `-help`: print usage.
- `-plugins-only`: deploy a standalone plugin payload into an existing MetaHook installation. Accepts `-describe-target` to validate/query that installation, or `-include-debug-symbols` when installing. Cannot be combined with `-uninstall`.

Plugin-only payloads require `install/output/svencoop/metahook/plugins/*.dll`, but no launcher. The existing launcher and `<moddir>/metahook/` must exist. Common resources are mapped to the selected mod as in a full install, including plugin PDBs and dependency libraries under the mod directory. Root executables, DLLs and PDBs are never copied; plugin lists and their templates are neither overwritten, created nor deleted. No shortcut is created. Install MetaHook and enable the plugin in `plugins.lst` first; this mode does not install missing runtime dependencies or enable plugins automatically.

```powershell
.\MetahookInstallerCLI.exe -appid 225840 -plugins-only -describe-target
.\MetahookInstallerCLI.exe -appid 225840 -plugins-only -include-debug-symbols
```

`-uninstall`, `-describe-target` and `-include-debug-symbols` are mutually exclusive. Query errors go to stderr and return exit code `1`. Omitting `-gamedir` also enables Steam discovery in query mode:

Expand Down
18 changes: 15 additions & 3 deletions src/MetahookInstallerCLI/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ public sealed record CommandLineOptions(
bool Uninstall,
bool ShowHelp,
bool DescribeTarget = false,
bool IncludeDebugSymbols = false)
bool IncludeDebugSymbols = false,
bool PluginsOnly = false)
{
public const string Usage =
"Usage: MetahookInstallerCLI -appid <appid> [-gamedir <gamedir>] [-moddir <moddir>] [-uninstall | -describe-target | -include-debug-symbols]\n" +
"Usage: MetahookInstallerCLI -appid <appid> [-gamedir <gamedir>] [-moddir <moddir>] [-plugins-only] [-uninstall | -describe-target | -include-debug-symbols]\n" +
" -appid <appid> Steam app ID of the game, e.g. 225840 (Sven Co-op) or 70 (Half-Life).\n" +
" -gamedir <gamedir> Game root directory. Defaults to the Steam install directory of the app.\n" +
" -moddir <moddir> Mod directory under the game root. Defaults to the app's base mod.\n" +
" -uninstall Remove MetaHook instead of installing it.\n" +
" -describe-target Print target JSON without installing (assumes both launchers in payload).\n" +
" -include-debug-symbols Also install root PDB files.\n" +
" -plugins-only Update plugins/resources in an existing MetaHook installation; keep root files and plugin lists.\n" +
" -help Show this help.";

private static readonly HashSet<string> ValueKeys = new(StringComparer.OrdinalIgnoreCase)
Expand All @@ -40,6 +42,7 @@ public static CommandLineOptions Parse(string[] args)
var uninstall = false;
var describeTarget = false;
var includeDebugSymbols = false;
var pluginsOnly = false;
for (var i = 0; i < args.Length; i++)
{
var arg = args[i];
Expand Down Expand Up @@ -72,6 +75,12 @@ public static CommandLineOptions Parse(string[] args)
continue;
}

if (key.Equals("plugins-only", StringComparison.OrdinalIgnoreCase))
{
pluginsOnly = true;
continue;
}

if (!ValueKeys.Contains(key))
{
throw new ArgumentException($"Unknown argument '{arg}'.");
Expand All @@ -97,6 +106,8 @@ public static CommandLineOptions Parse(string[] args)

if ((uninstall && (describeTarget || includeDebugSymbols)) || (describeTarget && includeDebugSymbols))
throw new ArgumentException("-uninstall, -describe-target and -include-debug-symbols cannot be combined.");
if (uninstall && pluginsOnly)
throw new ArgumentException("-plugins-only cannot be combined with -uninstall.");

return new CommandLineOptions(
appId,
Expand All @@ -105,7 +116,8 @@ public static CommandLineOptions Parse(string[] args)
uninstall,
false,
describeTarget,
includeDebugSymbols);
includeDebugSymbols,
pluginsOnly);
}

// findGameDirectory is only queried when -gamedir is omitted.
Expand Down
11 changes: 9 additions & 2 deletions src/MetahookInstallerCLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
if (options.DescribeTarget)
{
var gameDirectory = Path.GetFullPath(target.GameDirectory);
var launcherPath = MetahookSetup.DescribeLauncherPath(gameDirectory, target.ModDirectory);
var launcherPath = MetahookSetup.DescribeLauncherPath(gameDirectory, target.ModDirectory, options.PluginsOnly);
Console.WriteLine(JsonSerializer.Serialize(new
{
GameDirectory = gameDirectory,
Expand Down Expand Up @@ -58,9 +58,16 @@
return 0;
}

var source = InstallPayload.FindApplicationSourceDirectory()
var source = InstallPayload.FindApplicationSourceDirectory(options.PluginsOnly)
?? throw new DirectoryNotFoundException(
"The install/output folder cannot be located next to MetahookInstallerCLI.exe. Please extract the complete archive before running the programme.");
if (options.PluginsOnly)
{
var existingLauncher = MetahookSetup.InstallPlugins(source, target.GameDirectory, target.ModDirectory);
Console.WriteLine($"Updated plugins for {target.GameName}: {Path.Combine(target.GameDirectory, target.ModDirectory)}");
Console.WriteLine($"Launcher: {existingLauncher}");
return 0;
}
var launcher = MetahookSetup.Install(source, target.GameDirectory, target.ModDirectory, options.IncludeDebugSymbols);
var shortcut = MetahookSetup.CreateShortcut(shortcutDirectory, target.GameName, launcher,
target.GameDirectory, target.ModDirectory);
Expand Down
65 changes: 46 additions & 19 deletions src/MetahookInstallerCore/InstallPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@ namespace MetahookInstaller;
public static class InstallPayload
{
// Release builds only look next to the executable; Debug builds also search its ancestors.
public static string? FindApplicationSourceDirectory()
public static string? FindApplicationSourceDirectory(bool pluginsOnly = false)
{
#if DEBUG
return FindSourceDirectory(AppContext.BaseDirectory, true);
return FindSourceDirectory(AppContext.BaseDirectory, true, pluginsOnly);
#else
return FindSourceDirectory(AppContext.BaseDirectory, false);
return FindSourceDirectory(AppContext.BaseDirectory, false, pluginsOnly);
#endif
}

public static string? FindSourceDirectory(string applicationDirectory, bool searchParents)
public static string? FindSourceDirectory(string applicationDirectory, bool searchParents, bool pluginsOnly = false)
{
DirectoryInfo? directory = new(Path.GetFullPath(applicationDirectory));
while (directory != null)
{
var source = Path.Combine(directory.FullName, "install", "output");
if (File.Exists(Path.Combine(source, "MetaHook.exe")) ||
File.Exists(Path.Combine(source, "MetaHook_blob.exe")))
if (pluginsOnly ? HasPlugins(source) :
File.Exists(Path.Combine(source, "MetaHook.exe")) || File.Exists(Path.Combine(source, "MetaHook_blob.exe")))
return source;
if (!searchParents)
break;
Expand All @@ -39,33 +39,53 @@ public static string GetLauncherPath(string gameDirectory, string modDirectory,
isNonBlobEngine ? (isSvenCoop ? "svencoop.exe" : "MetaHook.exe") : "MetaHook_blob.exe");
}

public static string Install(string source, string gameDirectory, string modDirectory,
bool isNonBlobEngine, bool needsSdl, bool includeDebugSymbols = false)
private static bool HasPlugins(string source)
{
var normalLauncher = Path.Combine(source, "MetaHook.exe");
isNonBlobEngine = isNonBlobEngine && File.Exists(normalLauncher);
var sourceLauncher = isNonBlobEngine ? normalLauncher : Path.Combine(source, "MetaHook_blob.exe");
if (!File.Exists(sourceLauncher))
throw new FileNotFoundException("Could not find the required MetaHook launcher.", sourceLauncher);
var plugins = Path.Combine(source, "svencoop", "metahook", "plugins");
return Directory.Exists(plugins) && Directory.EnumerateFiles(plugins)
.Any(file => Path.GetExtension(file).Equals(".dll", StringComparison.OrdinalIgnoreCase));
}

public static void InstallPlugins(string source, string gameDirectory, string modDirectory)
{
if (!HasPlugins(source))
throw new DirectoryNotFoundException("Plugin payload must contain svencoop/metahook/plugins/*.dll.");
CopyResources(source, gameDirectory, modDirectory, preservePluginLists: true);
}

private static void CopyResources(string source, string gameDirectory, string modDirectory, bool preservePluginLists = false)
{
var isSvenCoop = modDirectory.Equals("svencoop", StringComparison.OrdinalIgnoreCase);
var targetLauncher = GetLauncherPath(gameDirectory, modDirectory, isNonBlobEngine);
var commonResources = Path.Combine(source, "svencoop");
if (Directory.Exists(commonResources))
CopyDirectory(commonResources, Path.Combine(gameDirectory, modDirectory));
CopyDirectory(commonResources, Path.Combine(gameDirectory, modDirectory), preservePluginLists);

foreach (var folder in Directory.GetDirectories(source).Where(directory =>
Path.GetFileName(directory).Equals(modDirectory, StringComparison.OrdinalIgnoreCase) ||
Path.GetFileName(directory).StartsWith(modDirectory + "_", StringComparison.OrdinalIgnoreCase)))
{
if (isSvenCoop && Path.GetFileName(folder).Equals("svencoop", StringComparison.OrdinalIgnoreCase))
continue;
CopyDirectory(folder, Path.Combine(gameDirectory, Path.GetFileName(folder)));
CopyDirectory(folder, Path.Combine(gameDirectory, Path.GetFileName(folder)), preservePluginLists);
}

var platform = Path.Combine(source, "platform");
if (isSvenCoop && Directory.Exists(platform))
CopyDirectory(platform, Path.Combine(gameDirectory, "platform"));
CopyDirectory(platform, Path.Combine(gameDirectory, "platform"), preservePluginLists);
}

public static string Install(string source, string gameDirectory, string modDirectory,
bool isNonBlobEngine, bool needsSdl, bool includeDebugSymbols = false)
{
var normalLauncher = Path.Combine(source, "MetaHook.exe");
isNonBlobEngine = isNonBlobEngine && File.Exists(normalLauncher);
var sourceLauncher = isNonBlobEngine ? normalLauncher : Path.Combine(source, "MetaHook_blob.exe");
if (!File.Exists(sourceLauncher))
throw new FileNotFoundException("Could not find the required MetaHook launcher.", sourceLauncher);

var isSvenCoop = modDirectory.Equals("svencoop", StringComparison.OrdinalIgnoreCase);
var targetLauncher = GetLauncherPath(gameDirectory, modDirectory, isNonBlobEngine);
CopyResources(source, gameDirectory, modDirectory);

File.Copy(sourceLauncher, targetLauncher, true);
foreach (var file in Directory.GetFiles(source).Where(file =>
Expand Down Expand Up @@ -99,12 +119,19 @@ public static string Install(string source, string gameDirectory, string modDire
return targetLauncher;
}

private static void CopyDirectory(string source, string destination)
private static void CopyDirectory(string source, string destination, bool preservePluginLists = false)
{
Directory.CreateDirectory(destination);
foreach (var file in Directory.GetFiles(source))
{
var name = Path.GetFileName(file);
if (preservePluginLists && (name.Equals("plugins.lst", StringComparison.OrdinalIgnoreCase) ||
name.Equals("plugins_svencoop.lst", StringComparison.OrdinalIgnoreCase) ||
name.Equals("plugins_goldsrc.lst", StringComparison.OrdinalIgnoreCase)))
continue;
File.Copy(file, Path.Combine(destination, Path.GetFileName(file)), true);
}
foreach (var directory in Directory.GetDirectories(source))
CopyDirectory(directory, Path.Combine(destination, Path.GetFileName(directory)));
CopyDirectory(directory, Path.Combine(destination, Path.GetFileName(directory)), preservePluginLists);
}
}
14 changes: 12 additions & 2 deletions src/MetahookInstallerCore/MetahookSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,21 @@ private static void EnsureValidInstallTarget(string gameDirectory, string modDir
}

// Describes a complete payload (both launchers) without requiring or deploying it.
public static string DescribeLauncherPath(string gameDirectory, string modDirectory)
public static string DescribeLauncherPath(string gameDirectory, string modDirectory, bool pluginsOnly = false)
{
EnsureValidInstallTarget(gameDirectory, modDirectory);
return InstallPayload.GetLauncherPath(Path.GetFullPath(gameDirectory), modDirectory,
var launcher = InstallPayload.GetLauncherPath(Path.GetFullPath(gameDirectory), modDirectory,
PortableExecutable.IsLegitimatePE(Path.Combine(gameDirectory, "hw.dll")));
if (pluginsOnly && (!File.Exists(launcher) || !Directory.Exists(Path.Combine(gameDirectory, modDirectory, "metahook"))))
throw new InvalidOperationException("Install MetaHook before deploying plugins: the expected launcher and mod's metahook directory must exist.");
return launcher;
}

public static string InstallPlugins(string source, string gameDirectory, string modDirectory)
{
var launcher = DescribeLauncherPath(gameDirectory, modDirectory, pluginsOnly: true);
InstallPayload.InstallPlugins(source, gameDirectory, modDirectory);
return launcher;
}

// Returns the installed launcher path.
Expand Down
Loading
Loading