From 01b87374887d7a848bd876ffad7006beb157ade4 Mon Sep 17 00:00:00 2001 From: mxve <68632137+mxve@users.noreply.github.com> Date: Sat, 30 Mar 2024 17:41:34 +0100 Subject: [PATCH] fix command line arguments for alterware-launcher.exe --- src/Components/Modules/QuickPatch.cpp | 2 +- src/Utils/Library.cpp | 26 +++++++++++++------------- src/Utils/Library.hpp | 2 +- src/Utils/Utils.cpp | 22 ++++++++++++++++++++++ src/Utils/Utils.hpp | 2 ++ 5 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index e8a7ded9..ef455f9a 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -249,7 +249,7 @@ namespace Components const std::string command = binary == "iw4x-sp.exe" ? "iw4x-sp" : "iw4x"; SetEnvironmentVariableA("MW2_INSTALL", workingDir.data()); - Utils::Library::LaunchProcess(binary, std::format("{} --pass \"{}\"", command, GetCommandLineA()), workingDir); + Utils::Library::LaunchProcess(Utils::String::Convert(binary), std::format(L"{} --pass \"{}\"", Utils::String::Convert(command), Utils::GetLaunchParameters()), workingDir); } __declspec(naked) void QuickPatch::SND_GetAliasOffset_Stub() diff --git a/src/Utils/Library.cpp b/src/Utils/Library.cpp index 70d661de..fae1bbcc 100644 --- a/src/Utils/Library.cpp +++ b/src/Utils/Library.cpp @@ -102,22 +102,22 @@ namespace Utils this->module_ = nullptr; } - void Library::LaunchProcess(const std::string& process, const std::string& commandLine, const std::string& currentDir) + void Library::LaunchProcess(const std::wstring& process, const std::wstring& commandLine, const std::filesystem::path& currentDir) { - STARTUPINFOA startupInfo; - PROCESS_INFORMATION processInfo; + STARTUPINFOW startup_info; + PROCESS_INFORMATION process_info; - ZeroMemory(&startupInfo, sizeof(startupInfo)); - ZeroMemory(&processInfo, sizeof(processInfo)); - startupInfo.cb = sizeof(startupInfo); + ZeroMemory(&startup_info, sizeof(startup_info)); + ZeroMemory(&process_info, sizeof(process_info)); + startup_info.cb = sizeof(startup_info); - CreateProcessA(process.data(), const_cast(commandLine.data()), nullptr, - nullptr, false, NULL, nullptr, currentDir.data(), - &startupInfo, &processInfo); + CreateProcessW(process.data(), const_cast(commandLine.data()), nullptr, + nullptr, false, NULL, nullptr, currentDir.wstring().data(), + &startup_info, &process_info); - if (processInfo.hThread && processInfo.hThread != INVALID_HANDLE_VALUE) - CloseHandle(processInfo.hThread); - if (processInfo.hProcess && processInfo.hProcess != INVALID_HANDLE_VALUE) - CloseHandle(processInfo.hProcess); + if (process_info.hThread && process_info.hThread != INVALID_HANDLE_VALUE) + CloseHandle(process_info.hThread); + if (process_info.hProcess && process_info.hProcess != INVALID_HANDLE_VALUE) + CloseHandle(process_info.hProcess); } } diff --git a/src/Utils/Library.hpp b/src/Utils/Library.hpp index 367d9d08..3ff72663 100644 --- a/src/Utils/Library.hpp +++ b/src/Utils/Library.hpp @@ -65,7 +65,7 @@ namespace Utils return T(); } - static void LaunchProcess(const std::string& process, const std::string& commandLine, const std::string& currentDir); + static void LaunchProcess(const std::wstring& process, const std::wstring& commandLine, const std::filesystem::path& currentDir); private: HMODULE module_; diff --git a/src/Utils/Utils.cpp b/src/Utils/Utils.cpp index 141a0fcc..60e06a5f 100644 --- a/src/Utils/Utils.cpp +++ b/src/Utils/Utils.cpp @@ -163,6 +163,28 @@ namespace Utils } } + std::wstring GetLaunchParameters() + { + std::wstring args; + + int numArgs; + auto* const argv = CommandLineToArgvW(GetCommandLineW(), &numArgs); + + if (argv) + { + for (auto i = 1; i < numArgs; ++i) + { + std::wstring arg(argv[i]); + args.append(arg); + args.append(L" "); + } + + LocalFree(argv); + } + + return args; + } + HMODULE GetNTDLL() { return GetModuleHandleA("ntdll.dll"); diff --git a/src/Utils/Utils.hpp b/src/Utils/Utils.hpp index f864a670..9ec8664b 100644 --- a/src/Utils/Utils.hpp +++ b/src/Utils/Utils.hpp @@ -24,6 +24,8 @@ namespace Utils void OpenUrl(const std::string& url); + std::wstring GetLaunchParameters(); + bool HasIntersection(unsigned int base1, unsigned int len1, unsigned int base2, unsigned int len2); template