fix command line arguments for alterware-launcher.exe

This commit is contained in:
mxve 2024-03-30 17:41:34 +01:00
parent cf4ae75cfa
commit 01b8737488
5 changed files with 39 additions and 15 deletions

View File

@ -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()

View File

@ -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<char*>(commandLine.data()), nullptr,
nullptr, false, NULL, nullptr, currentDir.data(),
&startupInfo, &processInfo);
CreateProcessW(process.data(), const_cast<wchar_t*>(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);
}
}

View File

@ -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_;

View File

@ -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");

View File

@ -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 <typename T>