diff --git a/BindingRedirects.cs b/BindingRedirects.cs index 6540c0d..d058713 100644 --- a/BindingRedirects.cs +++ b/BindingRedirects.cs @@ -33,9 +33,9 @@ public static void Setup(string exePath, string dllName) } } - public static void CopyRedirects(string sourceFile, string applicationPath, string applicationFile) + public static void CopyRedirects(string sourceFile, string frameworkDllFolder, string applicationFile) { - File.Copy(sourceFile, Path.Combine(applicationPath, applicationFile + ".config"), true); + File.Copy(sourceFile, Path.Combine(frameworkDllFolder, applicationFile + ".config"), true); } // TODO: Merge XML files, but this may be non-trivial due to actual version conflicts, so rather make downstream frameworks supply the right config files. diff --git a/CommandLine/CliEntryPoint.cs b/CommandLine/CliEntryPoint.cs index 44a8b98..389b01e 100644 --- a/CommandLine/CliEntryPoint.cs +++ b/CommandLine/CliEntryPoint.cs @@ -184,11 +184,12 @@ public async Task InvokeAsync(string commandLine, IConsole? outputConsole) } protected virtual void LaunchGame(bool nonInteractive, string applicationPath, string frameworkDllName, - string? modsJsonPath, string? modsFolder, string commandLine, bool patchLargeAddressAware) + string? modsJsonPath, string? modsFolder, string commandLine, bool? setLargeAddressAware) { var profileFolder = PreLaunch(modsJsonPath, modsFolder); + var frameworkDllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, frameworkDllName); // actually, we need the framework folder but with the game name? This fixes binding redirects apparently. - SetupBindingRedirects(applicationPath, frameworkDllName); + SetupBindingRedirects(applicationPath, frameworkDllPath); if (setLargeAddressAware.HasValue) { try @@ -205,27 +206,16 @@ protected virtual void LaunchGame(bool nonInteractive, string applicationPath, s } } - var process = StartApplication(applicationPath, commandLine, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, frameworkDllName), profileFolder); + var process = StartApplication(applicationPath, commandLine, frameworkDllPath, profileFolder); PostLaunch(process, profileFolder, nonInteractive); } - protected virtual void SetupBindingRedirects(string applicationPath, string frameworkDllName) - { - var redirectFile = frameworkDllName + ".config"; - if (!File.Exists(redirectFile)) - { - // Fall back to the generic DLL - redirectFile = "Andraste.Payload.Generic.dll.config"; - } - - BindingRedirects.CopyRedirects(redirectFile, Directory.GetParent(applicationPath)!.FullName, Path.GetFileName(applicationPath)); - } - protected virtual void MonitorGame(bool nonInteractive, string applicationPath, string frameworkDllName, string? modsJsonPath, string modsFolder) { PreLaunch(modsJsonPath, modsFolder); - SetupBindingRedirects(applicationPath, frameworkDllName); + var frameworkDllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, frameworkDllName); + SetupBindingRedirects(applicationPath, frameworkDllPath); // TODO: PostLaunch //PostLaunch(); } @@ -234,11 +224,25 @@ protected virtual void AttachGame(bool nonInteractive, int pid, string framework string? modsJsonPath, string modsFolder) { var profileFolder = PreLaunch(modsJsonPath, modsFolder); + var frameworkDllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, frameworkDllName); var process = Process.GetProcessById(pid); // TODO: Does this MainModule work? - SetupBindingRedirects(process.MainModule!.FileName, frameworkDllName); + SetupBindingRedirects(process.MainModule!.FileName, frameworkDllPath); PostLaunch(process, profileFolder, nonInteractive); } + + protected virtual void SetupBindingRedirects(string applicationPath, string frameworkDllPath) + { + var frameworkDllName = Path.GetFileName(frameworkDllPath); + var redirectFile = frameworkDllName + ".config"; + if (!File.Exists(redirectFile)) + { + // Fall back to the generic DLL + redirectFile = "Andraste.Payload.Generic.dll.config"; + } + + BindingRedirects.CopyRedirects(redirectFile, Directory.GetParent(frameworkDllPath)!.FullName, Path.GetFileName(applicationPath)); + } protected virtual string PreLaunch(string? modsJsonPath, string? modsFolder) {